本文整理匯總了Golang中github.com/gin-gonic/gin.Engine.GET方法的典型用法代碼示例。如果您正苦於以下問題:Golang Engine.GET方法的具體用法?Golang Engine.GET怎麽用?Golang Engine.GET使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gin-gonic/gin.Engine
的用法示例。
在下文中一共展示了Engine.GET方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: sanityCheck
func sanityCheck(r *gin.Engine) {
r.GET("/sanity-check.json", func(c *gin.Context) {
type tool struct {
Name string `json:"name"`
Description string `json:"description"`
Homepage string `json:"homepage"`
Installed bool `json:"installed"`
}
var sanity = *GetSanityCheck()
c.JSON(200, gin.H{
"tools": []tool{
tool{Name: "LaTeX", Description: "Compiles Tex", Homepage: "https://www.latex-project.org", Installed: sanity.latex},
tool{Name: "pdflatex", Description: "Converts .tex to .pdf", Homepage: "https://www.latex-project.org", Installed: sanity.pdflatex},
tool{Name: "convert", Description: "Converts .pdf to .png", Homepage: "http://www.imagemagick.org/script/index.php", Installed: sanity.convert},
},
})
})
r.GET("/sanity-check", func(c *gin.Context) {
var sanity = *GetSanityCheck()
c.HTML(200, "sanity-check.tmpl", gin.H{
"latex": sanity.latex,
"pdflatex": sanity.pdflatex,
"convert": sanity.convert,
})
})
}
示例2: NewUserResource
func NewUserResource(e *gin.Engine) {
u := UserResource{}
// Setup Routes
e.GET("/users", u.getAllUsers)
e.GET("/users/:id", u.getUserByID)
}
示例3: InitRooter
func InitRooter(e *gin.Engine) {
e.GET("/status", func(c *gin.Context) { c.String(http.StatusOK, "ok") })
e.GET("/searchUser", userService.ListEndpoint)
e.GET("/searchItem", itemService.ListEndpoint)
e.GET("/searchPost", postService.ListEndpoint)
e.GET("/user/:id", userService.GetWebEndpoint)
e.GET("/item/:id", itemService.GetWebEndpoint)
e.GET("/post/:id", postService.GetWebEndpoint)
e.Static("/static", "./static")
//
// json := e.Group("/json")
// {
// json.GET("user/detail/:id", auth(), userService.GetEndpoint)
// json.GET("user/list", auth(), userService.ListEndpoint)
// }
//
// web := e.Group("/web")
// {
// web.GET("user/detail/:id", auth(), userService.GetWebEndpoint)
// web.GET("user/list", auth(), userService.ListWebEndpoint)
// }
//
// // However, this one will match /user/john/ and also /user/john/send
// // If no other routers match /user/john, it will redirect to /user/join/
// e.GET("/user/:name/*action", func(c *gin.Context) {
// name := c.Param("name")
// action := c.Param("action")
// message := name + " is " + action
// c.String(http.StatusOK, message)
// })
}
示例4: AddRepoRoutes
func AddRepoRoutes(s *store.Engine, r *gin.Engine) {
r.GET("/users/:username/repos", func(c *gin.Context) {
var repos []*Repo
for _, repo := range s.State.Repos {
if repo.RepoOwner.Username == c.Param("username") {
repos = append(repos, repo)
}
}
c.JSON(http.StatusOK, repos)
})
r.GET("/users/:username/repos/:reponame", func(c *gin.Context) {
var repo *Repo
for _, rp := range s.State.Repos {
if rp.RepoOwner.Username == c.Param("username") &&
rp.Name == c.Param("reponame") {
repo = rp
break
}
}
c.JSON(http.StatusOK, repo)
})
}
示例5: defineRouting
func defineRouting(router *gin.Engine) {
router.POST("/answer/new", CreateAnswer)
router.POST("/question/new", CreateQuestion)
router.POST("/survey/new", CreateSurvey)
router.POST("/person/new", CreatePerson)
router.GET("/survey/:id", GetSurvey)
}
示例6: SetupRoutes
func SetupRoutes(router *gin.Engine) {
router.GET("/", GetHome)
router.GET("/static/*path", GetAsset)
api := router.Group("/api")
{
SetupMiddlewares(api)
api.GET("/info", GetInfo)
api.POST("/connect", Connect)
api.GET("/databases", GetDatabases)
api.GET("/connection", GetConnectionInfo)
api.GET("/activity", GetActivity)
api.GET("/schemas", GetSchemas)
api.GET("/tables", GetTables)
api.GET("/tables/:table", GetTable)
api.GET("/tables/:table/rows", GetTableRows)
api.GET("/tables/:table/info", GetTableInfo)
api.GET("/tables/:table/indexes", GetTableIndexes)
api.GET("/query", RunQuery)
api.POST("/query", RunQuery)
api.GET("/explain", ExplainQuery)
api.POST("/explain", ExplainQuery)
api.GET("/history", GetHistory)
api.GET("/bookmarks", GetBookmarks)
}
}
示例7: setupRoutes
// setupRoutes is an internal method where we setup application routes
func setupRoutes(r *gin.Engine) {
// TODO: home route "/" is not yet defined.
// r.GET("/", ...)
// static files served by application
r.Static("/static", "./static")
// auth urls for the login form and logout url
r.GET("/login", auth.Login)
r.POST("/login", auth.Login)
r.GET("/logout", auth.Logout)
// sessionResource is a special auth api resource, with POST and DELETE
// endpoints used for logging a user in or out.
sessionResource := r.Group("/api/session")
{
sessionResource.POST("", auth.LoginAPI)
sessionResource.DELETE("", auth.LogoutAPI)
}
// admin urls
adminRoutes := r.Group("/admin", auth.LoginRequired())
{
adminRoutes.GET("", admin.Admin)
adminRoutes.GET("/json", admin.JSONTest)
}
}
示例8: registerRoutes
func registerRoutes(e *gin.Engine) {
controller := rc.ResourceController{}
controller.DatabaseProvider = Database
resourceNames := []string{"RecordMatchContext",
"RecordMatchSystemInterface", "RecordSet"}
for _, name := range resourceNames {
e.GET("/"+name+"/:id", controller.GetResource)
e.POST("/"+name, controller.CreateResource)
e.PUT("/"+name+"/:id", controller.UpdateResource)
e.DELETE("/"+name+"/:id", controller.DeleteResource)
e.GET("/"+name, controller.GetResources)
}
e.POST("/AnswerKey", controller.SetAnswerKey)
name := "RecordMatchRun"
e.GET("/"+name, controller.GetResources)
e.GET("/"+name+"/:id", controller.GetResource)
e.POST("/"+name, rc.CreateRecordMatchRunHandler(Database))
e.PUT("/"+name+"/:id", controller.UpdateResource)
e.DELETE("/"+name+"/:id", controller.DeleteResource)
e.GET("/RecordMatchRunMetrics", rc.GetRecordMatchRunMetricsHandler(Database))
e.GET("/RecordMatchRunLinks/:id", rc.GetRecordMatchRunLinksHandler(Database))
e.Static("/ptmatch/api/", "api")
}
示例9: Init
// Init initializes application routers.
func Init(g *gin.Engine) {
g.Use(middleware.UserFromToken())
// Home page.
g.GET("/", Home)
// Health check group.
h := g.Group("/h")
{
h.GET("/ping", health.Ping)
}
// User related group.
u := g.Group("/user")
{
usin := u.Group("/signin")
usin.Use(middleware.NotAuthenticated())
{
usin.POST("/:service", auth.SignIn)
usin.GET("/:service/complete", auth.SignInComplete)
}
urepos := u.Group("/repos")
urepos.Use(middleware.Authenticated())
{
urepos.GET("/:service", repos.ReposList)
urepos.PATCH("/:service", repos.ReposUpdate)
}
}
}
示例10: Register
func Register(r *gin.Engine) {
api(r.Group("/api"))
r.GET("/", showIndex)
r.GET("/h/:_", showIndex)
r.GET("/p/:_", showIndex)
}
示例11: RegisterHandlers
func (h *UserHandlers) RegisterHandlers(g *gin.Engine) {
g.GET("/user", h.All)
g.GET("/user/:id", h.GetUser)
g.PUT("/user", h.CreateUser)
g.POST("/user/:id", h.UpdateUser)
g.DELETE("/user/:id", h.DeleteUser)
g.POST("/user/:id/password", h.ChangePassword)
}
示例12: initGin
//Setup gin Engine server
func initGin(ginEngine *gin.Engine) {
ginEngine.Use(logrusLogger())
ginEngine.POST("/assignment", putAssignment)
ginEngine.POST("/submission", putSubmission)
ginEngine.GET("/plugin/langs", getSupportedLangs)
ginEngine.GET("/debug/vars", expvarGin.Handler())
ginEngine.GET("/health", healthCheck)
}
示例13: main
func main() {
flag.Parse()
if *logToFile {
logWriteTo, err := os.OpenFile(logFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
log.Printf("error opening to log file: %v", err)
}
if logWriteTo != nil {
log.SetOutput(logWriteTo)
}
}
gin.SetMode(*ginMode)
var route *gin.Engine
if *useGinLogger {
route = gin.Default()
} else {
route = gin.New()
route.Use(logger)
}
route.GET("/", func(ctx *gin.Context) {
ctx.JSON(200, gin.H{"message": "Its an entry point :)"})
})
route.GET("/token", func(ctx *gin.Context) {
tokenString := auth.GetToken(secretpassword)
ctx.JSON(200, gin.H{"token": tokenString})
})
route.GET("/dbaccessor", func(ctx *gin.Context) {
ctx.JSON(200, getFakeDbData())
})
route.Use(auth.Auth(secretpassword))
route.POST("/auth", func(ctx *gin.Context) {
ak := ctx.Request.FormValue("authkey")
if ak == "" {
ctx.JSON(401, "No auth key")
} else if !auth.VerifyAuthKey(ak) {
ctx.JSON(401, "Wrong key")
} else {
ctx.Redirect(http.StatusFound, "/user")
}
})
route.GET("/user", func(ctx *gin.Context) {
key := ctx.MustGet("authKey")
udetails := dbAccessor(key.(string))
ctx.JSON(200, gin.H{"user": udetails})
})
route.GET("/user/:id", func(ctx *gin.Context) {
id := ctx.Params.ByName("id")
ctx.JSON(200, find(id))
})
if err := route.Run(fmt.Sprintf(":%d", *port)); err != nil {
logFatal("Http not running: ", err)
} else {
logPrintln("shutting down")
}
}
示例14: Controller
// Controller for taxonomies resources
func Controller(r *gin.Engine, db *sql.DB) {
r.GET("/taxonomies", func(c *gin.Context) {
taxonomies, err := ListAllTaxonomies(db)
if err != nil {
c.AbortWithError(400, err)
return
}
c.Header("Content-Type", "application/json")
c.String(200, taxonomies)
})
r.POST("/taxonomy", func(c *gin.Context) {
tax := new(Taxonomy)
err := c.BindJSON(&tax)
if err != nil {
c.Error(err)
return
}
err = CreateTaxonomy(tax, db)
if err != nil {
c.AbortWithError(400, err)
return
}
c.String(200, "")
})
r.DELETE("/taxonomy/:id", func(c *gin.Context) {
defer func() {
if r := recover(); r != nil {
c.AbortWithError(400, r.(error))
}
}()
id := getID(c)
err := DeleteTaxonomy(id, db)
if err != nil {
panic(err)
}
c.String(200, "")
})
r.PUT("/taxonomy/:id", func(c *gin.Context) {
defer func() {
if r := recover(); r != nil {
c.AbortWithError(400, r.(error))
}
}()
id := getID(c)
tax := new(Taxonomy)
err := c.BindJSON(&tax)
if err != nil {
panic(err)
}
err = UpdateTaxonomy(id, tax, db)
if err != nil {
c.AbortWithError(400, err)
return
}
c.String(200, "")
})
}
示例15: Setup
func (h *StaticHandler) Setup(engine *gin.Engine) {
fs := gin.Dir(h.Root, false)
h.fileServer = http.StripPrefix("/", http.FileServer(fs))
engine.GET("/*filepath", h.Handle)
engine.HEAD("/*filepath", h.Handle)
return
}