本文整理汇总了Golang中github.com/gorilla/pat.Router类的典型用法代码示例。如果您正苦于以下问题:Golang Router类的具体用法?Golang Router怎么用?Golang Router使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Router类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ptyExec
func ptyExec(test *testing.T, mux *pat.Router) {
mux.Post("/exec", func(res http.ResponseWriter, req *http.Request) {
test.Log("got exec")
conn, rw, err := res.(http.Hijacker).Hijack()
if err != nil {
res.WriteHeader(http.StatusInternalServerError)
res.Write([]byte(err.Error()))
return
}
defer conn.Close()
script := req.FormValue("cmd")
if script == "" {
test.Log("missing script")
test.FailNow()
}
test.Log("executing", script)
cmd := exec.Command("/bin/bash", "-c", script)
file, err := pty.Start(cmd)
if err != nil {
test.Log(err)
test.FailNow()
}
test.Log("copying from pty")
go io.Copy(file, rw)
io.Copy(conn, file)
test.Log("finished running")
})
}
开发者ID:sfermigier,项目名称:nanobox,代码行数:28,代码来源:exec_test.go
示例2: normalExec
func normalExec(test *testing.T, mux *pat.Router) {
mux.Post("/exec", func(res http.ResponseWriter, req *http.Request) {
test.Log("got exec")
conn, rw, err := res.(http.Hijacker).Hijack()
if err != nil {
res.WriteHeader(http.StatusInternalServerError)
res.Write([]byte(err.Error()))
return
}
defer conn.Close()
script := req.FormValue("cmd")
if script == "" {
test.Log("missing script")
test.FailNow()
}
test.Log("executing", script)
cmd := exec.Command("/bin/bash", "-c", script)
cmd.Stdin = rw
cmd.Stderr = conn
// cmd.Stdout = conn
// cmd.Run()
reader, err := cmd.StdoutPipe()
cmd.Start()
io.Copy(conn, reader)
conn.(*net.TCPConn).CloseWrite()
err = cmd.Wait()
test.Log("finished running")
})
}
开发者ID:sfermigier,项目名称:nanobox,代码行数:29,代码来源:exec_test.go
示例3: Register
// Register creates routes for each static resource
func Register(config Config, r *pat.Router) {
//log.Debug("registering not found handler for static package", nil)
//r.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
// render.HTML(w, http.StatusNotFound, "error", render.DefaultVars(req, map[string]interface{}{"error": "Page not found"}))
//})
log.Printf("registering static content handlers for static package\n")
for _, file := range config.AssetNames()() {
if strings.HasPrefix(file, "static/") {
path := strings.TrimPrefix(file, "static")
log.Printf("registering handler for static asset %s\n", path)
b, err := config.Asset()("static" + path)
if err != nil {
panic(err)
}
mimeType := http.DetectContentType(b)
log.Printf("using mime type %s\n", mimeType)
r.Path(path).Methods("GET").HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", mimeType)
w.Header().Set("Cache-control", "public, max-age=259200")
w.WriteHeader(200)
w.Write(b)
})
}
}
}
开发者ID:zxchris,项目名称:discourse-sso-go,代码行数:31,代码来源:static.go
示例4: userAddRoutes
func userAddRoutes(router *pat.Router) {
router.Post("/user/waiver", serve(
Authenticate(true),
acceptWaiver,
toJson,
))
}
开发者ID:pjherring,项目名称:ggc,代码行数:7,代码来源:user.go
示例5: addTwilioRoutes
func addTwilioRoutes(router *pat.Router) {
router.Get("/twilio/call", serve(
parseFromUrl(urlParams{"From": parseParamToString}),
handleTwilio,
toXml,
))
}
开发者ID:pjherring,项目名称:ggc,代码行数:7,代码来源:twilio.go
示例6: CreateWeb
func CreateWeb(cfg *config.Config, pat *pat.Router, asset func(string) ([]byte, error)) *Web {
web := &Web{
config: cfg,
asset: asset,
}
pat.Path("/images/{file:.*}").Methods("GET").HandlerFunc(web.Static("assets/images/{{file}}"))
pat.Path("/css/{file:.*}").Methods("GET").HandlerFunc(web.Static("assets/css/{{file}}"))
pat.Path("/js/{file:.*}").Methods("GET").HandlerFunc(web.Static("assets/js/{{file}}"))
pat.Path("/fonts/{file:.*}").Methods("GET").HandlerFunc(web.Static("assets/fonts/{{file}}"))
pat.Path("/").Methods("GET").HandlerFunc(web.Index())
return web
}
开发者ID:jjz,项目名称:MailHog-UI,代码行数:14,代码来源:web.go
示例7: addDashboardRoutes
func addDashboardRoutes(router *pat.Router) {
router.Get("/dashboard/progress", serve(
dashboardAuth,
getDashboardProgress,
toJson,
))
router.Get("/dashboard/clues", serve(
dashboardAuth,
getDashboardClues,
toJson,
))
router.Put("/dashboard/start_times", serve(
parseRequest(new(setStartTimesReq)),
dashboardAuth,
setStartTimes,
noResponse,
))
router.Put("/dashboard", serve(
parseRequest(new(_DashboardAuthReq)),
dashboardAuth,
))
}
开发者ID:pjherring,项目名称:ggc,代码行数:26,代码来源:dashboard.go
示例8: teamAddRoutes
func teamAddRoutes(router *pat.Router) {
router.Post("/team/{team_id}/finish", serve(
dashboardAuth,
parseFromUrl(urlParams{
"team_id": parseParamToInt64,
}),
setTeamFinish,
toJson,
))
router.Delete("/team/{team_id}/finish", serve(
dashboardAuth,
parseFromUrl(urlParams{
"team_id": parseParamToInt64,
}),
setTeamFinish,
toJson,
))
router.Post("/team/{phrase}", serve(
parseFromUrl(urlParams{
"phrase": parseParamToString,
}),
parseRequest(new(_TeamJoinReq)),
validateJoinTeam,
joinTeam,
SetUserId,
toJson,
))
router.Post("/team", serve(
parseRequest(new(_TeamCreateReq)),
createTeam,
SetUserId,
toJson,
))
}
开发者ID:pjherring,项目名称:ggc,代码行数:34,代码来源:team.go
示例9: addClueRoutes
func addClueRoutes(router *pat.Router) {
router.Get("/clue/{clue_id}/hint", serve(
Authenticate(true),
parseFromUrl(urlParams{
"clue_id": parseParamToInt64,
"lat": parseParamToFloat64,
"lng": parseParamToFloat64,
}),
takeHint,
toJson,
))
router.Get("/clue", serve(
Authenticate(true),
parseFromUrl(urlParams{"clue_id": parseParamToInt64}),
currentClue,
toJson,
))
router.Post("/clue/{clue_id}", serve(
Authenticate(true),
parseFromUrl(urlParams{
"clue_id": parseParamToInt64,
}),
parseRequest(new(_SolveClueReq)),
solveClue,
toJson,
))
router.Put("/clue/{clue_id}", serve(
dashboardAuth,
parseRequest(new(record.Clue)),
updateClue,
toJson,
))
}
开发者ID:pjherring,项目名称:ggc,代码行数:33,代码来源:clue.go
示例10: addTrackRoutes
func addTrackRoutes(router *pat.Router) {
router.Get("/tracks", serve(
dashboardAuth,
allTracks,
toJson,
))
router.Put("/track/{track_id}/toggle", serve(
dashboardAuth,
parseFromUrl(urlParams{
"track_id": parseParamToInt64,
}),
toggleTrackActivation,
noResponse,
))
}
开发者ID:pjherring,项目名称:ggc,代码行数:16,代码来源:track.go
示例11: CreateWeb
func CreateWeb(cfg *config.Config, pat *pat.Router, asset func(string) ([]byte, error)) *Web {
web := &Web{
config: cfg,
asset: asset,
}
WebPath = cfg.WebPath
log.Printf("Serving under http://%s%s/", cfg.UIBindAddr, WebPath)
pat.Path(WebPath + "/images/{file:.*}").Methods("GET").HandlerFunc(web.Static("assets/images/{{file}}"))
pat.Path(WebPath + "/css/{file:.*}").Methods("GET").HandlerFunc(web.Static("assets/css/{{file}}"))
pat.Path(WebPath + "/js/{file:.*}").Methods("GET").HandlerFunc(web.Static("assets/js/{{file}}"))
pat.Path(WebPath + "/fonts/{file:.*}").Methods("GET").HandlerFunc(web.Static("assets/fonts/{{file}}"))
pat.StrictSlash(true).Path(WebPath + "/").Methods("GET").HandlerFunc(web.Index())
return web
}
开发者ID:GREsau,项目名称:MailHog-UI,代码行数:18,代码来源:web.go
示例12: Register
// Register creates routes for each static resource
func Register(config render.Config, r *pat.Router) {
log.Debug("registering not found handler for static package", nil)
r.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
render.HTML(w, http.StatusNotFound, "error", render.DefaultVars(req, map[string]interface{}{"error": "Page not found"}))
})
log.Debug("registering static content handlers for static package", nil)
for _, file := range config.AssetNames()() {
if strings.HasPrefix(file, "static/") {
path := strings.TrimPrefix(file, "static")
log.Trace("registering handler for static asset", log.Data{"path": path})
var mimeType string
switch {
case strings.HasSuffix(path, ".css"):
mimeType = "text/css"
case strings.HasSuffix(path, ".js"):
mimeType = "application/javascript"
default:
mimeType = mime.TypeByExtension(path)
}
log.Trace("using mime type", log.Data{"type": mimeType})
r.Path(path).Methods("GET").HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
if b, err := config.Asset()("static" + path); err == nil {
w.Header().Set("Content-Type", mimeType)
w.Header().Set("Cache-control", "public, max-age=259200")
w.WriteHeader(200)
w.Write(b)
return
}
// This should never happen!
log.ErrorR(req, errors.New("it happened ¯\\_(ツ)_/¯"), nil)
r.NotFoundHandler.ServeHTTP(w, req)
})
}
}
}
开发者ID:ian-kent,项目名称:service.go,代码行数:40,代码来源:static.go
示例13: HomeHandler
func HomeHandler(router *pat.Router, w http.ResponseWriter, req *http.Request) {
url, _ := router.GetRoute("service").URL("service_name", "trolling-and-molling")
fmt.Fprintf(w, "Home handler! %s", url)
}
开发者ID:JakubOboza,项目名称:go_http_examples,代码行数:4,代码来源:main.go
示例14: CreateAPIv2
func CreateAPIv2(conf *config.Config, r *pat.Router) *APIv2 {
log.Println("Creating API v2")
apiv2 := &APIv2{
config: conf,
}
r.Path("/api/v2/messages").Methods("GET").HandlerFunc(apiv2.messages)
r.Path("/api/v2/messages").Methods("OPTIONS").HandlerFunc(apiv2.defaultOptions)
r.Path("/api/v2/search").Methods("GET").HandlerFunc(apiv2.search)
r.Path("/api/v2/search").Methods("OPTIONS").HandlerFunc(apiv2.defaultOptions)
r.Path("/api/v2/jim").Methods("GET").HandlerFunc(apiv2.jim)
r.Path("/api/v2/jim").Methods("POST").HandlerFunc(apiv2.createJim)
r.Path("/api/v2/jim").Methods("PUT").HandlerFunc(apiv2.updateJim)
r.Path("/api/v2/jim").Methods("DELETE").HandlerFunc(apiv2.deleteJim)
r.Path("/api/v2/jim").Methods("OPTIONS").HandlerFunc(apiv2.defaultOptions)
r.Path("/api/v2/outgoing-smtp").Methods("GET").HandlerFunc(apiv2.listOutgoingSMTP)
r.Path("/api/v2/outgoing-smtp").Methods("OPTIONS").HandlerFunc(apiv2.defaultOptions)
return apiv2
}
开发者ID:jackc,项目名称:MailHog-Server,代码行数:23,代码来源:v2.go
示例15: Register
// Register registers a healthcheck route with the router
func Register(r *pat.Router, path string, healthy func() bool) {
r.Path(path).Methods("GET").HandlerFunc(Handler(healthy))
}
开发者ID:ian-kent,项目名称:service.go,代码行数:4,代码来源:healthcheck.go
示例16: ServicesHandler
func ServicesHandler(router *pat.Router, w http.ResponseWriter, req *http.Request) {
url, _ := router.GetRoute("services").URL()
fmt.Fprintf(w, "Services List Page! Go -> %s", url)
}
开发者ID:JakubOboza,项目名称:go_http_examples,代码行数:4,代码来源:main.go
示例17: normalPing
func normalPing(mux *pat.Router) {
mux.Get("/ping", func(res http.ResponseWriter, req *http.Request) {
res.Write([]byte("pong"))
})
}
开发者ID:sfermigier,项目名称:nanobox,代码行数:5,代码来源:exec_test.go
示例18: CreateAPIv1
func CreateAPIv1(conf *config.Config, r *pat.Router) *APIv1 {
log.Println("Creating API v1")
apiv1 := &APIv1{
config: conf,
}
stream = goose.NewEventStream()
r.Path("/api/v1/messages").Methods("GET").HandlerFunc(apiv1.messages)
r.Path("/api/v1/messages").Methods("DELETE").HandlerFunc(apiv1.delete_all)
r.Path("/api/v1/messages").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions)
r.Path("/api/v1/messages/{id}").Methods("GET").HandlerFunc(apiv1.message)
r.Path("/api/v1/messages/{id}").Methods("DELETE").HandlerFunc(apiv1.delete_one)
r.Path("/api/v1/messages/{id}").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions)
r.Path("/api/v1/messages/{id}/download").Methods("GET").HandlerFunc(apiv1.download)
r.Path("/api/v1/messages/{id}/download").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions)
r.Path("/api/v1/messages/{id}/mime/part/{part}/download").Methods("GET").HandlerFunc(apiv1.download_part)
r.Path("/api/v1/messages/{id}/mime/part/{part}/download").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions)
r.Path("/api/v1/messages/{id}/release").Methods("POST").HandlerFunc(apiv1.release_one)
r.Path("/api/v1/messages/{id}/release").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions)
r.Path("/api/v1/events").Methods("GET").HandlerFunc(apiv1.eventstream)
r.Path("/api/v1/events").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions)
go func() {
for {
select {
case msg := <-apiv1.config.MessageChan:
log.Println("Got message in APIv1 event stream")
bytes, _ := json.MarshalIndent(msg, "", " ")
json := string(bytes)
log.Printf("Sending content: %s\n", json)
apiv1.broadcast(json)
}
}
}()
return apiv1
}
开发者ID:danielwhite,项目名称:MailHog-Server,代码行数:43,代码来源:v1.go
示例19: addProgressRoutes
func addProgressRoutes(router *pat.Router) {
router.Get("/progress", getProgress)
}
开发者ID:pjherring,项目名称:ggc,代码行数:3,代码来源:progress.go
注:本文中的github.com/gorilla/pat.Router类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论