Giter Club home page Giter Club logo

gorouter's Introduction

Hi there 👋

Recruit developers to build the kv database engine NutsDB together 招募开发者一起共建开源的KV数据库引擎NutsDB,有想法联系我。(wechat:xujiajun1234567,备注:nutsdb)

Project address:https://github.com/nutsdb/nutsdb

Hope to build nutsdb together(希望共建nutsdb):nutsdb/nutsdb#116

gorouter's People

Contributors

allisson avatar tadvi avatar thehippo avatar vision9527 avatar xpzouying avatar xujiajun avatar yaodingyd 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

gorouter's Issues

Which CPU was used for your benchmarks?

Your current benchmark doesn't say which CPU model you're using for the benchmark. This is probably the most important part to include. I assume you're running some pre 7th-gen Intel i5/i7 CPU since it's on a Mac with DDR3 RAM.

Benchmark System:
Go Version : go1.11.2 darwin/amd64
OS: Mac OS X 10.13.6
Architecture: x86_64
RAM; 16 GB 2133 MHz LPDDR3
CPU: ???

Benchmark is not (only) measuring the routing cost

Currently your benchmark code does the following:

func benchRoutes(b *testing.B, router http.Handler, routes []route) {
	b.N = 10000
	b.ReportAllocs()
	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		for _, route := range routes {
			router.ServeHTTP(httptest.NewRecorder(), httptest.NewRequest(route.method, route.path, nil))
		}
	}
}

The critical part is the router.ServeHTTP(httptest.NewRecorder(), httptest.NewRequest(route.method, route.path, nil)) within the loop, meaning that you allocate and initialize a new Recorder and a Request in every loop iteration.
Unfortunately that is likely much more expensive than the actual routing, meaning that both the measured memory cost and the execution time are completely meaningless, since there is a huge baseline cost.

static file handler is too complex

user need to add url partern for every depth folder ?
is there a short way to match a total folder as below

// FileSystem custom file system handler
type FileSystem struct {
    fs http.FileSystem
}

// Open opens file
func (fs FileSystem) Open(path string) (http.File, error) {
    f, err := fs.fs.Open(path)
    if err != nil {
        return nil, err
    }

    s, err := f.Stat()
    if s.IsDir() {
        index := strings.TrimSuffix(path, "/") + "/index.html"
        if _, err := fs.fs.Open(index); err != nil {
            return nil, err
        }
    }

    return f, nil
}


fileServer := http.FileServer(FileSystem{http.Dir(".")})
http.Handle("/static/", http.StripPrefix(strings.TrimRight("/static/", "/"), fileServer))

How to remove regex from :id and :name parameters?

I like the idea of this router, and I'm planning on using it for an upcoming project. However the automatic regex matching for :id and :name is bothering me. I don't want to use it, and if I do, I'll provide my own regex. How do I prevent any regex matching from happening for those parameters?

I don't think it's a good idea to assume the regex that people want to use for random parameters, it can cause bugs and other problems. But that's just my opinion.

Router always return 404 response code.

Router always return 404 response header
"Hello world!" run the same with error code.

# go version 
go version go1.13.7 linux/amd64

# curl  localhost:8181 
hello world

# curl  localhost:8181 -I 
HTTP/1.1 404 Not Found

Are there any plans to support reverse routing?

Your router looks very attractive from a performance perspective.

But it looks like it is missing a very important feature for REST API that is reverse routing.

I am widely using gorilla/mux along with its reverse routing right now and would like to find a faster alternative for it.

If your router would have this feature, it would be very useful.

can't match suffix '/' in url

image

image

Server side code:

func main() {
	mux := gorouter.New()
	//url regex match
	mux.GET("/user/{id:[0-9]+}/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("match user/{id:[0-9]+} !"))
	})

	log.Fatal(http.ListenAndServe(":8181", mux))
}

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.