本文整理汇总了Golang中github.com/prometheus/common/route.Router类的典型用法代码示例。如果您正苦于以下问题:Golang Router类的具体用法?Golang Router怎么用?Golang Router使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Router类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Register
// Register the API's endpoints in the given router.
func (api *API) Register(r *route.Router) {
if api.context == nil {
api.context = route.Context
}
instr := func(name string, f apiFunc) http.HandlerFunc {
hf := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
setCORS(w)
if data, err := f(r); err != nil {
respondError(w, err, data)
} else {
respond(w, data)
}
})
return prometheus.InstrumentHandler(name, httputil.CompressionHandler{
Handler: hf,
})
}
r.Get("/query", instr("query", api.query))
r.Get("/query_range", instr("query_range", api.queryRange))
r.Get("/label/:name/values", instr("label_values", api.labelValues))
r.Get("/series", instr("series", api.series))
r.Del("/series", instr("drop_series", api.dropSeries))
}
开发者ID:nickolyamba,项目名称:prometheus,代码行数:28,代码来源:api.go
示例2: RegisterWeb
// RegisterWeb registers handlers to serve files for the web interface.
func RegisterWeb(r *route.Router) {
r.Get("/app/*filepath", func(w http.ResponseWriter, req *http.Request) {
fp := route.Param(route.Context(req), "filepath")
serveAsset(w, req, filepath.Join("ui/app", fp))
})
r.Get("/lib/*filepath", func(w http.ResponseWriter, req *http.Request) {
fp := route.Param(route.Context(req), "filepath")
serveAsset(w, req, filepath.Join("ui/lib", fp))
})
r.Get("/", func(w http.ResponseWriter, req *http.Request) {
serveAsset(w, req, "ui/app/index.html")
})
}
开发者ID:magicwang-cn,项目名称:alertmanager,代码行数:14,代码来源:web.go
示例3: RegisterWeb
// RegisterWeb registers handlers to serve files for the web interface.
func RegisterWeb(r *route.Router) {
ihf := prometheus.InstrumentHandlerFunc
r.Get("/app/*filepath", ihf("app_files",
func(w http.ResponseWriter, req *http.Request) {
fp := route.Param(route.Context(req), "filepath")
serveAsset(w, req, filepath.Join("ui/app", fp))
},
))
r.Get("/lib/*filepath", ihf("lib_files",
func(w http.ResponseWriter, req *http.Request) {
fp := route.Param(route.Context(req), "filepath")
serveAsset(w, req, filepath.Join("ui/lib", fp))
},
))
r.Get("/metrics", prometheus.Handler().ServeHTTP)
r.Get("/", ihf("index", func(w http.ResponseWriter, req *http.Request) {
serveAsset(w, req, "ui/app/index.html")
}))
}
开发者ID:MonsantoCo,项目名称:alertmanager,代码行数:23,代码来源:web.go
示例4: Register
// Register registers the handler for the various endpoints below /api.
func (api *API) Register(router *route.Router) {
router.Get("/query", handle("query", api.Query))
router.Get("/query_range", handle("query_range", api.QueryRange))
router.Get("/metrics", handle("metrics", api.Metrics))
}
开发者ID:hvnsweeting,项目名称:prometheus,代码行数:6,代码来源:api.go
示例5: RegisterWeb
// RegisterWeb registers handlers to serve files for the web interface.
func RegisterWeb(r *route.Router, reloadCh chan<- struct{}) {
ihf := prometheus.InstrumentHandlerFunc
r.Get("/app/*filepath", ihf("app_files",
func(w http.ResponseWriter, req *http.Request) {
fp := route.Param(route.Context(req), "filepath")
serveAsset(w, req, filepath.Join("ui/app", fp))
},
))
r.Get("/lib/*filepath", ihf("lib_files",
func(w http.ResponseWriter, req *http.Request) {
fp := route.Param(route.Context(req), "filepath")
serveAsset(w, req, filepath.Join("ui/lib", fp))
},
))
r.Get("/metrics", prometheus.Handler().ServeHTTP)
r.Get("/", ihf("index", func(w http.ResponseWriter, req *http.Request) {
serveAsset(w, req, "ui/app/index.html")
}))
r.Post("/-/reload", func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte("Reloading configuration file..."))
reloadCh <- struct{}{}
})
r.Get("/debug/*subpath", http.DefaultServeMux.ServeHTTP)
r.Post("/debug/*subpath", http.DefaultServeMux.ServeHTTP)
}
开发者ID:yacloud-io,项目名称:alertmanager,代码行数:31,代码来源:web.go
示例6: Register
// Register registers the API handlers under their correct routes
// in the given router.
func (api *API) Register(r *route.Router) {
ihf := func(name string, f http.HandlerFunc) http.HandlerFunc {
return prometheus.InstrumentHandlerFunc(name, func(w http.ResponseWriter, r *http.Request) {
setCORS(w)
f(w, r)
})
}
r.Options("/*path", ihf("options", func(w http.ResponseWriter, r *http.Request) {}))
// Register legacy forwarder for alert pushing.
r.Post("/alerts", ihf("legacy_add_alerts", api.legacyAddAlerts))
// Register actual API.
r = r.WithPrefix("/v1")
r.Get("/status", ihf("status", api.status))
r.Get("/alerts/groups", ihf("alert_groups", api.alertGroups))
r.Get("/alerts", ihf("list_alerts", api.listAlerts))
r.Post("/alerts", ihf("add_alerts", api.addAlerts))
r.Get("/silences", ihf("list_silences", api.listSilences))
r.Post("/silences", ihf("add_silence", api.addSilence))
r.Get("/silence/:sid", ihf("get_silence", api.getSilence))
r.Del("/silence/:sid", ihf("del_silence", api.delSilence))
}
开发者ID:farcaller,项目名称:alertmanager,代码行数:29,代码来源:api.go
示例7: Register
// Register registers the API handlers under their correct routes
// in the given router.
func (api *API) Register(r *route.Router) {
ihf := prometheus.InstrumentHandlerFunc
// Register legacy forwarder for alert pushing.
r.Post("/alerts", ihf("legacy_add_alerts", api.legacyAddAlerts))
// Register actual API.
r = r.WithPrefix("/v1")
r.Get("/status", ihf("status", api.status))
r.Get("/alerts/groups", ihf("alert_groups", api.alertGroups))
r.Get("/alerts", ihf("list_alerts", api.listAlerts))
r.Post("/alerts", ihf("add_alerts", api.addAlerts))
r.Get("/silences", ihf("list_silences", api.listSilences))
r.Post("/silences", ihf("add_silence", api.addSilence))
r.Get("/silence/:sid", ihf("get_silence", api.getSilence))
r.Del("/silence/:sid", ihf("del_silence", api.delSilence))
}
开发者ID:cherti,项目名称:alertmanager,代码行数:22,代码来源:api.go
示例8: Register
// Register regieters the API handlers under their correct routes
// in the given router.
func (api *API) Register(r *route.Router) {
// Register legacy forwarder for alert pushing.
r.Post("/alerts", api.legacyAddAlerts)
// Register actual API.
r = r.WithPrefix("/v1")
r.Get("/status", api.status)
r.Get("/alerts/groups", api.alertGroups)
r.Get("/alerts", api.listAlerts)
r.Post("/alerts", api.addAlerts)
r.Get("/silences", api.listSilences)
r.Post("/silences", api.addSilence)
r.Get("/silence/:sid", api.getSilence)
r.Del("/silence/:sid", api.delSilence)
}
开发者ID:magicwang-cn,项目名称:alertmanager,代码行数:21,代码来源:api.go
示例9: Register
// Register the API's endpoints in the given router.
func (api *API) Register(r *route.Router) {
instr := func(name string, f apiFunc) http.HandlerFunc {
hf := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
setCORS(w)
if data, err := f(r); err != nil {
respondError(w, err, data)
} else if data != nil {
respond(w, data)
} else {
w.WriteHeader(http.StatusNoContent)
}
})
return prometheus.InstrumentHandler(name, httputil.CompressionHandler{
Handler: hf,
})
}
r.Options("/*path", instr("options", api.options))
r.Get("/query", instr("query", api.query))
r.Get("/query_range", instr("query_range", api.queryRange))
r.Get("/label/:name/values", instr("label_values", api.labelValues))
r.Get("/series", instr("series", api.series))
r.Del("/series", instr("drop_series", api.dropSeries))
r.Get("/targets", instr("targets", api.targets))
}
开发者ID:prometheus,项目名称:prometheus,代码行数:30,代码来源:api.go
示例10: Register
// Register registers the handler for the various endpoints below /api.
func (api *API) Register(router *route.Router) {
// List all the endpoints here instead of using a wildcard route because we
// would otherwise handle /api/v1 as well.
router.Options("/query", handle("options", api.Options))
router.Options("/query_range", handle("options", api.Options))
router.Options("/metrics", handle("options", api.Options))
router.Get("/query", handle("query", api.Query))
router.Get("/query_range", handle("query_range", api.QueryRange))
router.Get("/metrics", handle("metrics", api.Metrics))
}
开发者ID:brutus333,项目名称:prometheus,代码行数:12,代码来源:api.go
注:本文中的github.com/prometheus/common/route.Router类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论