当前位置: 首页>>代码示例>>Golang>>正文


Golang Router.GET方法代码示例

本文整理汇总了Golang中github.com/julienschmidt/httprouter.Router.GET方法的典型用法代码示例。如果您正苦于以下问题:Golang Router.GET方法的具体用法?Golang Router.GET怎么用?Golang Router.GET使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/julienschmidt/httprouter.Router的用法示例。


在下文中一共展示了Router.GET方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Register

func (c *streamController) Register(router *httprouter.Router) {
	router.PUT("/streams", basicAuth(c.handle(c.addToStream), c.authConfig))
	router.POST("/streams/coalesce", basicAuth(c.handle(c.coalesceStreams), c.authConfig))
	router.GET("/stream/:id", basicAuth(c.handle(c.getStream), c.authConfig))

	log.Debug("Routes Registered")
}
开发者ID:rtyer,项目名称:streams,代码行数:7,代码来源:stream_controller.go

示例2: myRouterConfig

func myRouterConfig(router *httprouter.Router) {
	router.GET("/pepe", func(w http.ResponseWriter, req *http.Request, p httprouter.Params) {
		fmt.Fprintln(w, "pepe")
	})

	router.GET("/", homeHandler)

}
开发者ID:nicolasgaraza,项目名称:EnrollmentGO-Beta,代码行数:8,代码来源:router.go

示例3: SetRoutes

//SetRoutes sets the controllers routes in given router
func (c *Controller) SetRoutes(router *httprouter.Router) {
	router.GET("/games", c.ListGames)
	router.POST("/games", c.NewGame)
	router.GET("/games/:id", c.PrintGameState)
	router.POST("/games/:id/move", c.ApplyMove)
	router.POST("/games/:id/init", c.InitGame)
	router.POST("/games/:id/start", c.StartGame)
}
开发者ID:tehleach,项目名称:hue,代码行数:9,代码来源:controller.go

示例4: Register

func (c *streamController) Register(router *httprouter.Router) {
	router.PUT("/streams", basicAuth(timeRequest(c.handle(c.addToStream), addToStreamTimer), c.authConfig))
	router.DELETE("/streams", basicAuth(timeRequest(c.handle(c.removeFromStream), removeFromStreamTimer), c.authConfig))
	router.POST("/streams/coalesce", basicAuth(timeRequest(c.handle(c.coalesceStreams), coalesceTimer), c.authConfig))
	router.GET("/stream/:id", basicAuth(timeRequest(c.handle(c.getStream), getStreamTimer), c.authConfig))

	log.Debug("Routes Registered")
}
开发者ID:ello,项目名称:streams,代码行数:8,代码来源:stream_controller.go

示例5: SetupRoutes

// SetupRoutes maps routes to the PubSub's handlers
func (ps *PubSub) SetupRoutes(router *httprouter.Router) *httprouter.Router {
	router.POST("/:topic_name", ps.PublishMessage)
	router.POST("/:topic_name/:subscriber_name", ps.Subscribe)
	router.DELETE("/:topic_name/:subscriber_name", ps.Unsubscribe)
	router.GET("/:topic_name/:subscriber_name", ps.GetMessages)

	return router
}
开发者ID:pengux,项目名称:pub-sub,代码行数:9,代码来源:pubsub.go

示例6: Register

func (d *Dump) Register(r *httprouter.Router) {
	r.GET("/dump", d.GetDumps)
	r.GET("/dump/:type", d.GetDumpsForType)
	r.GET("/dump/:type/:id", d.Get)
	r.DELETE("/dump/:type/:id", d.Delete)
	r.POST("/dump/:type", d.Create)
	r.GET("/dumpremote", d.GetAllRemoteDumps)
	r.GET("/dumpremote/:name", d.GetRemoteDumps)
}
开发者ID:janhalfar,项目名称:dumpster,代码行数:9,代码来源:dump.go

示例7: Register

func Register(router *httprouter.Router) {
	router.GET("/storage/files", func(w http.ResponseWriter, req *http.Request, params httprouter.Params) {
		encodedToken := req.Header.Get("X-Auth-Token")
		//		authMacaroon, err := macaroon.New(auth.Key, auth.ServiceID, auth.Location)
		//		if err != nil {
		//			log.Print(err)
		//			w.WriteHeader(500)
		//			w.Write([]byte("Oops, something went wrong..."))
		//			return
		//		}

		token, err := base64.URLEncoding.DecodeString(encodedToken)
		if err != nil {
			log.Print(err)
			w.WriteHeader(500)
			w.Write([]byte("Oops, something went wrong..."))
			return
		}

		userMacaroon := &macaroon.Macaroon{}
		if err := userMacaroon.UnmarshalBinary(token); err != nil {
			log.Print(err)
			w.WriteHeader(500)
			w.Write([]byte("Oops, something went wrong..."))
			return
		}

		log.Printf("#### Macaroon caveats: %+v\n", userMacaroon.Caveats())
		log.Printf("#### Macaroon signature: %+v\n", userMacaroon.Signature())
		log.Printf("#### Macaroon id: %+v\n", userMacaroon.Id())
		log.Printf("#### Macaroon location: %+v\n", userMacaroon.Location())

		if err := userMacaroon.Verify(auth.Key, noCaveatsChecker, nil); err != nil {
			log.Print(err)
			w.WriteHeader(401)
			w.Write([]byte(err.Error()))
			return
		}

		response := struct {
			Files []string `json:"files"`
		}{
			Files: []string{
				"http://localhost:6061/storage/files/1",
				"http://localhost:6061/storage/files/2",
				"http://localhost:6061/storage/files/3",
			},
		}

		if err := json.NewEncoder(w).Encode(response); err != nil {
			log.Print(err)
			w.WriteHeader(500)
			w.Write([]byte(err.Error()))
		}
	})
}
开发者ID:drborges,项目名称:macaroons-spike,代码行数:56,代码来源:api.go

示例8: addQueueHandlers

// addQueueHandlers add Queue handlers to router
func addQueueHandlers(router *httprouter.Router) {
	// get all message in queue
	router.GET("/queue", wrapHandler(queueGetMessages))
	// get a message by id
	router.GET("/queue/:id", wrapHandler(queueGetMessage))
	// discard a message
	router.DELETE("/queue/discard/:id", wrapHandler(queueDiscardMessage))
	// bounce a message
	router.DELETE("/queue/bounce/:id", wrapHandler(queueBounceMessage))
}
开发者ID:teefax,项目名称:tmail,代码行数:11,代码来源:handlers_queue.go

示例9: Register

func (e authEndpoint) Register(mux *httprouter.Router) {
	mux.GET("/register", jsonHandler(func() interface{} {
		return &defaultRegisterFlows
	}))
	mux.GET("/login", jsonHandler(func() interface{} {
		return &defaultLoginFlows
	}))
	mux.POST("/register", jsonHandler(e.postRegister))
	mux.POST("/login", jsonHandler(e.postLogin))
}
开发者ID:rezacute,项目名称:bullettime,代码行数:10,代码来源:auth.go

示例10: AddRoutes

func AddRoutes(router *httprouter.Router) {
	mylog.Debugf("enter rule.AddRoutes(%+v)", router)
	defer func() { mylog.Debugf("exit rule.AddRoutes(%+v)", router) }()

	controller := &controller{}
	router.GET("/rules", controller.GetAll)
	router.GET("/rules/:name", controller.Get)
	router.POST("/rules", controller.Post)
	router.DELETE("/rules/:name", controller.Del)
}
开发者ID:robertocs,项目名称:cepiot,代码行数:10,代码来源:rule_controller.go

示例11: configure

// configure registers the API's routes on a router. If the passed router is nil, we create a new one and return it.
// The nil mode is used when an API is run in stand-alone mode.
func (a *API) configure(router *httprouter.Router) *httprouter.Router {

	if router == nil {
		router = httprouter.New()
	}

	for i, route := range a.Routes {

		if err := route.parseInfo(route.Path); err != nil {
			logging.Error("Error parsing info for %s: %s", route.Path, err)
		}
		a.Routes[i] = route
		h := a.handler(route)

		pth := a.FullPath(route.Path)

		if route.Methods&GET == GET {
			logging.Info("Registering GET handler %v to path %s", h, pth)
			router.Handle("GET", pth, h)
		}
		if route.Methods&POST == POST {
			logging.Info("Registering POST handler %v to path %s", h, pth)
			router.Handle("POST", pth, h)

		}

	}

	chain := buildChain(a.SwaggerMiddleware...)
	if chain == nil {
		chain = buildChain(a.swaggerHandler())
	} else {
		chain.append(a.swaggerHandler())
	}

	// Server the API documentation swagger
	router.GET(a.FullPath("/swagger"), a.middlewareHandler(chain, nil, nil))

	chain = buildChain(a.TestMiddleware...)
	if chain == nil {
		chain = buildChain(a.testHandler())
	} else {
		chain.append(a.testHandler())
	}

	router.GET(path.Join("/test", a.root(), ":category"), a.middlewareHandler(chain, nil, nil))

	// Redirect /$api/$version/console => /console?url=/$api/$version/swagger
	uiPath := fmt.Sprintf("/console?url=%s", url.QueryEscape(a.FullPath("/swagger")))
	router.Handler("GET", a.FullPath("/console"), http.RedirectHandler(uiPath, 301))

	return router

}
开发者ID:sguzwf,项目名称:vertex,代码行数:56,代码来源:api.go

示例12: source

func source(r *htr.Router) error {
	r.GET("/source",
		func(w http.ResponseWriter, r *http.Request, ps htr.Params) {
			if _, err := io.WriteString(w, sourceDoc); err != nil {
				log.Printf("failed to write response: %s", err.Error())
			}
		},
	)

	return nil
}
开发者ID:patosullivan,项目名称:mf-proto,代码行数:11,代码来源:route.go

示例13: setupWebFrontend

// Setup all routes for Web-Frontend
func setupWebFrontend(router *httprouter.Router) {
	// Index
	router.GET("/", routes.ViewIndex)
	router.GET("/status/:url", routes.ViewIndex)
	router.GET("/results/:url", routes.ViewIndex)

	// Admin
	router.GET("/admin", routes.ViewAdmin)
	router.GET("/admin/login", routes.ViewLogin)

	// Static Files
	router.ServeFiles("/public/*filepath", http.Dir("public"))
}
开发者ID:MarvinMenzerath,项目名称:UpAndRunning2,代码行数:14,代码来源:main.go

示例14: addUsersHandlers

// addUsersHandlers add Users handler to router
func addUsersHandlers(router *httprouter.Router) {
	// add user
	router.POST("/users/:user", wrapHandler(usersAdd))

	// get all users
	router.GET("/users", wrapHandler(usersGetAll))

	// get one user
	router.GET("/users/:user", wrapHandler(usersGetOne))

	// del an user
	router.DELETE("/users/:user", wrapHandler(usersDel))
}
开发者ID:ro78,项目名称:tmail,代码行数:14,代码来源:handlers_users.go

示例15: AddAdminRoutes

//AddAdminRoutes Adds all the admin routes that need user login
func AddAdminRoutes(router *httprouter.Router, a *application.App) {
	router.GET("/"+adminPrefix, admin.GETDashboardIndex(a))
	router.GET("/"+adminPrefix+"/logout", admin.GETDashboardLogout(a))
	router.GET("/"+adminPrefix+"/users/new", admin.GETUsersNew(a))
	router.POST("/"+adminPrefix+"/users/new", admin.POSTUsersNew(a))
	router.GET("/"+adminPrefix+"/profile", admin.GETDashboardProfile(a))
	router.POST("/"+adminPrefix+"/profile", admin.POSTDashboardProfile(a))
}
开发者ID:skmetaly,项目名称:pbblog,代码行数:9,代码来源:routes.go


注:本文中的github.com/julienschmidt/httprouter.Router.GET方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。