:tongue: CleverGo is a lightweight, feature rich and high performance HTTP router for Go.

Overview

CleverGo

Build Status Coverage Status Go Report Card Go.Dev reference Release Downloads Chat Community

CleverGo is a lightweight, feature rich and trie based high performance HTTP request router.

go get -u clevergo.tech/clevergo

Benchmark

Features

  • Full features of HTTP router.
  • High Performance: extremely fast, see Benchmark.
  • Gradual learning curve: you can learn the entire usages by going through the documentation in half an hour.
  • Reverse Route Generation: allow generating URLs by named route or matched route.
  • Route Group: as known as subrouter.
  • Friendly to APIs: it is easy to design RESTful APIs and versioning your APIs by route group.
  • Middleware: plug middleware in route group or particular route, supports global middleware as well. Compatible with most of third-party middleware.
  • Logger: a generic logger interface, supports zap and logrus. Logger can be used in middleware or handler.
  • ...

Examples

Checkout example for details.

Contribute

Contributions are welcome.

  • Star it and spread the package.
  • File an issue to ask questions, request features or report bugs.
  • Fork and make a pull request.
  • Improve documentations.

Credit

See CREDIT.md.

Comments
  • Render 覆盖已设置 Content-Type Header

    Render 覆盖已设置 Content-Type Header

    c.SetHeader("Content-Type", "application/javascript; charset=utf-8")
    return c.Render(200, "index.html", data)
    

    期望

    Content-Type: application/javascript; charset=utf-8
    

    结果

    Content-Type: text/html; charset=utf-8
    

    https://github.com/clevergo/clevergo/blob/master/context.go#L350 这里强制使用 headerContentTypeHTML 覆盖了原 Content-Type

    opened by beikege 5
  • 路由功能加强

    路由功能加强

    建议支持这种路由

    r.Get("/a", func(c *clevergo.Context) error {
    	return c.String(http.StatusOK, "/a")
    })
    r.Get("/a/b", func(c *clevergo.Context) error {
    	return c.String(http.StatusOK, "/a/b")
    })
    // 优先级最低
    r.Get("/*any", func(c *clevergo.Context) error {
    	return c.String(http.StatusOK, c.Params.String("any"))
    })
    

    当前提示

    panic: wildcard segment '*any' conflicts with existing children in path '/*any'
    
    opened by beikege 4
  • Context enhancement

    Context enhancement

    • [x] Context.SetCookie: already done since v1.6
    • [x] Context.Cookies and Context.Cookie
    • [x] Context.Emit, Context.Blob
    • [x] Context.JSON, Context.JSONBlob
    • [x] Context.JSONP, Context.JSONPCallback, Context.JSONPBlob, Context.JSONPCallbackBlob
    • [x] Context.XML, Context.XMLBlob
    • [x] Context.String
    • [x] Context.HTML, Context.HTMLBlob
    • [x] Context.FormValue
    • [x] Context.PostFormValue
    • [x] Context.QueryString, Context.QueryParams and Context.QueryParam
    • [x] Context.Render: renders a template. Renderer implementation:
    • [x] Context.RouteURL: generates the URL of naming route.
    enhancement 
    opened by razonyang 3
  • 如何在中间件中获取ctx.Response响应状态?

    如何在中间件中获取ctx.Response响应状态?

    当前无法获取 ctx.Response 状态码

    func TimeShow(next clevergo.Handle) clevergo.Handle {
    	return func(ctx *clevergo.Context) error {
    		start := time.Now()
    		next(ctx)
    		// ctx.Response.Status()
    		fmt.Printf("%s %s %d\n", time.Since(start).String(), ctx.Request.URL.String(), 200)
    		return nil
    	}
    }
    

    需要包装 http.ResponseWriter 接口

    type ResponseWriter struct {
    	http.ResponseWriter
    	size   int
    	status int
    	written bool
    }
    
    opened by beikege 2
  • /hello/xxx/  match route   app.Get(

    /hello/xxx/ match route app.Get("/hello/:name" should be 404 not 301

    Describe the bug http://localhost:8080/hello/aa retrun 200 http://localhost:8080/hello/aa/ return 301 should be 404

    To Reproduce Steps to reproduce the behavior: 1. test.go

    package main
    import (
    	"fmt"
    	"net/http"
    
    	"clevergo.tech/clevergo"
    )
    func hello(c *clevergo.Context) error {
    	return c.String(http.StatusOK, fmt.Sprintf("Hello %s!", c.Params.String("name")))
    }
    
    func main() {
    	app := clevergo.New()
    	app.Get("/hello/:name", hello)   
    	app.Run(":8080")
    }
    

    go run test.go 2. curl curl http://localhost:8080/hello/aa/ Expected behavior A clear and concise description of what you expected to happen.

    curl http://localhost:8080/hello/aa/ return 404 like net/http main.go

    package main
    import (
        "fmt"
        "net/http"
    )
    func main() {
        http.HandleFunc("/hello/aa", func (w http.ResponseWriter, r *http.Request) {
            fmt.Fprintf(w, "Welcome to my website!")
        })
       http.ListenAndServe(":80", nil)
    }
    go run main.go 
    

    curl http://localhost:80/hello/aa/ return 404 page not found

    Additional context Add any other context about the problem here.

    question 
    opened by tablecell 1
  • session  doc  from https://clevergo.tech/zh/basics/session/ is empty

    session doc from https://clevergo.tech/zh/basics/session/ is empty

    Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

    Describe the solution you'd like A clear and concise description of what you want to happen.

    Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

    Additional context Add any other context or screenshots about the feature request here.

    opened by tablecell 1
  • 建议添加一些常用的快捷输出方法.

    建议添加一些常用的快捷输出方法.

    类似echo框架

    JSON(code int, i interface{}) error
    HTML(code int, html string) error
    String(code int, s string) error
    Render(code int, name string, data interface{}) error
    Cookies() []*http.Cookie
    Cookie(name string) (*http.Cookie, error)
    SetCookie(cookie *http.Cookie)
    ...
    

    框架很好用👍感谢作者,有没有电报交流群?

    enhancement todo 
    opened by beikege 1
  • 中间件优先级疑问

    中间件优先级疑问

    英文太差,请原谅我使用中文.

    package main
    
    import (
    	"fmt"
    	"net/http"
    
    	"github.com/clevergo/clevergo"
    )
    
    func middleware(name string) clevergo.MiddlewareFunc {
    	return func(next clevergo.Handle) clevergo.Handle {
    		return func(ctx *clevergo.Context) error {
    			fmt.Printf("开始: %s\n", name)
    			if err := next(ctx); err != nil {
    				return err
    			}
    			fmt.Printf("结束: %s\n", name)
    			return nil
    		}
    	}
    }
    
    func myHandle(ctx *clevergo.Context) error {
    	fmt.Println("执行: handle")
    	return nil
    }
    
    func main() {
    	router := clevergo.NewRouter()
    	router.Use(middleware("全局中间件"))
    
    	test := router.Group("/test", clevergo.RouteGroupMiddleware(middleware("路由组中间件")))
    	test.Get("/abc", myHandle, clevergo.RouteMiddleware(middleware("路由中间件")))
    
    	http.ListenAndServe(":80", router)
    }
    
    http://127.0.0.1/test/abc
    
    输出:
    开始: 全局中间件
    开始: 路由中间件
    开始: 路由组中间件
    执行: handle
    结束: 路由组中间件
    结束: 路由中间件
    结束: 全局中间件
    

    路由中间件的优先级高于路由组的,是否合理?

    bug 
    opened by beikege 1
  • Activating Open Collective

    Activating Open Collective

    Hi, I'm making updates for Open Collective. Either you or another core contributor signed this repository up for Open Collective. This pull request adds financial contributors from your Open Collective https://opencollective.com/clevergo ❤️

    What it does:

    • adds a badge to show the latest number of financial contributors
    • adds a banner displaying contributors to the project on GitHub
    • adds a banner displaying all individuals contributing financially on Open Collective
    • adds a section displaying all organizations contributing financially on Open Collective, with their logo and a link to their website

    P.S: As with any pull request, feel free to comment or suggest changes.

    Thank you for your great contribution to the Open Source community. You are awesome! 🙌 And welcome to the Open Collective community! 😊

    Come chat with us in the #opensource channel on https://slack.opencollective.com - great place to ask questions and share best practices with other Open Source sustainers!

    opened by monkeywithacupcake 1
  • Add a Gitter chat badge to README.md

    Add a Gitter chat badge to README.md

    go-gem/gem now has a Chat Room on Gitter

    @ruishengyang has just created a chat room. You can visit it here: https://gitter.im/go-gem/gem.

    This pull-request adds this badge to your README.md:

    Gitter

    If my aim is a little off, please let me know.

    Happy chatting.

    PS: Click here if you would prefer not to receive automatic pull-requests from Gitter in future.

    opened by gitter-badger 1
  • Change module path

    Change module path

    Changes:

    • Import path was changed from github.com/clevergo/clevergo to clevergo.tech/clevergo.
    • Router was renamed as Application.
    • NewRouter was deleted, and New was introduced for creating an application.
    • IRouter was renamed as Router.
    • Context improvements:
      • Context.Host: returns the host of request.
      • Context.Context: returns the context.Context of request.

    The module path was changed, but it won't break things while using original path. The only impact I can think of is that the original module will not be updated and maintained anymore.

    opened by razonyang 0
Releases(v0.6.0)
Owner
CleverGo Web Framework
Toolkits for building web applications and services.
CleverGo Web Framework
A high performance HTTP request router that scales well

HttpRouter HttpRouter is a lightweight high performance HTTP request router (also called multiplexer or just mux for short) for Go. In contrast to the

Julien Schmidt 13.5k Dec 9, 2021
A high performance fasthttp request router that scales well

FastHttpRouter FastHttpRouter is forked from httprouter which is a lightweight high performance HTTP request router (also called multiplexer or just m

招牌疯子 871 Dec 1, 2022
:rotating_light: Is a lightweight, fast and extensible zero allocation HTTP router for Go used to create customizable frameworks.

LARS LARS is a fast radix-tree based, zero allocation, HTTP router for Go. view examples. If looking for a more pure Go solution, be sure to check out

Go Playgound 389 Nov 18, 2022
lightweight, idiomatic and composable router for building Go HTTP services

chi is a lightweight, idiomatic and composable router for building Go HTTP services. It's especially good at helping you write large REST API services

go-chi 12.7k Dec 4, 2022
Fast, simple, and lightweight HTTP router for Golang

Sariaf Fast, simple and lightweight HTTP router for golang Install go get -u github.com/majidsajadi/sariaf Features Lightweight compatible with net/ht

defectivepixel 33 Aug 19, 2022
Lightweight Router for Golang using net/http standard library with custom route parsing, handler and context.

Go-Lightweight-Router Lightweight Router for Golang using net/http standard library with custom route parsing, handler and context. Further developmen

null 0 Nov 3, 2021
High-speed, flexible tree-based HTTP router for Go.

httptreemux High-speed, flexible, tree-based HTTP router for Go. This is inspired by Julien Schmidt's httprouter, in that it uses a patricia tree, but

Daniel Imfeld 566 Nov 25, 2022
Bxog is a simple and fast HTTP router for Go (HTTP request multiplexer).

Bxog is a simple and fast HTTP router for Go (HTTP request multiplexer). Usage An example of using the multiplexer: package main import ( "io" "net

Eduard 105 Sep 27, 2022
xujiajun/gorouter is a simple and fast HTTP router for Go. It is easy to build RESTful APIs and your web framework.

gorouter xujiajun/gorouter is a simple and fast HTTP router for Go. It is easy to build RESTful APIs and your web framework. Motivation I wanted a sim

徐佳军 532 Oct 30, 2022
A powerful HTTP router and URL matcher for building Go web servers with 🦍

gorilla/mux https://www.gorillatoolkit.org/pkg/mux Package gorilla/mux implements a request router and dispatcher for matching incoming requests to th

Gorilla Web Toolkit 17.9k Dec 8, 2022
Fast and flexible HTTP router

treemux - fast and flexible HTTP router Basic example Debug logging CORS example Error handling Rate limiting using Redis Gzip compression OpenTelemet

Vladimir Mihailenco 507 Nov 29, 2022
Go HTTP request router and web framework benchmark

Go HTTP Router Benchmark This benchmark suite aims to compare the performance of HTTP request routers for Go by implementing the routing structure of

Peter Kieltyka 27 Oct 4, 2022
Simple Golang HTTP router

Bellt Simple Golang HTTP router Bellt Package implements a request router with the aim of managing controller actions based on fixed and parameterized

Guilherme Caruso 55 Sep 27, 2022
FastRouter is a fast, flexible HTTP router written in Go.

FastRouter FastRouter is a fast, flexible HTTP router written in Go. FastRouter contains some customizable options, such as TrailingSlashesPolicy, Pan

Razon Yang 22 Sep 27, 2022
Go Server/API micro framework, HTTP request router, multiplexer, mux

?? gorouter Go Server/API micro framework, HTTP request router, multiplexer, mux. ?? ABOUT Contributors: Rafał Lorenz Want to contribute ? Feel free t

Rafał Lorenz 139 Nov 27, 2022
An extremely fast Go (golang) HTTP router that supports regular expression route matching. Comes with full support for building RESTful APIs.

ozzo-routing You may consider using go-rest-api to jumpstart your new RESTful applications with ozzo-routing. Description ozzo-routing is a Go package

Ozzo Framework 445 Nov 15, 2022
Pure is a fast radix-tree based HTTP router

package pure Pure is a fast radix-tree based HTTP router that sticks to the native implementations of Go's "net/http" package; in essence, keeping the

Go Playgound 132 Dec 1, 2022
Go HTTP router

violetear Go HTTP router http://violetear.org Design Goals Keep it simple and small, avoiding extra complexity at all cost. KISS Support for static an

Nicolas Embriz 105 Sep 27, 2022
Simple router build on `net/http` supports custom middleWare.

XMUS-ROUTER Fast lightweight router build on net/http supports delegate and in url params. usage : Create new router using NewRouter() which need rout

amupxm [amir hossein mokarrami far] 5 Dec 27, 2021