Coder Social home page Coder Social logo

neo's Introduction

Neo

Build Status GoDoc

Go Web Framework

Installation

# framework
go get github.com/ivpusic/neo

# CLI tool
go get github.com/ivpusic/neo/cmd/neo

Documentation

Project Site

API Documentation

Example

Create Neo application:

neo new myapp
cd myapp
package main

import (
    "github.com/ivpusic/neo"
)

func main() {
    app := neo.App()

    app.Get("/", func(ctx *neo.Ctx) (int, error) {
        return 200, ctx.Res.Text("I am Neo Programmer")
    })

    app.Start()
}

Run it:

neo run main.go

License

MIT

neo's People

Contributors

butaixianran avatar ivpusic avatar mattn avatar tarrsalah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

neo's Issues

Can we remove gorm from ctx?

I try to recommand neo to other people and they don't think gorm should be in ctx, which many people may never use it at all.

I know it's a break change, but that's make sense for a lightweight web frame. Even who need gorm, they may never use it in a route handle function. They must have some model, controller packages for that.

'neo run' fails to reload

I'm on OSX

~/D/g/s/b/f/brody % neo run main.go
 git/ivp/go-/hr 14:33:03 ♥[INFO] ▶ go-hotreload started.
 git/ivp/go-/hr 14:33:03 ♥[INFO] ▶ Watching for changes.
 git/ivp/go-/hr 14:33:03 ♥[INFO] ▶ Use -v flag for verbose mode
 git/ivp/neo 14:33:04 ♥[INFO] ▶ Starting application on address `127.0.0.1:3000`
 git/ivp/go-/hr 14:33:11 ✖[ERRO] ▶ Error while executing fuser command! exit status 1
 git/ivp/neo 14:33:11 ♥[INFO] ▶ Starting application on address `127.0.0.1:3000`
panic: listen tcp 127.0.0.1:3000: bind: address already in use

goroutine 1 [running]:
github.com/ivpusic/neo.(*Application).Start(0xc20804c280)
        /Users/jan/Documents/go/src/github.com/ivpusic/neo/application.go:129 +0x201
main.main()
        /Users/jan/Documents/go/src/bitbucket.org/furion/brody/main.go:17 +0x71

goroutine 2 [runnable]:
runtime.forcegchelper()
        /usr/local/Cellar/go/1.4.1/libexec/src/runtime/proc.go:90
runtime.goexit()
        /usr/local/Cellar/go/1.4.1/libexec/src/runtime/asm_amd64.s:2232 +0x1

goroutine 3 [runnable]:
runtime.bgsweep()
        /usr/local/Cellar/go/1.4.1/libexec/src/runtime/mgc0.go:82
runtime.goexit()
        /usr/local/Cellar/go/1.4.1/libexec/src/runtime/asm_amd64.s:2232 +0x1

goroutine 4 [runnable]:
runtime.runfinq()
        /usr/local/Cellar/go/1.4.1/libexec/src/runtime/malloc.go:712
runtime.goexit()
        /usr/local/Cellar/go/1.4.1/libexec/src/runtime/asm_amd64.s:2232 +0x1
exit status 2

CORS support (or lack thereof)

I feel like neo has a potential of being a really nice Go library for building API's, but while trying to do so, I ran into another issue. CORS.

Currently, neo can only properly handle GET and simple POST requests from same origin.
Handling cors requires a bit of middleware code

    // CORS Middleware
    app.Use(func(ctx *neo.Ctx, next neo.Next) {
        if origin := ctx.Req.Header.Get("Origin"); origin != "" {
            ctx.Res.Header.Set("Access-Control-Allow-Origin", origin)
            ctx.Res.Header.Set("Access-Control-Allow-Credentials", "true")
            ctx.Res.Header.Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
            ctx.Res.Header.Set("Access-Control-Allow-Headers",
                "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization")
        }

        // back to neo
        next()
    })

, but the real pain is enabling POST, PUT, PATCH, DELETE... requests, since Neo doesn't expose router internals, one has to manually define OPTIONS region for every single endpoint.

    app.Options("/channels/:name", func(ctx *neo.Ctx) {
        ctx.Res.Raw([]byte(""), http.StatusOK)
    })
    app.Options("/channels", func(ctx *neo.Ctx) {
        ctx.Res.Raw([]byte(""), http.StatusOK)
    })

This is a lot of repetitive boilerplate, and is something the framework should be able to take care of in a more succint manner.

Note: My cors setup here isn't 100% correct and shound't be used as a reference.

git/ivp/neo 11:43:37 ✖[ERRO] ▶ exit status 1

The program does not work properly
go version:1.8.3

package main
import (
	"github.com/ivpusic/neo"
)

func main() {
	app := neo.App()

	app.Get("/", func(ctx *neo.Ctx) (int, error) {
		return 200, ctx.Res.Text("I am Neo Programmer")
	})

	app.Start()
}

run command:

 apple@henjue-mac: neo run sync_token_api.go
 git/ivp/neo 11:43:37 ✖[ERRO] ▶ exit status 1

Use cases for event functionality

I have not seen a golang web framework that has events like this does.

I was looking for examples to see how and its use cases. Are there any ?

Also it seem to use a bus. Pretty smart.

Very curious and if you have more info / URLs please let me know

can you add sub region?

such as:
father := app.Region().Prefix("/login")
father.Use(fn Widdleware)
son := father.Region().Prefix("/son") (or son := father.Prefix("/son")) //whole is /login/son
son.Get("", func(ctx *neo.Ctx) (int, error) {
...
})

Would a single ctx.Error be better than ctx.Errors?

Hi, I see you add Errors to ctx, but I'm thinking what gin does may not a good idea.

Basically, when we get an error, we just want to return from route handler.
Collecting errors like gin seems doesn't make sense

Golang's team offered a best practice on their blog about handling errors: Errors are values

Their solution is: define a single error object in a top level struct ( which should be in ctx in our cases )

So we can do something like this:

ctx.Error := SomeFunc()
// we don't need to deal with error here, a middleware will handle it automatically
if ctx.Error != nil { return 0, nil}

But with ctx.Errors, I have to write more code:

err := SomeFunc()
if err != nil {
    ctx.Error(err)
    return 0, nil
}

If we handle it with ctx.Errors[0]:

ctx.Errors := make([]error, 1)
ctx.Errors[0] := SomeFunc()

In this way, ctx.HasErrors() will always be true even if ctx.Errors[0] is nil

Following golang team's strategy, with a single ctx.Error, we can even do something like this:

func SomeFunc(param1, param2, err) error {
    //check error first
    if err != nil {return}
    //do something
}

func SomeFunc2(param1, param2, err) error {
    if err != nil {return}
    //do something else
}


ctx.Error := SomeFunc(param1, param2, ctx.Error)
ctx.Error := SomeFunc2(param1, param2, ctx.Error)
ctx.Error := SomeFunc3(param1, param2, ctx.Error)
return 200, ctx.Text("done")
//then, middleware will handle ctx.Error, if there is one.

In this way, we don't need to check ctx.Error at all, since every function has checked that error at beginning, if there is an error, all those functions will just return.

I think golang team's solution is much better than gin's, a single ctx.Error may truely better than collecting all errors.

static files serve broken

git/ivp/neo 09:20:51 ♥[INFO] ▶ --> [Req] HEAD to /static/multipage/images/portfolio/[email protected]
git/ivp/neo 09:20:51 ♥[INFO] ▶ <-- Res HEAD to /static/multipage/images/portfolio/[email protected] Took 0
git/ivp/neo 09:20:51 ★[DEBU] ▶ trying to match static url: /static/multipage/images/portfolio/[email protected]
git/ivp/neo 09:20:51 ★[DEBU] ▶ replacing /static/multipage/images/portfolio/[email protected] with /static
git/ivp/neo 09:20:51 ★[DEBU] ▶ found possible result. Path: /home/xi/go/src/github.com/xi3/yishu/public/multipage/images/portfolio/[email protected]
git/ivp/neo 09:20:51 ★[DEBU] ▶ replacing /static/multipage/images/portfolio/[email protected] with /static
git/ivp/neo 09:20:51 ★[DEBU] ▶ found possible result. Path: /home/xi/go/src/github.com/xi3/yishu/public/multipage/images/portfolio/[email protected]
git/ivp/neo 09:20:51 ★[DEBU] ▶ result not found in static
git/ivp/neo 09:20:51 ★[DEBU] ▶ route /static/multipage/images/portfolio/[email protected] not found
git/ivp/neo 09:20:51 ♥[INFO] ▶ --> [Req] HEAD to /static/multipage/images/portfolio/[email protected]
git/ivp/neo 09:20:51 ♥[INFO] ▶ <-- Res HEAD to /static/multipage/images/portfolio/[email protected] Took 0
git/ivp/neo 09:20:51 ★[DEBU] ▶ trying to match static url: /static/multipage/images/portfolio/[email protected]
git/ivp/neo 09:20:51 ★[DEBU] ▶ replacing /static/multipage/images/portfolio/[email protected] with /static
git/ivp/neo 09:20:51 ★[DEBU] ▶ found possible result. Path: /home/xi/go/src/github.com/xi3/yishu/public/multipage/images/portfolio/[email protected]
git/ivp/neo 09:20:51 ★[DEBU] ▶ result not found in static
git/ivp/neo 09:20:51 ★[DEBU] ▶ route /static/multipage/images/portfolio/[email protected] not found
git/ivp/neo 09:20:51 ♥[INFO] ▶ --> [Req] HEAD to /static/multipage/images/portfolio/[email protected]
git/ivp/neo 09:20:51 ♥[INFO] ▶ <-- Res HEAD to /static/multipage/images/portfolio/[email protected] Took 0
2015/02/21 09:20:51 http: panic serving 60.252.32.245:59490: tabwriter: panic during Write
goroutine 37 [running]:
net/http.func·011()
/usr/local/go/src/net/http/server.go:1130 +0xbb
github.com/ivpusic/neo.func·001()
/home/xi/go/src/github.com/ivpusic/neo/application.go:55 +0x95
github.com/ivpusic/neo.func·002()
/home/xi/go/src/github.com/ivpusic/neo/application.go:77 +0x13d
text/tabwriter.handlePanic(0xc20813f468, 0x7e1270, 0x5)
/usr/local/go/src/text/tabwriter/tabwriter.go:443 +0x126
text/tabwriter.handlePanic(0xc20813f350, 0x7db270, 0x5)
/usr/local/go/src/text/tabwriter/tabwriter.go:443 +0x126
text/tabwriter.(_Writer).writeLines(0xc2080be200, 0x0, 0x0, 0x2, 0xab)
/usr/local/go/src/text/tabwriter/tabwriter.go:262 +0x70f
text/tabwriter.(_Writer).format(0xc2080be200, 0x0, 0x0, 0x2, 0x9e3928)
/usr/local/go/src/text/tabwriter/tabwriter.go:370 +0x421
text/tabwriter.(_Writer).Flush(0xc2080be200, 0x0, 0x0)
/usr/local/go/src/text/tabwriter/tabwriter.go:466 +0xfc
text/tabwriter.(_Writer).Write(0xc2080be200, 0xc2080ef0e0, 0xac, 0x120, 0xac, 0x0, 0x0)
/usr/local/go/src/text/tabwriter/tabwriter.go:501 +0x4a3
fmt.Fprintln(0x7f182009b058, 0xc2080be200, 0xc20813f580, 0x1, 0x1, 0x83, 0x0, 0x0)
/usr/local/go/src/fmt/print.go:255 +0x9f
github.com/ivpusic/go-clicolor/clicolor.(_Printer).InFormat(0xc2080d8220)
/home/xi/go/src/github.com/ivpusic/go-clicolor/clicolor/clicolor.go:56 +0x50f
github.com/ivpusic/golog.(_Stdout).Append(0xc20801e540, 0xecc79d473, 0x2a801648, 0x9db0c0, 0xc208150ee0, 0x6c, 0xa, 0x7e3e70, 0x4, 0x7f8310, ...)
/home/xi/go/src/github.com/ivpusic/golog/appender.go:50 +0x3ed
github.com/ivpusic/golog.(_Logger).makeLog(0xc208010150, 0x6d4780, 0xc2080d8190, 0xa, 0x7e3e70, 0x4, 0x7f8310, 0x3, 0x7da150, 0x5, ...)
/home/xi/go/src/github.com/ivpusic/golog/logger.go:139 +0x215
github.com/ivpusic/golog.(_Logger).Debug(0xc208010150, 0x6d4780, 0xc2080d8190, 0x0, 0x0, 0x0)
/home/xi/go/src/github.com/ivpusic/golog/logger.go:241 +0xc5
github.com/ivpusic/neo.(_Static).match(0xc208038208, 0xc20806c5c5, 0x2b, 0x0, 0x0, 0x0, 0x0)
/home/xi/go/src/github.com/ivpusic/neo/static.go:38 +0x593
github.com/ivpusic/neo.(_Application).ServeHTTP(0xc20806c480, 0x7f182009c750, 0xc2080940a0, 0xc208034750)
/home/xi/go/src/github.com/ivpusic/neo/application.go:87 +0x1ee
net/http.serverHandler.ServeHTTP(0xc2080bd2c0, 0x7f182009c750, 0xc2080940a0, 0xc208034750)
/usr/local/go/src/net/http/server.go:1703 +0x19a
net/http.(_conn).serve(0xc208116320)
/usr/local/go/src/net/http/server.go:1204 +0xb57
created by net/http.(_Server).Serve
/usr/local/go/src/net/http/server.go:1751 +0x35e
git/ivp/neo 09:20:51 ★[DEBU] ▶ emmiting event error
git/ivp/neo 09:20:51 ★[DEBU] ▶ trying to match static url: /static/multipage/images/portfolio/[email protected]
git/ivp/neo 09:20:51 ★[DEBU] ▶ listeners for event error not found git/ivp/neo 09:20:51 ★[DEBU] ▶ listeners for event error
git/ivp/neo 09:20:51 ★[DEBU] ▶ emmiting event error
panic: runtime error: index out of range [recovered]
panic: tabwriter: panic during Flush [recovered]
panic: tabwriter: panic during Write

goroutine 39 [running]:
text/tabwriter.handlePanic(0xc2081419c8, 0x7e1270, 0x5)
/usr/local/go/src/text/tabwriter/tabwriter.go:443 +0x126
text/tabwriter.handlePanic(0xc2081418b0, 0x7db270, 0x5)
/usr/local/go/src/text/tabwriter/tabwriter.go:443 +0x126
text/tabwriter.(_Writer).writeLines(0xc2080be200, 0x0, 0x0, 0x2, 0x55)
/usr/local/go/src/text/tabwriter/tabwriter.go:262 +0x70f
text/tabwriter.(_Writer).format(0xc2080be200, 0x0, 0x0, 0x2, 0x9e3928)
/usr/local/go/src/text/tabwriter/tabwriter.go:370 +0x421
text/tabwriter.(_Writer).Flush(0xc2080be200, 0x0, 0x0)
/usr/local/go/src/text/tabwriter/tabwriter.go:466 +0xfc
text/tabwriter.(_Writer).Write(0xc2080be200, 0xc2080a2b80, 0x56, 0x80, 0x56, 0x0, 0x0)
/usr/local/go/src/text/tabwriter/tabwriter.go:501 +0x4a3
fmt.Fprintln(0x7f182009b058, 0xc2080be200, 0xc208141ae0, 0x1, 0x1, 0x2d, 0x0, 0x0)
/usr/local/go/src/fmt/print.go:255 +0x9f
github.com/ivpusic/go-clicolor/clicolor.(_Printer).InFormat(0xc20813aa10)
/home/xi/go/src/github.com/ivpusic/go-clicolor/clicolor/clicolor.go:56 +0x50f
github.com/ivpusic/golog.(_Stdout).Append(0xc20801e540, 0xecc79d473, 0x2aefc091, 0x9db0c0, 0xc20812cfe0, 0x16, 0xa, 0x7e3e70, 0x4, 0x7f8310, ...)
/home/xi/go/src/github.com/ivpusic/golog/appender.go:50 +0x3ed
github.com/ivpusic/golog.(_Logger).makeLog(0xc208010150, 0x6d4780, 0xc20813a990, 0xa, 0x7e3e70, 0x4, 0x7f8310, 0x3, 0x7da150, 0x5, ...)
/home/xi/go/src/github.com/ivpusic/golog/logger.go:139 +0x215
github.com/ivpusic/golog.(_Logger).Debugf(0xc208010150, 0x828210, 0x13, 0xc208141f80, 0x1, 0x1)
/home/xi/go/src/github.com/ivpusic/golog/logger.go:277 +0x137
github.com/ivpusic/neo/ebus.func·001()
/home/xi/go/src/github.com/ivpusic/neo/ebus/ebus.go:40 +0x130
created by github.com/ivpusic/neo/ebus.(*EBus).Emit
/home/xi/go/src/github.com/ivpusic/neo/ebus/ebus.go:52 +0x124

goroutine 1 [IO wait]:
net.(_pollDesc).Wait(0xc208074920, 0x72, 0x0, 0x0)
/usr/local/go/src/net/fd_poll_runtime.go:84 +0x47
net.(_pollDesc).WaitRead(0xc208074920, 0x0, 0x0)
/usr/local/go/src/net/fd_poll_runtime.go:89 +0x43
net.(_netFD).accept(0xc2080748c0, 0x0, 0x7f182009ae60, 0xc2080d8c08)
/usr/local/go/src/net/fd_unix.go:419 +0x40b
net.(_TCPListener).AcceptTCP(0xc2080383d8, 0x4a82ee, 0x0, 0x0)
/usr/local/go/src/net/tcpsock_posix.go:234 +0x4e
net/http.tcpKeepAliveListener.Accept(0xc2080383d8, 0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/net/http/server.go:1976 +0x4c
net/http.(_Server).Serve(0xc2080bd2c0, 0x7f182009c598, 0xc2080383d8, 0x0, 0x0)
/usr/local/go/src/net/http/server.go:1728 +0x92
net/http.(_Server).ListenAndServe(0xc2080bd2c0, 0x0, 0x0)
/usr/local/go/src/net/http/server.go:1718 +0x154
net/http.ListenAndServe(0xc20802afb0, 0x5, 0x7f182009b4d0, 0xc20806c480, 0x0, 0x0)
/usr/local/go/src/net/http/server.go:1808 +0xba
github.com/ivpusic/neo.(*Application).Start(0xc20806c480)
/home/xi/go/src/github.com/ivpusic/neo/application.go:127 +0x197
main.main()
/home/xi/go/src/github.com/xi3/yishu/main.go:29 +0x319

goroutine 34 [IO wait]:
net.(_pollDesc).Wait(0xc208145090, 0x72, 0x0, 0x0)
/usr/local/go/src/net/fd_poll_runtime.go:84 +0x47
net.(_pollDesc).WaitRead(0xc208145090, 0x0, 0x0)
/usr/local/go/src/net/fd_poll_runtime.go:89 +0x43
net.(_netFD).Read(0xc208145030, 0xc208135000, 0x1000, 0x1000, 0x0, 0x7f182009ae60, 0xc20813a308)
/usr/local/go/src/net/fd_unix.go:242 +0x40f
net.(_conn).Read(0xc208038680, 0xc208135000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/local/go/src/net/net.go:121 +0xdc
net/http.(_liveSwitchReader).Read(0xc208152cc8, 0xc208135000, 0x1000, 0x1000, 0x2, 0x0, 0x0)
/usr/local/go/src/net/http/server.go:214 +0xab
io.(_LimitedReader).Read(0xc2080deb80, 0xc208135000, 0x1000, 0x1000, 0x2, 0x0, 0x0)
/usr/local/go/src/io/io.go:408 +0xce
bufio.(_Reader).fill(0xc2080bd920)
/usr/local/go/src/bufio/bufio.go:97 +0x1ce
bufio.(_Reader).ReadSlice(0xc2080bd920, 0xc2080c3b0a, 0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/bufio/bufio.go:295 +0x257
bufio.(_Reader).ReadLine(0xc2080bd920, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/bufio/bufio.go:324 +0x62
net/textproto.(_Reader).readLineSlice(0xc2080eb410, 0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/net/textproto/reader.go:55 +0x9e
net/textproto.(_Reader).ReadLine(0xc2080eb410, 0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/net/textproto/reader.go:36 +0x4f
net/http.ReadRequest(0xc2080bd920, 0xc208035040, 0x0, 0x0)
/usr/local/go/src/net/http/request.go:598 +0xcb
net/http.(_conn).readRequest(0xc208152c80, 0x0, 0x0, 0x0)
/usr/local/go/src/net/http/server.go:586 +0x26f
net/http.(_conn).serve(0xc208152c80)
/usr/local/go/src/net/http/server.go:1162 +0x69e
created by net/http.(_Server).Serve
/usr/local/go/src/net/http/server.go:1751 +0x35e

goroutine 35 [IO wait]:
net.(_pollDesc).Wait(0xc20815b640, 0x72, 0x0, 0x0)
/usr/local/go/src/net/fd_poll_runtime.go:84 +0x47
net.(_pollDesc).WaitRead(0xc20815b640, 0x0, 0x0)
/usr/local/go/src/net/fd_poll_runtime.go:89 +0x43
net.(_netFD).Read(0xc20815b5e0, 0xc208155000, 0x1000, 0x1000, 0x0, 0x7f182009ae60, 0xc2080d8f38)
/usr/local/go/src/net/fd_unix.go:242 +0x40f
net.(_conn).Read(0xc208038588, 0xc208155000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/local/go/src/net/net.go:121 +0xdc
net/http.(_liveSwitchReader).Read(0xc208116728, 0xc208155000, 0x1000, 0x1000, 0x2, 0x0, 0x0)
/usr/local/go/src/net/http/server.go:214 +0xab
io.(_LimitedReader).Read(0xc20812cf40, 0xc208155000, 0x1000, 0x1000, 0x2, 0x0, 0x0)
/usr/local/go/src/io/io.go:408 +0xce
bufio.(_Reader).fill(0xc2080bd560)
/usr/local/go/src/bufio/bufio.go:97 +0x1ce
bufio.(_Reader).ReadSlice(0xc2080bd560, 0xc2080c5b0a, 0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/bufio/bufio.go:295 +0x257
bufio.(_Reader).ReadLine(0xc2080bd560, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/bufio/bufio.go:324 +0x62
net/textproto.(_Reader).readLineSlice(0xc2080cf380, 0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/net/textproto/reader.go:55 +0x9e
net/textproto.(_Reader).ReadLine(0xc2080cf380, 0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/net/textproto/reader.go:36 +0x4f
net/http.ReadRequest(0xc2080bd560, 0xc208035110, 0x0, 0x0)
/usr/local/go/src/net/http/request.go:598 +0xcb
net/http.(_conn).readRequest(0xc2081166e0, 0x0, 0x0, 0x0)
/usr/local/go/src/net/http/server.go:586 +0x26f
net/http.(_conn).serve(0xc2081166e0)
/usr/local/go/src/net/http/server.go:1162 +0x69e
created by net/http.(_Server).Serve
/usr/local/go/src/net/http/server.go:1751 +0x35e

goroutine 33 [IO wait]:
net.(_pollDesc).Wait(0xc208145020, 0x77, 0x0, 0x0)
/usr/local/go/src/net/fd_poll_runtime.go:84 +0x47
net.(_pollDesc).WaitWrite(0xc208145020, 0x0, 0x0)
/usr/local/go/src/net/fd_poll_runtime.go:93 +0x43
net.sendFile(0xc208144fc0, 0x7f182009ae10, 0xc208038c08, 0x6e0a0, 0x0, 0x0, 0x0)
/usr/local/go/src/net/sendfile_linux.go:60 +0x40c
net.(_TCPConn).ReadFrom(0xc208038678, 0x7f182009c6a8, 0xc2080788e0, 0xc, 0x0, 0x0)
/usr/local/go/src/net/tcpsock_posix.go:69 +0x57
net/http.(_response).ReadFrom(0xc208117900, 0x7f182009c6a8, 0xc2080788e0, 0x0, 0x0, 0x0)
/usr/local/go/src/net/http/server.go:413 +0x432
io.Copy(0x7f182009cc68, 0xc208117900, 0x7f182009c6a8, 0xc2080788e0, 0x0, 0x0, 0x0)
/usr/local/go/src/io/io.go:358 +0x13d
io.CopyN(0x7f182009cc68, 0xc208117900, 0x7f182009ae10, 0xc208038c08, 0x5ab7a7, 0x0, 0x0, 0x0)
/usr/local/go/src/io/io.go:327 +0x113
net/http.serveContent(0x7f182009c750, 0xc208117900, 0xc208035520, 0xc20804e8fd, 0xa, 0xecc79cf9a, 0x128e55af, 0x9db0c0, 0xc2080c76d8, 0x7f182009cab0, ...)
/usr/local/go/src/net/http/fs.go:257 +0xb33
net/http.serveFile(0x7f182009c750, 0xc208117900, 0xc208035520, 0x7f182009c810, 0xc20813af30, 0xc208139cad, 0xa, 0x0)
/usr/local/go/src/net/http/fs.go:412 +0x7dd
net/http.ServeFile(0x7f182009c750, 0xc208117900, 0xc208035520, 0xc208139c70, 0x47)
/usr/local/go/src/net/http/fs.go:428 +0xf1
github.com/ivpusic/neo.(_Response).serveFile(0xc208122120, 0xc208139c70, 0x47)
/home/xi/go/src/github.com/ivpusic/neo/response.go:126 +0x144
github.com/ivpusic/neo.func·003(0xc20814cc80)
/home/xi/go/src/github.com/ivpusic/neo/application.go:92 +0x45
github.com/ivpusic/neo.handler.apply(0xc2080dfae0, 0xc20814cc80, 0xc2080dfb00, 0x2, 0x2, 0x1)
/home/xi/go/src/github.com/ivpusic/neo/router.go:16 +0x2d
github.com/ivpusic/neo.func·006()
/home/xi/go/src/github.com/ivpusic/neo/interceptor.go:24 +0xa0
github.com/ivpusic/neo/middlewares/logger.Log(0xc20814cc80, 0xc2080dfb60)
/home/xi/go/src/github.com/ivpusic/neo/middlewares/logger/logger.go:21 +0x185
github.com/ivpusic/neo.middleware.apply(0x8a7890, 0xc20814cc80, 0xc2080dfb00, 0x2, 0x2, 0x0)
/home/xi/go/src/github.com/ivpusic/neo/interceptor.go:26 +0x135
github.com/ivpusic/neo.(_middleware).apply(0xc208038230, 0xc20814cc80, 0xc2080dfb00, 0x2, 0x2, 0x0)
:58 +0xc7
github.com/ivpusic/neo.func·005(0xc20814cc80)
/home/xi/go/src/github.com/ivpusic/neo/interceptor.go:12 +0x7d
github.com/ivpusic/neo.(_Application).ServeHTTP(0xc20806c480, 0x7f182009c750, 0xc208117900, 0xc208035520)
/home/xi/go/src/github.com/ivpusic/neo/application.go:96 +0x46b
net/http.serverHandler.ServeHTTP(0xc2080bd2c0, 0x7f182009c750, 0xc208117900, 0xc208035520)
/usr/local/go/src/net/http/server.go:1703 +0x19a
net/http.(_conn).serve(0xc208152be0)
/usr/local/go/src/net/http/server.go:1204 +0xb57
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:1751 +0x35e

goroutine 31 [IO wait]:
net.(_pollDesc).Wait(0xc2080d23e0, 0x72, 0x0, 0x0)
/usr/local/go/src/net/fd_poll_runtime.go:84 +0x47
net.(_pollDesc).WaitRead(0xc2080d23e0, 0x0, 0x0)
/usr/local/go/src/net/fd_poll_runtime.go:89 +0x43
net.(_netFD).Read(0xc2080d2380, 0xc208073000, 0x1000, 0x1000, 0x0, 0x7f182009ae60, 0xc2080d9cb0)
/usr/local/go/src/net/fd_unix.go:242 +0x40f
net.(_conn).Read(0xc208038820, 0xc208073000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/local/go/src/net/net.go:121 +0xdc
net/http.(_liveSwitchReader).Read(0xc208033b28, 0xc208073000, 0x1000, 0x1000, 0xc00000000000002, 0x0, 0x0)
/usr/local/go/src/net/http/server.go:214 +0xab
io.(_LimitedReader).Read(0xc2080d6e60, 0xc208073000, 0x1000, 0x1000, 0x2, 0x0, 0x0)
/usr/local/go/src/io/io.go:408 +0xce
bufio.(_Reader).fill(0xc2081227e0)
/usr/local/go/src/bufio/bufio.go:97 +0x1ce
bufio.(_Reader).ReadSlice(0xc2081227e0, 0xa, 0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/bufio/bufio.go:295 +0x257
bufio.(_Reader).ReadLine(0xc2081227e0, 0x0, 0x0, 0x0, 0xc207ff3100, 0x0, 0x0)
/usr/local/go/src/bufio/bufio.go:324 +0x62
net/textproto.(_Reader).readLineSlice(0xc2080cea50, 0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/net/textproto/reader.go:55 +0x9e
net/textproto.(_Reader).ReadLine(0xc2080cea50, 0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/net/textproto/reader.go:36 +0x4f
net/http.ReadRequest(0xc2081227e0, 0xc2080349c0, 0x0, 0x0)
/usr/local/go/src/net/http/request.go:598 +0xcb
net/http.(_conn).readRequest(0xc208033ae0, 0x0, 0x0, 0x0)
/usr/local/go/src/net/http/server.go:586 +0x26f
net/http.(_conn).serve(0xc208033ae0)
/usr/local/go/src/net/http/server.go:1162 +0x69e
created by net/http.(_Server).Serve
/usr/local/go/src/net/http/server.go:1751 +0x35e

goroutine 32 [semacquire]:
sync.(_Mutex).Lock(0xc20804e0a0)
/usr/local/go/src/sync/mutex.go:66 +0xd3
log.(_Logger).Output(0xc20804e0a0, 0x2, 0xc208162100, 0xa1c, 0x0, 0x0)
/usr/local/go/src/log/log.go:134 +0x97
log.Printf(0x84b850, 0x1d, 0xc208142c78, 0x3, 0x3)
/usr/local/go/src/log/log.go:276 +0x87
net/http.(_Server).logf(0xc2080bd2c0, 0x84b850, 0x1d, 0xc208142c78, 0x3, 0x3)
/usr/local/go/src/net/http/server.go:1775 +0x8b
net/http.func·011()
/usr/local/go/src/net/http/server.go:1131 +0x24f
github.com/ivpusic/neo.func·001()
/home/xi/go/src/github.com/ivpusic/neo/application.go:55 +0x95
github.com/ivpusic/neo.func·002()
/home/xi/go/src/github.com/ivpusic/neo/application.go:77 +0x13d
text/tabwriter.handlePanic(0xc208143468, 0x7e1270, 0x5)
/usr/local/go/src/text/tabwriter/tabwriter.go:443 +0x126
text/tabwriter.handlePanic(0xc208143350, 0x7db270, 0x5)
/usr/local/go/src/text/tabwriter/tabwriter.go:443 +0x126
text/tabwriter.(_Writer).writeLines(0xc2080be200, 0x0, 0x0, 0x3, 0x55)
/usr/local/go/src/text/tabwriter/tabwriter.go:262 +0x70f
text/tabwriter.(_Writer).format(0xc2080be200, 0x0, 0x0, 0x3, 0x9e3928)
/usr/local/go/src/text/tabwriter/tabwriter.go:370 +0x421
text/tabwriter.(_Writer).Flush(0xc2080be200, 0x0, 0x0)
/usr/local/go/src/text/tabwriter/tabwriter.go:466 +0xfc
text/tabwriter.(_Writer).Write(0xc2080be200, 0xc208032aa0, 0x87, 0xa0, 0x87, 0x0, 0x0)
/usr/local/go/src/text/tabwriter/tabwriter.go:501 +0x4a3
fmt.Fprintln(0x7f182009b058, 0xc2080be200, 0xc208143580, 0x1, 0x1, 0x5e, 0x0, 0x0)
/usr/local/go/src/fmt/print.go:255 +0x9f
github.com/ivpusic/go-clicolor/clicolor.(_Printer).InFormat(0xc20813a3b0)
/home/xi/go/src/github.com/ivpusic/go-clicolor/clicolor/clicolor.go:56 +0x50f
github.com/ivpusic/golog.(_Stdout).Append(0xc20801e540, 0xecc79d473, 0x2ad1e1d0, 0x9db0c0, 0xc20804e730, 0x47, 0xa, 0x7e3e70, 0x4, 0x7f8310, ...)
/home/xi/go/src/github.com/ivpusic/golog/appender.go:50 +0x3ed
github.com/ivpusic/golog.(_Logger).makeLog(0xc208010150, 0x6d4780, 0xc20813b590, 0xa, 0x7e3e70, 0x4, 0x7f8310, 0x3, 0x7da150, 0x5, ...)
/home/xi/go/src/github.com/ivpusic/golog/logger.go:139 +0x215
github.com/ivpusic/golog.(_Logger).Debug(0xc208010150, 0x6d4780, 0xc20813b590, 0x0, 0x0, 0x0)
/home/xi/go/src/github.com/ivpusic/golog/logger.go:241 +0xc5
github.com/ivpusic/neo.(_Static).match(0xc208038208, 0xc208128305, 0x2b, 0x0, 0x0, 0x0, 0x0)
/home/xi/go/src/github.com/ivpusic/neo/static.go:22 +0x100
github.com/ivpusic/neo.(_Application).ServeHTTP(0xc20806c480, 0x7f182009c750, 0xc208032a00, 0xc208034dd0)
/home/xi/go/src/github.com/ivpusic/neo/application.go:87 +0x1ee
net/http.serverHandler.ServeHTTP(0xc2080bd2c0, 0x7f182009c750, 0xc208032a00, 0xc208034dd0)
/usr/local/go/src/net/http/server.go:1703 +0x19a
net/http.(_conn).serve(0xc208152b40)
/usr/local/go/src/net/http/server.go:1204 +0xb57
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:1751 +0x35e

goroutine 37 [runnable]:
syscall.Syscall(0x1, 0x2, 0xc2080b6800, 0xa31, 0xa31, 0xa31, 0x0)
/usr/local/go/src/syscall/asm_linux_amd64.s:21 +0x5
syscall.write(0x2, 0xc2080b6800, 0xa31, 0x1800, 0xc2080b6800, 0x0, 0x0)
/usr/local/go/src/syscall/zsyscall_linux_amd64.go:1263 +0x6e
syscall.Write(0x2, 0xc2080b6800, 0xa31, 0x1800, 0x1800, 0x0, 0x0)
/usr/local/go/src/syscall/syscall_unix.go:152 +0x58
os.(_File).write(0xc208038010, 0xc2080b6800, 0xa31, 0x1800, 0x0, 0x0, 0x0)
/usr/local/go/src/os/file_unix.go:212 +0xb7
os.(_File).Write(0xc208038010, 0xc2080b6800, 0xa31, 0x1800, 0x9db0c0, 0x0, 0x0)
/usr/local/go/src/os/file.go:139 +0x91
log.(_Logger).Output(0xc20804e0a0, 0x2, 0xc208160b00, 0xa1d, 0x0, 0x0)
/usr/local/go/src/log/log.go:153 +0x4ed
log.Printf(0x84b850, 0x1d, 0xc20813ec78, 0x3, 0x3)
/usr/local/go/src/log/log.go:276 +0x87
net/http.(_Server).logf(0xc2080bd2c0, 0x84b850, 0x1d, 0xc20813ec78, 0x3, 0x3)
/usr/local/go/src/net/http/server.go:1775 +0x8b
net/http.func·011()
/usr/local/go/src/net/http/server.go:1131 +0x24f
github.com/ivpusic/neo.func·001()
/home/xi/go/src/github.com/ivpusic/neo/application.go:55 +0x95
github.com/ivpusic/neo.func·002()
/home/xi/go/src/github.com/ivpusic/neo/application.go:77 +0x13d
text/tabwriter.handlePanic(0xc20813f468, 0x7e1270, 0x5)
/usr/local/go/src/text/tabwriter/tabwriter.go:443 +0x126
text/tabwriter.handlePanic(0xc20813f350, 0x7db270, 0x5)
/usr/local/go/src/text/tabwriter/tabwriter.go:443 +0x126
text/tabwriter.(_Writer).writeLines(0xc2080be200, 0x0, 0x0, 0x2, 0xab)
/usr/local/go/src/text/tabwriter/tabwriter.go:262 +0x70f
text/tabwriter.(_Writer).format(0xc2080be200, 0x0, 0x0, 0x2, 0x9e3928)
/usr/local/go/src/text/tabwriter/tabwriter.go:370 +0x421
text/tabwriter.(_Writer).Flush(0xc2080be200, 0x0, 0x0)
/usr/local/go/src/text/tabwriter/tabwriter.go:466 +0xfc
text/tabwriter.(_Writer).Write(0xc2080be200, 0xc2080ef0e0, 0xac, 0x120, 0xac, 0x0, 0x0)
/usr/local/go/src/text/tabwriter/tabwriter.go:501 +0x4a3
fmt.Fprintln(0x7f182009b058, 0xc2080be200, 0xc20813f580, 0x1, 0x1, 0x83, 0x0, 0x0)
/usr/local/go/src/fmt/print.go:255 +0x9f
github.com/ivpusic/go-clicolor/clicolor.(_Printer).InFormat(0xc2080d8220)
/home/xi/go/src/github.com/ivpusic/go-clicolor/clicolor/clicolor.go:56 +0x50f
github.com/ivpusic/golog.(_Stdout).Append(0xc20801e540, 0xecc79d473, 0x2a801648, 0x9db0c0, 0xc208150ee0, 0x6c, 0xa, 0x7e3e70, 0x4, 0x7f8310, ...)
/home/xi/go/src/github.com/ivpusic/golog/appender.go:50 +0x3ed
github.com/ivpusic/golog.(_Logger).makeLog(0xc208010150, 0x6d4780, 0xc2080d8190, 0xa, 0x7e3e70, 0x4, 0x7f8310, 0x3, 0x7da150, 0x5, ...)
/home/xi/go/src/github.com/ivpusic/golog/logger.go:139 +0x215
github.com/ivpusic/golog.(_Logger).Debug(0xc208010150, 0x6d4780, 0xc2080d8190, 0x0, 0x0, 0x0)
/home/xi/go/src/github.com/ivpusic/golog/logger.go:241 +0xc5
github.com/ivpusic/neo.(_Static).match(0xc208038208, 0xc20806c5c5, 0x2b, 0x0, 0x0, 0x0, 0x0)
/home/xi/go/src/github.com/ivpusic/neo/static.go:38 +0x593
github.com/ivpusic/neo.(_Application).ServeHTTP(0xc20806c480, 0x7f182009c750, 0xc2080940a0, 0xc208034750)
/home/xi/go/src/github.com/ivpusic/neo/application.go:87 +0x1ee
net/http.serverHandler.ServeHTTP(0xc2080bd2c0, 0x7f182009c750, 0xc2080940a0, 0xc208034750)
/usr/local/go/src/net/http/server.go:1703 +0x19a
net/http.(_conn).serve(0xc208116320)
/usr/local/go/src/net/http/server.go:1204 +0xb57
created by net/http.(_Server).Serve
/usr/local/go/src/net/http/server.go:1751 +0x35e
exit status 2

how to get wildcard param's value?

We need something like this:

    app.Get("/path/:name/*", func(c *neo.Ctx) (int, error) {
        others := c.Req.Params("*")
        //do something
    })

How can I get the value of wildcard? Thanks

p.s. neo is great, it's exactly what we need, its router is also much easy to use then gin and echo. Thanks for this great job

Remove "neo" topic from repo

Problem

The NEO blockchain team have created an official page for the neo topic on Github.

See here: https://github.com/topics/neo

This repo has added the neo topic however it isn't relevant as a topic, more just as a name.

Solution

Remove neo topic from repo.

Notes

  • None

AssertNil will blow up

Doing this does blow up sometimes:

    app.Get("/downloads", func(ctx *neo.Ctx) {
        data, err := util.FolderScanner(util.RelativePath("tmp"), util.File)
        neo.AssertNil(err, http.StatusNoContent, []byte(err.Error()))
        ctx.Res.Json(data, http.StatusOK)
    })

If there is no error

neo.AssertNil(err, http.StatusNoContent, []byte(err.Error()))

Will cause nil pointer panic.

would we change the color of document site?

From dark theme into some bright theme, for example:

Sure dark theme is better for eyes, but bright theme make it looks more modern. I've already changed it in my fork, if it's ok to you, I'll create a pull request.

ctx.Req.JsonBody return EOF

client post json {'id':200,'name':"neo"} to route /api
want server return same json
test code :

package main
import (
    "github.com/ivpusic/neo"
_     "io/ioutil"
    "fmt"
)
func main() {
    app := neo.App()
    app.Get("/", func(ctx *neo.Ctx) (int, error) {
    	html:=`<html><head><script src="https://unpkg.com/axios/dist/axios.min.js"></script></head>
<body><script>
	axios.post('/api', {'id':200,'name':"neo"}).then(res => {  console.log(res.data); });
</script>
axios post 
</body><html>
	`
    	
        return 200, ctx.Res.Text(html)
    })

    app.Post("/api", func(ctx *neo.Ctx) (int, error) {
    	
   /*  body,err:=ioutil.ReadAll(ctx.Req.Body)
  	  fmt.Println(string(body))
      
	fmt.Println(ctx.Req.JsonBody(ctx.Req.Body))
	  
 	   if ( nil != err){
	   	    fmt.Println("err")
	      return 500,err
	   }
  */	
     fmt.Println(ctx.Req.Body)

    return 200,  ctx.Res.Json(ctx.Req.JsonBody(ctx.Req.Body))
    })

	    app.Start()
}


body,err:=ioutil.ReadAll(ctx.Req.Body)
read json correct
but ctx.Req.JsonBody(xxx) return EOF

How to wildcard "" and "/" for route?

Now need two func for route "/login" and "/login/"?
such as for "/"
app.Get("/", func(ctx *neo.Ctx) (int, error) {
...
})
i need another func for "":
app.Get("", func(ctx *neo.Ctx) (int, error) {
...
})

cannot create directory at 'aux'

When git wants to checkout it will show this error: fatal: cannot create directory at 'aux': Invalid argument. That's because aux is a reserved name on Windows.

neo cli run main.go won't work

Will get this panic:
panic: template: application-build-1454079793108505400.exe:1887: unexpected unrecognized character in action: U+FFFD '�' in command

There're many useless characters in log, which can not be displayed correctly on windows and get panic.

could we just remove them?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.