本文整理汇总了Golang中github.com/gorilla/mux.Router.Methods方法的典型用法代码示例。如果您正苦于以下问题:Golang Router.Methods方法的具体用法?Golang Router.Methods怎么用?Golang Router.Methods使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/gorilla/mux.Router
的用法示例。
在下文中一共展示了Router.Methods方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: registerRoutes
// registerRoutes registers HTTP route handlers
func (d *daemon) registerRoutes(router *mux.Router) {
// Add REST routes
s := router.Headers("Content-Type", "application/json").Methods("Post").Subrouter()
s.HandleFunc("/plugin/allocAddress", makeHTTPHandler(master.AllocAddressHandler))
s.HandleFunc("/plugin/releaseAddress", makeHTTPHandler(master.ReleaseAddressHandler))
s.HandleFunc("/plugin/createEndpoint", makeHTTPHandler(master.CreateEndpointHandler))
s.HandleFunc("/plugin/deleteEndpoint", makeHTTPHandler(master.DeleteEndpointHandler))
s.HandleFunc("/plugin/svcProviderUpdate", makeHTTPHandler(master.ServiceProviderUpdateHandler))
s = router.Methods("Get").Subrouter()
s.HandleFunc(fmt.Sprintf("/%s/%s", master.GetEndpointRESTEndpoint, "{id}"),
get(false, d.endpoints))
s.HandleFunc(fmt.Sprintf("/%s", master.GetEndpointsRESTEndpoint),
get(true, d.endpoints))
s.HandleFunc(fmt.Sprintf("/%s/%s", master.GetNetworkRESTEndpoint, "{id}"),
get(false, d.networks))
s.HandleFunc(fmt.Sprintf("/%s", master.GetNetworksRESTEndpoint),
get(true, d.networks))
s.HandleFunc(fmt.Sprintf("/%s", master.GetVersionRESTEndpoint), getVersion)
s.HandleFunc(fmt.Sprintf("/%s/%s", master.GetServiceRESTEndpoint, "{id}"),
get(false, d.services))
s.HandleFunc(fmt.Sprintf("/%s", master.GetServicesRESTEndpoint),
get(true, d.services))
}
示例2: AddRoutes
// AddRoutes adds routes to a router instance. If there are middlewares defined
// for a route, a new negroni app is created and wrapped as a http.Handler
func AddRoutes(routes []Route, router *mux.Router) {
var (
handler http.Handler
n *negroni.Negroni
)
for _, route := range routes {
// Add any specified middlewares
if len(route.Middlewares) > 0 {
n = negroni.New()
for _, middleware := range route.Middlewares {
n.Use(middleware)
}
// Wrap the handler in the negroni app with middlewares
n.Use(negroni.Wrap(route.HandlerFunc))
handler = n
} else {
handler = route.HandlerFunc
}
router.Methods(route.Method).
Path(route.Pattern).
Name(route.Name).
Handler(handler)
}
}
示例3: RegisterControlRoutes
// RegisterControlRoutes registers the various control routes with a http mux.
func RegisterControlRoutes(router *mux.Router) {
controlRouter := &controlRouter{
probes: map[string]controlHandler{},
}
router.Methods("GET").Path("/api/control/ws").HandlerFunc(controlRouter.handleProbeWS)
router.Methods("POST").MatcherFunc(URLMatcher("/api/control/{probeID}/{nodeID}/{control}")).HandlerFunc(controlRouter.handleControl)
}
示例4: registerRoutes
// registerRoutes registers HTTP route handlers
func (d *daemon) registerRoutes(router *mux.Router) {
// register web ui handlers
d.registerWebuiHandler(router)
// Add REST routes
s := router.Headers("Content-Type", "application/json").Methods("Post").Subrouter()
s.HandleFunc("/plugin/allocAddress", makeHTTPHandler(master.AllocAddressHandler))
s.HandleFunc("/plugin/releaseAddress", makeHTTPHandler(master.ReleaseAddressHandler))
s.HandleFunc("/plugin/createEndpoint", makeHTTPHandler(master.CreateEndpointHandler))
s.HandleFunc("/plugin/deleteEndpoint", makeHTTPHandler(master.DeleteEndpointHandler))
s = router.Methods("Get").Subrouter()
s.HandleFunc(fmt.Sprintf("/%s/%s", master.GetEndpointRESTEndpoint, "{id}"),
get(false, d.endpoints))
s.HandleFunc(fmt.Sprintf("/%s", master.GetEndpointsRESTEndpoint),
get(true, d.endpoints))
s.HandleFunc(fmt.Sprintf("/%s/%s", master.GetNetworkRESTEndpoint, "{id}"),
get(false, d.networks))
s.HandleFunc(fmt.Sprintf("/%s", master.GetNetworksRESTEndpoint),
get(true, d.networks))
s.HandleFunc(fmt.Sprintf("/%s", master.GetVersionRESTEndpoint), getVersion)
// See if we need to create the default tenant
go objApi.CreateDefaultTenant()
}
示例5: Register
//Register - registers an API Call with the router
func (call *APICall) Register(router *mux.Router) {
log.Println("Call: ", call)
router.Methods(call.Methods...).
Name(call.Name).
Path(call.Path).
HandlerFunc(call.HandlerFunc)
}
示例6: RegisterRoutes
// RegisterRoutes operates over `Routes` and registers all of them
func RegisterRoutes(router *mux.Router) *mux.Router {
for _, route := range routes {
router.Methods(route.Method).Path(route.Pattern).Name(route.Name).Handler(route.HandlerFunc)
}
router.PathPrefix("/").Handler(http.FileServer(assetFS()))
return router
}
示例7: RegisterReportPostHandler
// RegisterReportPostHandler registers the handler for report submission
func RegisterReportPostHandler(a Adder, router *mux.Router) {
post := router.Methods("POST").Subrouter()
post.HandleFunc("/api/report", func(w http.ResponseWriter, r *http.Request) {
var (
rpt report.Report
reader = r.Body
err error
)
if strings.Contains(r.Header.Get("Content-Encoding"), "gzip") {
reader, err = gzip.NewReader(r.Body)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
}
decoder := gob.NewDecoder(reader).Decode
if strings.HasPrefix(r.Header.Get("Content-Type"), "application/json") {
decoder = json.NewDecoder(reader).Decode
}
if err := decoder(&rpt); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
a.Add(rpt)
if len(rpt.Pod.Nodes) > 0 {
topologyRegistry.enableKubernetesTopologies()
}
w.WriteHeader(http.StatusOK)
})
}
示例8: setupHandlers
func setupHandlers(router *mux.Router) {
GET := router.Methods("GET", "HEAD").Subrouter()
POST := router.Methods("POST").Subrouter()
GET.HandleFunc("/", httpIndex)
GET.HandleFunc("/m/{id}", httpMeetup)
POST.HandleFunc("/new", apiNew)
}
示例9: SetRoutes
func (a *App) SetRoutes(router *mux.Router) error {
// Load App specific routes
a.LoadRoutes()
// Create a router for defining the routes which require authenticationAuth_fix
//For routes require auth, will be checked by a middleware which
//return error immediately
authReqdRouter := mux.NewRouter().StrictSlash(true)
//create a negroni with LoginReqd middleware
n := negroni.New(negroni.HandlerFunc(a.LoginRequired), negroni.Wrap(authReqdRouter))
// Set routes for core which doesnot require authentication
for _, route := range CORE_ROUTES_NOAUTH {
if validApiVersion(route.Version) {
urlPattern := fmt.Sprintf("%s/v%d/%s", DEFAULT_API_PREFIX, route.Version, route.Pattern)
router.Methods(route.Method).Path(urlPattern).Name(route.Name).Handler(http.HandlerFunc(route.HandlerFunc))
} else {
logger.Get().Info("Skipped the route: %s as version: %d is un spported", route.Name, route.Version)
}
}
// Set routes for core which require authentication
for _, route := range CORE_ROUTES {
if validApiVersion(route.Version) {
urlPattern := fmt.Sprintf("%s/v%d/%s", DEFAULT_API_PREFIX, route.Version, route.Pattern)
authReqdRouter.Methods(route.Method).Path(urlPattern).Name(route.Name).Handler(http.HandlerFunc(route.HandlerFunc))
router.Handle(urlPattern, n)
} else {
logger.Get().Info("Skipped the route: %s as version: %d is un spported", route.Name, route.Version)
}
}
//Set the provider specific routes here
//All the provider specific routes are assumed to be authenticated
for _, route := range a.routes {
logger.Get().Debug("%s", route)
if validApiVersion(route.Version) {
urlPattern := fmt.Sprintf("%s/v%d/%s", DEFAULT_API_PREFIX, route.Version, route.Pattern)
authReqdRouter.
Methods(route.Method).
Path(urlPattern).
Name(route.Name).
Handler(http.HandlerFunc(a.ProviderHandler))
router.Handle(urlPattern, n)
} else {
logger.Get().Info("Skipped the route: %s as version: %d is un spported", route.Name, route.Version)
}
}
return nil
}
示例10: registerRoutes
// registerRoutes registers HTTP route handlers
func (d *MasterDaemon) registerRoutes(router *mux.Router) {
// Add REST routes
s := router.Headers("Content-Type", "application/json").Methods("Post").Subrouter()
s.HandleFunc("/plugin/allocAddress", makeHTTPHandler(master.AllocAddressHandler))
s.HandleFunc("/plugin/releaseAddress", makeHTTPHandler(master.ReleaseAddressHandler))
s.HandleFunc("/plugin/createEndpoint", makeHTTPHandler(master.CreateEndpointHandler))
s.HandleFunc("/plugin/deleteEndpoint", makeHTTPHandler(master.DeleteEndpointHandler))
s.HandleFunc("/plugin/updateEndpoint", makeHTTPHandler(master.UpdateEndpointHandler))
s = router.Methods("Get").Subrouter()
// return netmaster version
s.HandleFunc(fmt.Sprintf("/%s", master.GetVersionRESTEndpoint), getVersion)
// Print info about the cluster
s.HandleFunc(fmt.Sprintf("/%s", master.GetInfoRESTEndpoint), func(w http.ResponseWriter, r *http.Request) {
info, err := d.getMasterInfo()
if err != nil {
log.Errorf("Error getting master state. Err: %v", err)
http.Error(w, "Error getting master state", http.StatusInternalServerError)
return
}
// convert to json
resp, err := json.Marshal(info)
if err != nil {
http.Error(w,
core.Errorf("marshalling json failed. Error: %s", err).Error(),
http.StatusInternalServerError)
return
}
w.Write(resp)
})
// services REST endpoints
// FIXME: we need to remove once service inspect is added
s.HandleFunc(fmt.Sprintf("/%s/%s", master.GetServiceRESTEndpoint, "{id}"),
get(false, d.services))
s.HandleFunc(fmt.Sprintf("/%s", master.GetServicesRESTEndpoint),
get(true, d.services))
// Debug REST endpoint for inspecting ofnet state
s.HandleFunc("/debug/ofnet", func(w http.ResponseWriter, r *http.Request) {
ofnetMasterState, err := d.ofnetMaster.InspectState()
if err != nil {
log.Errorf("Error fetching ofnet state. Err: %v", err)
http.Error(w, "Error fetching ofnet state", http.StatusInternalServerError)
return
}
w.Write(ofnetMasterState)
})
}
示例11: InstallHandlers
// install handlers into the provided router
func (self *CentralBooking) InstallHandlers(router *mux.Router) {
router.
Methods("POST").
Path("/register/instance").
HandlerFunc(self.RegisterInstance)
// apeing vault
router.
Methods("GET").
Path("/sys/health").
HandlerFunc(self.CheckHealth)
}
示例12: defineEtcdDiscoveryRoutes
func (mgr *pxeManagerT) defineEtcdDiscoveryRoutes(etcdRouter *mux.Router) {
etcdRouter.PathPrefix("/new").Methods("PUT").HandlerFunc(mgr.etcdDiscoveryNewCluster)
tokenRouter := etcdRouter.PathPrefix("/{token:[a-f0-9]{32}}").Subrouter()
tokenRouter.PathPrefix("/_config/size").Methods("GET").HandlerFunc(mgr.etcdDiscoveryProxyHandler)
tokenRouter.PathPrefix("/_config/size").Methods("PUT").HandlerFunc(mgr.etcdDiscoveryProxyHandler)
tokenRouter.PathPrefix("/{machine}").Methods("PUT").HandlerFunc(mgr.etcdDiscoveryProxyHandler)
tokenRouter.PathPrefix("/{machine}").Methods("GET").HandlerFunc(mgr.etcdDiscoveryProxyHandler)
tokenRouter.PathPrefix("/{machine}").Methods("DELETE").HandlerFunc(mgr.etcdDiscoveryProxyHandler)
tokenRouter.Methods("GET").HandlerFunc(mgr.etcdDiscoveryProxyHandler)
etcdRouter.Methods("GET").HandlerFunc(mgr.etcdDiscoveryHandler)
}
示例13: Routes
func Routes(r *mux.Router) {
ps := r.Path("/paintings").Subrouter()
ps.Methods("GET").Handler(listPaintings)
ps.Methods("POST").Handler(createPainting)
r.Methods("GET").Path("/paintings/categories").Handler(listCategories)
r.Methods("GET").Path("/paintings/media").Handler(listMedia)
p := r.Path("/paintings/{ID:[0-9]+}").Subrouter()
p.Methods("GET").Handler(showPainting)
p.Methods("PUT").Handler(editPainting)
r.Methods("POST").Path("/paintings/{ID:[0-9]+}/rotate").Handler(rotatePainting)
}
示例14: IntegrateRoutes
func IntegrateRoutes(router *mux.Router) {
router.
Methods("POST").
Path(ipnUrl).
Name("ipn notification").
HandlerFunc(processIPN)
router.
Methods("POST").
Path(ipnRespondTaskUrl).
Name("ipn notification responder task").
HandlerFunc(ipnDoResponseTaskHandler)
}
示例15: Register
// Register maps all routes to the appropriate handler
func Register(router *mux.Router, t *template.Template) {
home := controllers.NewHome(t)
router.HandleFunc("/", home.Index)
router.HandleFunc("/about", home.About)
router.NotFoundHandler = http.HandlerFunc(home.NotFound)
account := controllers.NewAccount(t)
router.HandleFunc("/login", account.Login)
router.Methods("POST").Path("/signin").HandlerFunc(account.Signin)
admin := controllers.NewAdmin(t)
router.Handle("/admin", AuthHandler(admin.Index))
static := http.StripPrefix("/static/", http.FileServer(http.Dir("./static/")))
router.PathPrefix("/static/").Handler(static)
}