當前位置: 首頁>>代碼示例>>Golang>>正文


Golang martini.NewRouter函數代碼示例

本文整理匯總了Golang中github.com/codegangsta/martini.NewRouter函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewRouter函數的具體用法?Golang NewRouter怎麽用?Golang NewRouter使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewRouter函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: startGUI

func startGUI(addr string, m *model.Model) {
	router := martini.NewRouter()
	router.Get("/", getRoot)
	router.Get("/rest/version", restGetVersion)
	router.Get("/rest/model", restGetModel)
	router.Get("/rest/connections", restGetConnections)
	router.Get("/rest/config", restGetConfig)
	router.Get("/rest/need", restGetNeed)
	router.Get("/rest/system", restGetSystem)

	fs, err := embed.Unpack(Resources)
	if err != nil {
		panic(err)
	}

	go func() {
		mr := martini.New()
		mr.Use(embeddedStatic(fs))
		mr.Use(martini.Recovery())
		mr.Action(router.Handle)
		mr.Map(m)
		err := http.ListenAndServe(addr, mr)
		if err != nil {
			warnln("GUI not possible:", err)
		}
	}()

}
開發者ID:JoeX2,項目名稱:syncthing,代碼行數:28,代碼來源:gui.go

示例2: NewServer

// NewServer creates an instance of a martini server. The
// adapterInst parameter is the adapter type the server will
// use when dispatching requests.
func NewServer(adapterInst PanamaxAdapter) AdapterServer {
	s := martini.New()

	// Setup middleware
	s.Use(martini.Recovery())
	s.Use(martini.Logger())
	s.Use(mapEncoder)
	s.Use(func(c martini.Context, w http.ResponseWriter, r *http.Request) {
		c.Map(adapterInst)
	})
	// Setup routes
	router := martini.NewRouter()
	router.Group(fmt.Sprintf("/%s", APIVersion), func(r martini.Router) {
		r.Get(`/services`, getServices)
		r.Get(`/services/:id`, getService)
		r.Post(`/services`, createServices)
		r.Put(`/services/:id`, updateService)
		r.Delete(`/services/:id`, deleteService)
		r.Get(`/metadata`, getMetadata)
	})

	// Add the router action
	s.Action(router.Handle)
	server := martiniServer{svr: s}

	return &server
}
開發者ID:rupakg,項目名稱:pmxadapter,代碼行數:30,代碼來源:server.go

示例3: startGUI

func startGUI(cfg GUIConfiguration, m *Model) {
	router := martini.NewRouter()
	router.Get("/", getRoot)
	router.Get("/rest/version", restGetVersion)
	router.Get("/rest/model", restGetModel)
	router.Get("/rest/connections", restGetConnections)
	router.Get("/rest/config", restGetConfig)
	router.Get("/rest/config/sync", restGetConfigInSync)
	router.Get("/rest/system", restGetSystem)
	router.Get("/rest/errors", restGetErrors)

	router.Post("/rest/config", restPostConfig)
	router.Post("/rest/restart", restPostRestart)
	router.Post("/rest/reset", restPostReset)
	router.Post("/rest/error", restPostError)
	router.Post("/rest/error/clear", restClearErrors)

	go func() {
		mr := martini.New()
		if len(cfg.User) > 0 && len(cfg.Password) > 0 {
			mr.Use(basic(cfg.User, cfg.Password))
		}
		mr.Use(embeddedStatic())
		mr.Use(martini.Recovery())
		mr.Use(restMiddleware)
		mr.Action(router.Handle)
		mr.Map(m)
		err := http.ListenAndServe(cfg.Address, mr)
		if err != nil {
			warnln("GUI not possible:", err)
		}
	}()
}
開發者ID:nbrownus,項目名稱:syncthing,代碼行數:33,代碼來源:gui.go

示例4: main

func main() {
	// Load DB
	options := &bolt.Options{Timeout: 2 * time.Second}
	dbPath := path.Join(os.Getenv("BOLT_PATH"), "reminder.db")
	db, err := bolt.Open(dbPath, 0600, options)
	if err != nil {
		log.Fatalf("Error opening bolt DB: %v", err)
	}
	defer db.Close()

	// Schedule all (non-cancelled) Reminders
	rems, err := remind.GetAllReminders(db)
	if err != nil {
		log.Fatalf("Error getting reminders: %v\n", err)
	}

	runningReminders.Schedule(db, rems)

	//
	// Router, etc
	//

	r := martini.NewRouter()
	m := martini.New()
	m.Use(martini.Logger())
	m.Use(martini.Recovery())
	m.Action(r.Handle)

	m.Map(db)

	r.Post("/sms", incomingSMS)

	m.Run()
}
開發者ID:elimisteve,項目名稱:do_reminder,代碼行數:34,代碼來源:reminder.go

示例5: martiniInit

func martiniInit() {
	m := martini.New()
	r := martini.NewRouter()

	m.Map(db)
	//m.Use(sessions.Sessions("my_session", sessions.NewCookieStore([]byte("secret123"))))
	//m.Use(oauth2.Github(&oauth2.Options{
	// 	ClientId:	  "64a641523f31dd5bfe4b",
	// 	ClientSecret: "4fe3fbbca262835c424ca6a80aec6c6cb4228037",
	// 	RedirectURL:  "http://localhost:2714/github_callback",
	// 	Scopes:		  []string{"user:email"},
	//}))

	//r.Get("/", index)
	r.Get("/comments/:forum/:page", GetAllCommentsResource)
	r.Post("/comment", PostCommentHandler)
	//r.Get("/github_redirect", RedirectUrl)
	//r.Get("/github_callback", func(request *http.Request) string {
	// 	request.ParseForm()
	// 	return fmt.Sprintf("%+v", request)
	//})

	m.Use(martini.Static("ui"))
	m.Action(r.Handle)

	fmt.Println("Running on port " + viper.GetString("port"))

	sio.Handle("/", m)
	//http.Handle("/", m)
	//http.ListenAndServe(":"+viper.GetString("port"), m)
}
開發者ID:giorgil,項目名稱:kaiju,代碼行數:31,代碼來源:martini.go

示例6: startGUI

func startGUI(addr string, m *Model) {
	router := martini.NewRouter()
	router.Get("/", getRoot)
	router.Get("/rest/version", restGetVersion)
	router.Get("/rest/model", restGetModel)
	router.Get("/rest/connections", restGetConnections)
	router.Get("/rest/config", restGetConfig)
	router.Get("/rest/config/sync", restGetConfigInSync)
	router.Get("/rest/need", restGetNeed)
	router.Get("/rest/system", restGetSystem)
	router.Get("/rest/errors", restGetErrors)

	router.Post("/rest/config", restPostConfig)
	router.Post("/rest/restart", restPostRestart)
	router.Post("/rest/error", restPostError)

	go func() {
		mr := martini.New()
		mr.Use(embeddedStatic())
		mr.Use(martini.Recovery())
		mr.Action(router.Handle)
		mr.Map(m)
		err := http.ListenAndServe(addr, mr)
		if err != nil {
			warnln("GUI not possible:", err)
		}
	}()
}
開發者ID:ngpestelos,項目名稱:syncthing,代碼行數:28,代碼來源:gui.go

示例7: TestMartiniSelectiveRouter

func TestMartiniSelectiveRouter(t *testing.T) {
	for _, test := range tests {
		w := httptest.NewRecorder()
		r := martini.NewRouter()

		done := make(chan bool)
		selectRoute(r, test.ExpectedMethod, func(rq *http.Request) {
			done <- true
		})

		req, err := http.NewRequest(test.Method, "/", nil)
		if err != nil {
			t.Fatal(err)
		}
		OverrideRequestMethod(req, test.OverrideMethod)

		m := martini.New()
		m.Use(Override())
		m.Action(r.Handle)
		go m.ServeHTTP(w, req)
		select {
		case <-done:
		case <-time.After(30 * time.Millisecond):
			t.Errorf("Expected router to route to %s, got something else (%v).", test.ExpectedMethod, test)
		}
	}
}
開發者ID:Boomerangz,項目名稱:martini-contrib,代碼行數:27,代碼來源:override_test.go

示例8: 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:pilu,項目名稱:golang-mux-benchmark,代碼行數:27,代碼來源:mux_bench_test.go

示例9: BenchmarkCodegangstaMartini_Composite

func BenchmarkCodegangstaMartini_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:pilu,項目名稱:golang-mux-benchmark,代碼行數:35,代碼來源:mux_bench_test.go

示例10: routes

func routes() martini.Router {
	r := martini.NewRouter()
	r.Get("/", func() string {
		return "It works!"
	})
	r.Post("/capture", handleCapture)
	return r
}
開發者ID:nathanwdavis,項目名稱:eventcapture_comparison,代碼行數:8,代碼來源:eventcaptureserver.go

示例11: newMartini

func newMartini() *martini.ClassicMartini {
	r := martini.NewRouter()
	m := martini.New()
	m.Use(middleware.Logger())
	m.Use(martini.Recovery())
	m.Use(martini.Static("public"))
	m.MapTo(r, (*martini.Routes)(nil))
	m.Action(r.Handle)
	return &martini.ClassicMartini{m, r}
}
開發者ID:josephyzhou,項目名稱:gogs,代碼行數:10,代碼來源:web.go

示例12: init

func init() {
	m = martini.New()
	r := martini.NewRouter()
	r.Get("/v2/catalog", GetCatalog)
	r.Put("/v2/service_instances/:id", CreateService)
	r.Delete("/v2/service_instances/:id", DeleteService)
	r.Put("/v2/service_instances/:instance_id/service_bindings/:id", BindService)
	r.Delete("/v2/service_instances/:instance_id/service_bindings/:id", UnbindService)
	m.Action(r.Handle)
}
開發者ID:rleiwang,項目名稱:cf-go-broker,代碼行數:10,代碼來源:broker.go

示例13: AppServer

func AppServer() *Server {
	r := martini.NewRouter()
	m := martini.New()
	m.Use(martini.Logger())
	m.Use(martini.Recovery())
	m.Use(render.Renderer())
	m.Use(DB())

	m.Action(r.Handle)
	return &Server{m, r}
}
開發者ID:h12w,項目名稱:golang-rest-server,代碼行數:11,代碼來源:server.go

示例14: init

func init() {
	m = martini.New()
	// Setup routes
	r := martini.NewRouter()
	r.Post(`/images`, postImage)
	r.Get(`/torrents`, getTorrent)
	r.Get(`/images/all`, getImagesList)
	r.Get(`/images`, getImages)
	// Add the router action
	m.Action(r.Handle)
}
開發者ID:ruo91,項目名稱:docket,代碼行數:11,代碼來源:registry.go

示例15: newModern

func newModern() *Modern { // customized martini.Classic
	r := martini.NewRouter()
	m := martini.New()
	m.Use(martini.Recovery())
	m.Action(r.Handle)

	return &Modern{
		Martini: m,
		Router:  r,
	}
}
開發者ID:johntdyer,項目名稱:golang-devops-stuff,代碼行數:11,代碼來源:server.go


注:本文中的github.com/codegangsta/martini.NewRouter函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。