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


Golang Router.Get方法代碼示例

本文整理匯總了Golang中github.com/gorilla/mux.Router.Get方法的典型用法代碼示例。如果您正苦於以下問題:Golang Router.Get方法的具體用法?Golang Router.Get怎麽用?Golang Router.Get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/gorilla/mux.Router的用法示例。


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

示例1: NewHandler

func NewHandler(s api.FluxService, r *mux.Router, logger log.Logger, h metrics.Histogram) http.Handler {
	for method, handlerFunc := range map[string]func(api.FluxService) http.Handler{
		"ListServices":   handleListServices,
		"ListImages":     handleListImages,
		"PostRelease":    handlePostRelease,
		"GetRelease":     handleGetRelease,
		"Automate":       handleAutomate,
		"Deautomate":     handleDeautomate,
		"Lock":           handleLock,
		"Unlock":         handleUnlock,
		"History":        handleHistory,
		"GetConfig":      handleGetConfig,
		"SetConfig":      handleSetConfig,
		"RegisterDaemon": handleRegister,
		"IsConnected":    handleIsConnected,
	} {
		var handler http.Handler
		handler = handlerFunc(s)
		handler = logging(handler, log.NewContext(logger).With("method", method))
		handler = observing(handler, h.With("method", method))

		r.Get(method).Handler(handler)
	}
	return r
}
開發者ID:weaveworks,項目名稱:flux,代碼行數:25,代碼來源:transport.go

示例2: getURL

func getURL(router *mux.Router, name string, pairs ...string) string {
	route := router.Get(name)
	if route == nil {
		glog.Fatalf("Couldn't find any route named %s", name)
	}

	routeURL, err := route.URL(pairs...)
	if err != nil {
		glog.Fatalf("Couldn't resolve route %s into a URL", routeURL)
	}

	return routeURL.String()
}
開發者ID:kleopatra999,項目名稱:skia-buildbot,代碼行數:13,代碼來源:main.go

示例3: AssignHandlersToUserRoutes

func AssignHandlersToUserRoutes(r *mux.Router, c *m.Context, db *sql.DB) *mux.Router {

	userStore := &datastores.UserStore{db}

	r.Get(router.ReadUser).Handler(m.AuthenticateToken(c, m.RefreshExpiringToken(ServeFindUser(userStore))))

	r.Get(router.CreateUser).Handler(m.ServeHTTP(m.ParseRequestBody(new(models.UnauthUser), ServeRegisterUser(userStore))))

	r.Get(router.Login).Handler(m.ServeHTTP(m.ParseRequestBody(new(models.UnauthUser), ServeLogin(userStore))))

	r.Get(router.Logout).Handler(m.AuthenticateToken(c, ServeLogout()))

	return r
}
開發者ID:jmheidly,項目名稱:Answer-Patch,代碼行數:14,代碼來源:handler.go

示例4: AssignHandlersToQuestionRoutes

func AssignHandlersToQuestionRoutes(r *mux.Router, c *m.Context, db *sql.DB) *mux.Router {

	questionStore := &datastores.QuestionStore{db}
	//	answerStore := &datastores.AnswerStore{db}

	r.Get(router.ReadPost).Handler(m.AuthenticateToken(c, m.RefreshExpiringToken(ServePostByID(questionStore))))

	r.Get(router.ReadQuestionsByFilter).Handler(m.AuthenticateToken(c, m.RefreshExpiringToken(ServeQuestionsByFilter(questionStore))))

	r.Get(router.ReadSortedQuestions).Handler(m.AuthenticateToken(c, m.RefreshExpiringToken(ServeSortedQuestions(questionStore))))

	r.Get(router.CreateQuestion).Handler(m.AuthenticateToken(c, m.RefreshExpiringToken(ServeSubmitQuestion(questionStore))))

	return r
}
開發者ID:jmheidly,項目名稱:Answer-Patch,代碼行數:15,代碼來源:handler.go

示例5: makeURL

func makeURL(endpoint string, router *mux.Router, routeName string, urlParams ...string) (*url.URL, error) {
	if len(urlParams)%2 != 0 {
		panic("urlParams must be even!")
	}

	endpointURL, err := url.Parse(endpoint)
	if err != nil {
		return nil, errors.Wrapf(err, "parsing endpoint %s", endpoint)
	}

	routeURL, err := router.Get(routeName).URL()
	if err != nil {
		return nil, errors.Wrapf(err, "retrieving route path %s", routeName)
	}

	v := url.Values{}
	for i := 0; i < len(urlParams); i += 2 {
		v.Add(urlParams[i], urlParams[i+1])
	}

	endpointURL.Path = path.Join(endpointURL.Path, routeURL.Path)
	endpointURL.RawQuery = v.Encode()
	return endpointURL, nil
}
開發者ID:weaveworks,項目名稱:flux,代碼行數:24,代碼來源:transport.go

示例6: ServicesHandler

func ServicesHandler(router *mux.Router, w http.ResponseWriter, req *http.Request) {
	url, _ := router.Get("services").URL()
	fmt.Fprintf(w, "Services List Page! Go -> %s", url)
}
開發者ID:JakubOboza,項目名稱:go_http_examples,代碼行數:4,代碼來源:server.go

示例7: HomeHandler

func HomeHandler(router *mux.Router, w http.ResponseWriter, req *http.Request) {
	url, _ := router.Get("service").URL("service_name", "trolling-and-molling")
	fmt.Fprintf(w, "Home handler! %s", url)
}
開發者ID:JakubOboza,項目名稱:go_http_examples,代碼行數:4,代碼來源:server.go

示例8: MountHandlers

func MountHandlers(r *mux.Router, ds *api.Services) {
	r.Get(routes.Rankings).HandlerFunc(ListRankingsHandler(ds))
	r.Get(routes.MatchesRun).HandlerFunc(RunMatchesHandler(ds))

	r.Get(routes.Players).HandlerFunc(ListPlayersHandler(ds))
	r.Get(routes.PlayersCreate).HandlerFunc(CreatePlayersHandler(ds))
	r.Get(routes.PlayersDelete).HandlerFunc(DeletePlayersHandler(ds))

	r.Get(routes.Users).HandlerFunc(ListUsersHandler(ds))
	r.Get(routes.UsersCreate).HandlerFunc(CreateUsersHandler(ds))
	r.Get(routes.UsersDelete).HandlerFunc(DeleteUsersHandler(ds))

	r.Get(routes.Games).HandlerFunc(ListDetailsGamesHandler(ds))

	r.Get(routes.GameStates).HandlerFunc(ListGameStatesHandler(ds))
	r.Get(routes.States).HandlerFunc(ListGameStatesHandler(ds)) // alias

	r.Get(routes.APIBaseRoute).Path("/{rest:.*}").HandlerFunc(http.NotFound)
}
開發者ID:mukta3396,項目名稱:abalone,代碼行數:19,代碼來源:handlers.go


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