本文整理汇总了Golang中github.com/go-martini/martini.NewRouter函数的典型用法代码示例。如果您正苦于以下问题:Golang NewRouter函数的具体用法?Golang NewRouter怎么用?Golang NewRouter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewRouter函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Start
func Start() {
r := martini.NewRouter()
m := martini.New()
m.Use(martini.Logger())
m.Use(martini.Recovery())
m.MapTo(r, (*martini.Routes)(nil))
m.Action(r.Handle)
// Gitchain API
r.Post("/rpc", jsonRpcService().ServeHTTP)
r.Get("/info", info)
// Git Server
r.Post("^(?P<path>.*)/git-upload-pack$", func(params martini.Params, req *http.Request) string {
body, _ := ioutil.ReadAll(req.Body)
fmt.Println(req, body)
return params["path"]
})
r.Post("^(?P<path>.*)/git-receive-pack$", func(params martini.Params, req *http.Request) string {
fmt.Println(req)
return params["path"]
})
r.Get("^(?P<path>.*)/info/refs$", func(params martini.Params, req *http.Request) (int, string) {
body, _ := ioutil.ReadAll(req.Body)
fmt.Println(req, body)
return 404, params["path"]
})
log.Fatal(http.ListenAndServe(fmt.Sprintf("127.0.0.1:%d", env.Port), m))
}
开发者ID:josephyzhou,项目名称:gitchain,代码行数:34,代码来源:http.go
示例2: main
func main() {
conf.Env().Flag()
r := martini.NewRouter()
m := martini.New()
if conf.UBool("debug") {
m.Use(martini.Logger())
}
m.MapTo(r, (*martini.Routes)(nil))
m.Action(r.Handle)
session, err := mgo.Dial(conf.UString("mongo.uri"))
if err != nil {
panic(err)
}
session.SetMode(mgo.Monotonic, true)
db := session.DB(conf.UString("mongodb.database"))
logger := log.New(os.Stdout, "\x1B[36m[cdn] >>\x1B[39m ", 0)
m.Map(logger)
m.Map(db)
r.Group("", cdn.Cdn(cdn.Config{
MaxSize: conf.UInt("maxSize"),
ShowInfo: conf.UBool("showInfo"),
TailOnly: conf.UBool("tailOnly"),
}))
logger.Println("Server started at :" + conf.UString("port", "5000"))
_err := http.ListenAndServe(":"+conf.UString("port", "5000"), m)
if _err != nil {
logger.Printf("\x1B[31mServer exit with error: %s\x1B[39m\n", _err)
os.Exit(1)
}
}
开发者ID:gitter-badger,项目名称:cdn-1,代码行数:34,代码来源:cdn.go
示例3: Route
// Route return the route handler for this
func (s ServiceRegistryWebService) Route() martini.Router {
r := martini.NewRouter()
r.Group("/apiversions/", func(r martini.Router) {
r.Get("", s.getAPIVersions)
r.Post("", binding.Bind(common.APIVersion{}), s.createAPIVersion)
})
r.Group("/apiversions/:version/", func(r martini.Router) {
r.Get("", s.getAPIVersion)
r.Get("services/", s.getAPIServices)
r.Post("services/", binding.Bind(common.ServiceVersion{}), s.createAPIService)
})
r.Group("/services/", func(r martini.Router) {
r.Get("", s.getServices)
r.Post("", binding.Bind(common.ServiceDefinition{}), s.createService)
r.Delete(":service/", s.dropService)
})
r.Group("/services/:service/versions", func(r martini.Router) {
r.Get("", s.getServiceVersions)
r.Post("", binding.Bind(common.ServiceVersion{}), s.createServiceVersion)
})
r.Group("/services/:service/:version/hosts/", func(r martini.Router) {
r.Get("", s.getServiceHosts)
r.Post("", binding.Bind(common.ServiceHost{}), s.attachServiceHost)
})
return r
}
开发者ID:enzian,项目名称:go-msf,代码行数:32,代码来源:ServiceRegistryWebService.go
示例4: formTestMartini
func formTestMartini() *martini.Martini {
config := configuration.ReadTestConfigInRecursive()
mainDb := db.NewMainDb(config.Main.Database.ConnString, config.Main.Database.Name)
m := web.NewSessionAuthorisationHandler(mainDb)
m.Use(render.Renderer(render.Options{
Directory: "templates/auth",
Extensions: []string{".tmpl", ".html"},
Charset: "UTF-8",
}))
router := martini.NewRouter()
router.Get("/", func(r render.Render) {
r.HTML(200, "login", nil)
})
router.Group("/test", func(r martini.Router) {
r.Get("/:id", func(ren render.Render, prms martini.Params) {
id := prms["id"]
ren.JSON(200, map[string]interface{}{"id": id})
})
r.Get("/new", func(ren render.Render) {
ren.JSON(200, nil)
})
r.Get("/update/:id", func(ren render.Render, prms martini.Params) {
id := prms["id"]
ren.JSON(200, map[string]interface{}{"id": id})
})
r.Get("/delete/:id", func(ren render.Render, prms martini.Params) {
id := prms["id"]
ren.JSON(200, map[string]interface{}{"id": id})
})
})
m.Action(router.Handle)
return m
}
开发者ID:AlexeyProskuryakov,项目名称:kukuau_api_bot,代码行数:34,代码来源:test_routing.go
示例5: Test_todoapp_500
func Test_todoapp_500(t *testing.T) {
m := setupMartini()
r := martini.NewRouter()
m.Action(r.Handle)
hostname := currentHostname
defer func() {
currentHostname = hostname
}()
currentHostname = "will_cause_error"
r.Get("/api/ip", DataHandler("ip"))
response := httptest.NewRecorder()
req, err := http.NewRequest("GET", "http://localhost:4005/api/ip", nil)
if err != nil {
t.Fatal(err)
}
m.ServeHTTP(response, req)
Expect(t, response.Code, http.StatusInternalServerError)
body := response.Body.String()
Contain(t, body, `<h1>500 - Internal Server Error</h1>`)
Contain(t, body, `<h4>lookup will_cause_error: no such host</h4>`)
}
开发者ID:Cergoo,项目名称:dashboard,代码行数:25,代码来源:dashboard_test.go
示例6: main
// How to use Martini properly with Defer Panic client library
func main() {
dps := deferstats.NewClient("z57z3xsEfpqxpr0dSte0auTBItWBYa1c")
go dps.CaptureStats()
m := martini.New()
r := martini.NewRouter()
r.Get("/panic", func() string {
panic("There is no need for panic")
return "Hello world!"
})
r.Get("/slow", func() string {
time.Sleep(5 * time.Second)
return "Hello world!"
})
r.Get("/fast", func() string {
return "Hello world!"
})
m.MapTo(r, (*martini.Routes)(nil))
m.Action(r.Handle)
m.Use(middleware.Wrapper(dps))
m.RunOnAddr(":3000")
}
开发者ID:deferpanic,项目名称:dpmartini,代码行数:28,代码来源:example.go
示例7: StartWeb
func StartWeb() {
m := martini.Classic()
store := sessions.NewCookieStore([]byte("mandela"))
m.Use(sessions.Sessions("session", store))
m.Use(render.Renderer(render.Options{
Extensions: []string{".html"},
}))
m.Use(martini.Static("../../statics"))
r := martini.NewRouter()
r.Get("/", Home_handler) //首页
r.Get("/getdomain", GetDomain_handler) //获得本机的域名
m.Action(r.Handle)
webPort := 80
for i := 0; i < 1000; i++ {
_, err := net.ListenPacket("udp", ":"+strconv.Itoa(webPort))
if err != nil {
webPort = webPort + 1
} else {
break
}
}
m.RunOnAddr(":" + strconv.Itoa(webPort))
m.Run()
}
开发者ID:cokeboL,项目名称:mandela,代码行数:30,代码来源:web.go
示例8: launchFrontend
func launchFrontend() {
m := martini.New()
m.Use(martini.Static("static"))
m.Use(martini.Recovery())
m.Use(martini.Logger())
r := martini.NewRouter()
r.Get("/", indexHandler)
r.Get("/following", followHandler)
r.Get("/stat", statHandler)
r.Get("/channel/:streamer", channelHandler)
r.Get("/add/:streamer", addHandler)
r.Get("/del/:streamer", delHandler)
r.Get("/api/stat/:streamer", apiStat)
r.Get("/api/channel/:streamer", apiStat)
r.Get("/api/following", apiFollowing)
db := getDB()
redis := getRedis()
m.Map(db)
m.Map(redis)
m.Action(r.Handle)
log.Print("Started Web Server")
m.Run()
}
开发者ID:grsakea,项目名称:kappastat,代码行数:25,代码来源:web.go
示例9: init
func init() {
m = martini.New()
//set up middleware
m.Use(martini.Recovery())
m.Use(martini.Logger())
m.Use(auth.Basic(AuthToken, ""))
m.Use(MapEncoder)
// set up routes
r := martini.NewRouter()
r.Get(`/albums`, GetAlbums)
r.Get(`/albums/:id`, GetAlbum)
r.Post(`/albums`, AddAlbum)
r.Put(`/albums/:id`, UpdateAlbum)
r.Delete(`/albums/:id`, DeleteAlbum)
// inject database
// maps db package variable to the DB interface defined in data.go
// The syntax for the second parameter may seem weird,
// it is just converting nil to the pointer-to-DB-interface type,
// because all the injector needs is the type to map the first parameter to.
m.MapTo(db, (*DB)(nil))
// add route action
// adds the router’s configuration to the list of handlers that Martini will call.
m.Action(r.Handle)
}
开发者ID:pyanfield,项目名称:martini_demos,代码行数:28,代码来源:server.go
示例10: setupMultiple
func setupMultiple(mockEndpoints []MockRoute) {
mux = http.NewServeMux()
server = httptest.NewServer(mux)
fakeUAAServer = FakeUAAServer()
m := martini.New()
m.Use(render.Renderer())
r := martini.NewRouter()
for _, mock := range mockEndpoints {
method := mock.Method
endpoint := mock.Endpoint
output := mock.Output
if method == "GET" {
r.Get(endpoint, func() string {
return output
})
} else if method == "POST" {
r.Post(endpoint, func() string {
return output
})
}
}
r.Get("/v2/info", func(r render.Render) {
r.JSON(200, map[string]interface{}{
"authorization_endpoint": fakeUAAServer.URL,
"token_endpoint": fakeUAAServer.URL,
"logging_endpoint": server.URL,
})
})
m.Action(r.Handle)
mux.Handle("/", m)
}
开发者ID:shinji62,项目名称:go-cfclient,代码行数:33,代码来源:cf_test.go
示例11: createRouter
// Create the router.
func createRouter() martini.Router {
router := martini.NewRouter()
router.Get("/api/feed/list", api.FeedList())
router.Get("/api/feed/subscription", api.IsSubscribed())
router.Post("/api/feed/subscription", api.Subscribe())
router.Post("/api/feed/id/:id", api.Update())
router.Get("/api/feed/id/:id", api.FeedInfo())
router.Put("/api/feed/id/:id", api.UpdateFeedAndTags())
router.Delete("/api/feed/id/:id", api.DeleteFeed())
router.Get("/api/articles/random", api.RandomArticleList())
router.Get("/api/articles/unread/:limit/:offset", api.ArticleList("unread"))
router.Get("/api/articles/fid/:fid/:limit/:offset", api.ArticleList("fid"))
router.Get("/api/articles/tag/:tag/:limit/:offset", api.ArticleList("tag"))
router.Get("/api/articles/starred/:limit/:offset", api.ArticleList("starred"))
router.Get("/api/articles/search/:deflimit", api.SearchList())
router.Put("/api/articles/read", api.MarkArticlesRead())
router.Put("/api/articles/starred", api.MarkArticlesStarred())
router.Get("/api/article/content/:id", api.Article())
router.Put("/api/article/read/:id", api.MarkReadStatus(true)) // mark read
router.Put("/api/article/unread/:id", api.MarkReadStatus(false)) // mark unread
router.Get("/api/tags/list", api.TagsList())
router.Get("/api/system/settings", api.Settings())
router.Put("/api/system/shutdown", api.CloseServer())
router.Get("/api/", api.Status()) // do not need api token
router.Get("/api/checktoken", api.Status()) // check api token
router.Any("/api/**", api.Default())
return router
}
开发者ID:huangwangping,项目名称:qreader,代码行数:31,代码来源:server.go
示例12: BenchmarkCodegangstaNegroni_Composite
func BenchmarkCodegangstaNegroni_Composite(b *testing.B) {
namespaces, resources, requests := resourceSetup(10)
martiniMiddleware := func(rw http.ResponseWriter, r *http.Request, c martini.Context) {
c.Next()
}
handler := func(rw http.ResponseWriter, r *http.Request, c *martiniContext) {
fmt.Fprintf(rw, c.MyField)
}
r := martini.NewRouter()
m := martini.New()
m.Use(func(rw http.ResponseWriter, r *http.Request, c martini.Context) {
c.Map(&martiniContext{MyField: r.URL.Path})
c.Next()
})
m.Use(martiniMiddleware)
m.Use(martiniMiddleware)
m.Use(martiniMiddleware)
m.Use(martiniMiddleware)
m.Use(martiniMiddleware)
m.Action(r.Handle)
for _, ns := range namespaces {
for _, res := range resources {
r.Get("/"+ns+"/"+res, handler)
r.Post("/"+ns+"/"+res, handler)
r.Get("/"+ns+"/"+res+"/:id", handler)
r.Put("/"+ns+"/"+res+"/:id", handler)
r.Delete("/"+ns+"/"+res+"/:id", handler)
}
}
benchmarkRoutes(b, m, requests)
}
开发者ID:rexk,项目名称:golang-mux-benchmark,代码行数:35,代码来源:mux_bench_test.go
示例13: startMartini
func startMartini() {
mux := martini.NewRouter()
mux.Get("/hello", martiniHandlerWrite)
martini := martini.New()
martini.Action(mux.Handle)
http.ListenAndServe(":"+strconv.Itoa(port), martini)
}
开发者ID:cokeboL,项目名称:go-web-framework-benchmark,代码行数:7,代码来源:server.go
示例14: main
func main() {
username, password := waitForPostgres(serviceName)
db, err := postgres.Open(serviceName, fmt.Sprintf("dbname=postgres user=%s password=%s", username, password))
if err != nil {
log.Fatal(err)
}
r := martini.NewRouter()
m := martini.New()
m.Use(martini.Logger())
m.Use(martini.Recovery())
m.Use(render.Renderer())
m.Action(r.Handle)
m.Map(db)
r.Post("/databases", createDatabase)
r.Get("/ping", ping)
port := os.Getenv("PORT")
if port == "" {
port = "3000"
}
addr := ":" + port
if err := discoverd.Register(serviceName+"-api", addr); err != nil {
log.Fatal(err)
}
log.Fatal(http.ListenAndServe(addr, m))
}
开发者ID:kelsieflynn,项目名称:flynn-postgres,代码行数:30,代码来源:server.go
示例15: BenchmarkCodegangstaMartini_Middleware
func BenchmarkCodegangstaMartini_Middleware(b *testing.B) {
martiniMiddleware := func(rw http.ResponseWriter, r *http.Request, c martini.Context) {
c.Next()
}
r := martini.NewRouter()
m := martini.New()
m.Use(martiniMiddleware)
m.Use(martiniMiddleware)
m.Use(martiniMiddleware)
m.Use(martiniMiddleware)
m.Use(martiniMiddleware)
m.Use(martiniMiddleware)
m.Action(r.Handle)
r.Get("/action", helloHandler)
rw, req := testRequest("GET", "/action")
b.ResetTimer()
for i := 0; i < b.N; i++ {
m.ServeHTTP(rw, req)
if rw.Code != 200 {
panic("no good")
}
}
}
开发者ID:rexk,项目名称:golang-mux-benchmark,代码行数:27,代码来源:mux_bench_test.go
示例16: main
func main() {
db, err := bolt.Open("mpush.db", 0666, nil)
if err != nil {
log.Fatal(err)
}
defer db.Close()
m := martini.Classic()
m.Use(render.Renderer())
// Setup routes
r := martini.NewRouter()
r.Get(`/api/v0/lists`, allLists)
r.Get(`/api/v0/lists/:id`, findList)
r.Post(`/api/v0/lists`, createList)
r.Put(`/api/v0/lists/:id`, updateList)
r.Delete(`/api/v0/lists/:id`, removeList)
r.Post("/api/v0/push", pushHandler)
// Inject database
m.Map(db)
// Add the router action
m.Action(r.Handle)
m.Run()
}
开发者ID:KanwarGill,项目名称:trifles,代码行数:31,代码来源:main.go
示例17: init
func init() {
m = martini.New()
// I could probably just use martini.Classic() instead of configure these manually
// Static files
m.Use(martini.Static(`public`))
// Setup middleware
m.Use(martini.Recovery())
m.Use(martini.Logger())
// m.Use(auth.Basic(AuthToken, ""))
m.Use(MapEncoder)
// Setup routes
r := martini.NewRouter()
r.Get(`/albums`, server.GetAlbums)
r.Get(`/albums/:id`, server.GetAlbum)
r.Post(`/albums`, server.AddAlbum)
r.Put(`/albums/:id`, server.UpdateAlbum)
r.Delete(`/albums/:id`, server.DeleteAlbum)
// Inject database
m.MapTo(server.DBInstance, (*server.DB)(nil))
// Add the router action
m.Action(r.Handle)
}
开发者ID:ivanbportugal,项目名称:go-albums,代码行数:26,代码来源:main.go
示例18: createRoutes
func createRoutes() {
router = martini.NewRouter()
router.Get("/proberequests", GetAllProbeRequests)
router.Get("/count", GetProbeRequestCount)
m.MapTo(router, (*martini.Routes)(nil))
m.Action(router.Handle)
}
开发者ID:dereulenspiegel,项目名称:wifidetector,代码行数:7,代码来源:server.go
示例19: resetRouter
func (server *Server) resetRouter() {
router := martini.NewRouter()
server.martini.Router = router
server.martini.MapTo(router, (*martini.Routes)(nil))
server.martini.Action(router.Handle)
server.addOptionsRoute()
}
开发者ID:gitter-badger,项目名称:gohan,代码行数:7,代码来源:server.go
示例20: main
/*
Application entry point
*/
func main() {
m := martini.New()
//Set middleware
m.Use(martini.Recovery())
m.Use(martini.Logger())
m.Use(cors.Allow(&cors.Options{
AllowOrigins: []string{"*"},
AllowMethods: []string{"OPTIONS", "HEAD", "POST", "GET", "PUT"},
AllowHeaders: []string{"Authorization", "Content-Type"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
}))
//Create the router
r := martini.NewRouter()
//Options matches all and sends okay
r.Options(".*", func() (int, string) {
return 200, "ok"
})
api.SetupTodoRoutes(r)
api.SetupCommentRoutes(r)
mscore.StartServer(m, r)
fmt.Println("Started NSQ Test service")
}
开发者ID:newsquid,项目名称:newsquidtest,代码行数:32,代码来源:main.go
注:本文中的github.com/go-martini/martini.NewRouter函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论