本文整理匯總了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
}
示例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()
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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)
}
示例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)
}