GithubHelp home page GithubHelp logo

zdfccdanfeng / cedar Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tungyao/cedar

0.0 1.0 0.0 1.28 MB

Prefix Tree Go Router

Home Page: https://www.oschina.net/p/cedar-router

License: GNU General Public License v3.0

Go 92.14% HTML 7.86%

cedar's Introduction

Router on prefix tree algorithm ๐Ÿ˜€

all structure

cedar.NewRouter().Get(prefix,http.HandlerFunc,http.Handler)

Only one can take effect

update

  • Add new function: global function

it can to record logs and so on

r.GlobalFunc("test", func(w http.ResponseWriter,r *http.Request) error {
   	fmt.Println("123213")
   	return nil
})

Example

Normal

r := cedar.NewRouter()
r.Get("/",http.HandlerFunc(),nil)
r.Post("/",http.HandlerFunc(),nil)
r.Put("/",http.HandlerFunc(),nil)
r.Delete("/",http.HandlerFunc(),nil)
if err := http.ListenAndServe(":80", r); err != nil {
	log.Panicln(err)
}

Group

r := cedar.NewRouter()
r.Group("/",func (group *cedar.Groups){
    group.Get("/",http.HandlerFunc(),nil)
    group.Group("/x",func(groups *cedar.Groups) {
        group.Get("/x",http.HandlerFunc(),nil)
    })
})
if err := http.ListenAndServe(":80", r); err != nil {
	log.Panicln(err)
}

RestFul

r := cedar.NewRestRouter(cedar.RestConfig{
		EntryPath: "yashua",
		ApiName:   "api",
        Pattern:"." `new*`

})
r.Get(api,fn,handler)
r.Post(api,fn,handler)
r.Put(api,fn,handler)
r.Delete(api,fn,handler)
r.Group(path,func(groups *cedar.Group{
    r.Get(api,fn,handler)
})

exp

r.Get("user.add", func(writer http.ResponseWriter, request *http.Request) {
 		_, _ = fmt.Fprintln(writer, "hello")
})

localhost/wechat?api=user.add The "Pattern" is there ,you can use other punctuation marks

Other Exp

Usage

next time

cedar's People

Contributors

tungyao avatar

Watchers

James Cloos avatar

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.