本文整理匯總了Golang中github.com/gin-gonic/gin.Engine.Static方法的典型用法代碼示例。如果您正苦於以下問題:Golang Engine.Static方法的具體用法?Golang Engine.Static怎麽用?Golang Engine.Static使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gin-gonic/gin.Engine
的用法示例。
在下文中一共展示了Engine.Static方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: prepareRoutes
func prepareRoutes(router *gin.Engine) {
// Web Resources
router.Static("/static", "web/dist")
// API Routes
api := router.Group("/api/v1")
admin := api.Group("/admin")
public := api.Group("/public")
registered := api.Group("/")
sameRegisteredUser := api.Group("/user")
prepareMiddleware(admin, public, registered, sameRegisteredUser)
admin.GET("/users", listUsers)
admin.GET("/places", listPlaces)
admin.POST("/places", createPlace)
admin.POST("/events", createEvent)
admin.PUT("/place/:placeId", updatePlace)
admin.PUT("/event/:eventId", updateEvent)
admin.DELETE("/event/:eventId", cancelEvent)
sameRegisteredUser.GET("/:userId", getUser)
sameRegisteredUser.PUT("/:userId", updateUser)
sameRegisteredUser.DELETE("/:userId", disableUser)
registered.POST("/buy/:seatId", buyTicket)
public.GET("/place/:placeId", getPlace)
public.GET("/events", listEvents)
public.GET("/event/:eventId", getEvent)
public.POST("/users", createUser) // TODO Checar, me huele raro......
public.POST("/login", loginUser)
}
示例2: 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)
// })
}
示例3: 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")
}
示例4: 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)
}
}
示例5: InitAssetsTemplates
// InitAssetsTemplates initializes the router to use either a ricebox or the
// filesystem in case the ricebox couldn't be found.
func InitAssetsTemplates(r *gin.Engine, tbox, abox *rice.Box, verbose bool, names ...string) error {
var err error
if tbox != nil {
mt := multitemplate.New()
var tmpl string
var message *template.Template
for _, x := range names {
if tmpl, err = tbox.String(x); err != nil {
return err
}
if message, err = template.New(x).Parse(tmpl); err != nil {
return err
}
mt.Add(x, message)
}
logger.Debug("server", "Loaded templates from \"templates\" box")
r.HTMLRender = mt
} else {
r.LoadHTMLGlob("templates/*")
logger.Debug("server", "Loaded templates from disk")
}
if abox != nil {
r.StaticFS("/static", abox.HTTPBox())
logger.Debug("server", "Loaded assets from \"assets\" box")
} else {
r.Static("/static", "assets")
logger.Debug("server", "Loaded assets from disk")
}
return nil
}
示例6: SetStaticRoutes
func SetStaticRoutes(router *gin.Engine) *gin.Engine {
router.LoadHTMLFiles("views/index.html")
router.Static("/static", "./static")
router.GET("/", func(c *gin.Context) {
c.HTML(http.StatusOK, "index.html", gin.H{})
})
router.GET("/ping", func(c *gin.Context) {
c.String(200, "pong")
})
return router
}
示例7: LoadPage
func LoadPage(parentRoute *gin.Engine) {
//type Page struct {
// Title string
//}
parentRoute.SetHTMLTemplate(template.Must(template.ParseFiles("frontend/canjs/templates/message.html", "frontend/canjs/templates/app.html", "frontend/canjs/templates/base.html", "frontend/canjs/templates/404.html")))
log.Debug("url : " + config.StaticUrl)
log.Debug("guid : " + config.Guid)
log.Debug("path : " + staticPath)
parentRoute.Static(config.StaticUrl+"/"+config.Guid, staticPath)
// route.ServeFiles doesn't exist in the current version of gin. If you want to use this, use the 59d949d35080b83864dbeafadecef112d46aaeee.
//parentRoute.ServeFiles(config.StaticUrl+"/"+config.Guid+"/*filepath", http.Dir(staticPath))
parentRoute.NoRoute(func(c *gin.Context) {
c.HTML(404, "404.html", map[string]string{"language": config.DefaultLanguage, "title": config.Title})
})
route.Route(parentRoute.Group(""))
}
示例8: RegisterRoute
func RegisterRoute(r *gin.Engine) {
loadHTMLGlob(r, path.Join(config.GLOBAL_CONFIG.TemplatePath, "*"), registerDefaultFunctions)
r.GET("/", IndexAction)
r.GET("/post/:postId", ShowPostAction)
r.POST("/login", LoginAction)
r.POST("/register", RegisterAction)
r.GET("/logout", LogoutAction)
r.GET("/new_post", ShowNewPostPageAction)
r.POST("/posts", NewPostAction)
// admin
r.GET("/admin/users", controllers.ShowUsersAction)
r.Static("/statics", config.GLOBAL_CONFIG.StaticPath)
r.NoRoute(NoRouteHandler)
}
示例9: setupStatic
func setupStatic(router *gin.Engine) {
router.Static("/css", STATIC_DIR+"css")
router.Static("/js", STATIC_DIR+"js")
router.LoadHTMLGlob(STATIC_DIR + "tpl/*.tpl")
}
示例10: ExposeRoutes
func ExposeRoutes(router *gin.Engine) {
router.LoadHTMLGlob("web/templates/*.html")
router.HTMLRender = createCustomRender()
if config.IsEnvironment("production") && config.GetConfig("SPACE_CDN") != "" {
spaceCDN = config.GetConfig("SPACE_CDN")
} else {
spaceCDN = "/public"
router.Static("/public", "web/public")
}
store := sessions.NewCookieStore([]byte(config.GetConfig("SPACE_SESSION_SECRET")))
store.Options(sessions.Options{
Secure: config.IsEnvironment("production"),
HttpOnly: true,
})
router.Use(sessions.Sessions("jupiter.session", store))
views := router.Group("/")
{
views.GET("/", jupiterHandler)
views.GET("/profile", jupiterHandler)
views.GET("/signup", func(c *gin.Context) {
c.HTML(http.StatusOK, "satellite", utils.H{
"AssetsEndpoint": spaceCDN,
"Title": " - Sign up",
"Satellite": "io",
"Data": utils.H{
"feature.gates": utils.H{
"user.create": feature.Active("user.create"),
},
},
})
})
views.GET("/signin", func(c *gin.Context) {
c.HTML(http.StatusOK, "satellite", utils.H{
"AssetsEndpoint": spaceCDN,
"Title": " - Sign in",
"Satellite": "ganymede",
})
})
views.GET("/signout", func(c *gin.Context) {
session := sessions.Default(c)
userPublicId := session.Get("userPublicId")
if userPublicId != nil {
session.Delete("userPublicId")
session.Save()
}
c.Redirect(http.StatusFound, "/signin")
})
views.GET("/session", func(c *gin.Context) {
session := sessions.Default(c)
userPublicId := session.Get("userPublicId")
if userPublicId != nil {
c.Redirect(http.StatusFound, "/")
return
}
var nextPath string = "/"
var scope string = c.Query("scope")
var grantType string = c.Query("grant_type")
var code string = c.Query("code")
var clientId string = c.Query("client_id")
var _nextPath string = c.Query("_")
//var state string = c.Query("state")
if scope == "" || grantType == "" || code == "" || clientId == "" {
// Original response:
// c.String(http.StatusMethodNotAllowed, "Missing required parameters")
c.Redirect(http.StatusFound, "/signin")
return
}
if _nextPath != "" {
if _nextPath, err := url.QueryUnescape(_nextPath); err == nil {
nextPath = _nextPath
}
}
client := services.FindOrCreateClient("Jupiter")
if client.Key == clientId && grantType == oauth.AuthorizationCode && scope == models.PublicScope {
grantToken := services.FindSessionByToken(code, models.GrantToken)
if grantToken.ID != 0 {
session.Set("userPublicId", grantToken.User.PublicId)
session.Save()
services.InvalidateSession(grantToken)
c.Redirect(http.StatusFound, nextPath)
return
}
}
c.Redirect(http.StatusFound, "/signin")
})
views.GET("/authorize", authorizeHandler)
views.POST("/authorize", authorizeHandler)
//.........這裏部分代碼省略.........
示例11: route
func route(r *gin.Engine) {
r.Static("/assets", "assets")
r.GET("/", getApp)
r.GET("/search", getSearch)
r.POST("/result", postResult)
}
示例12: RegisterRoute
// 注冊路由
func RegisterRoute(route *gin.Engine) {
// 靜態文件目錄
route.Static("static", "./static")
// 注冊模板
registerTemplates("static/html/layout.html", "static/html/twocolorball/index.html")
registerTemplates("static/html/layout.html", "static/html/twocolorball/analyze1.html")
registerTemplates("static/html/layout.html", "static/html/twocolorball/analyze2.html")
registerTemplates("static/html/layout.html", "static/html/superlotto/index.html")
registerTemplates("static/html/layout.html", "static/html/superlotto/analyze1.html")
registerTemplates("static/html/layout.html", "static/html/superlotto/analyze2.html")
// 首頁默認轉到雙色球列表
route.GET("/", func(c *gin.Context) {
c.Redirect(http.StatusMovedPermanently, "/twocolorball")
})
// 雙色球
t := route.Group("/twocolorball")
{
// 列表頁麵
t.GET("/", func(c *gin.Context) {
err := processTemplate(c.Writer, "static/html/twocolorball/index.html", nil)
if err != nil {
log.Print(err)
}
})
// 列表查詢
t.GET("/list", func(c *gin.Context) {
paramN := c.Query("n")
n, err := strconv.Atoi(paramN)
if err != nil {
c.JSON(http.StatusOK, entity.ResultSM(false, fmt.Sprintf("錯誤的查詢參數N:%s", paramN)))
return
}
// 查詢
results, err := twocolorball.Query(n)
if err != nil {
c.JSON(http.StatusOK, entity.ResultSM(false, fmt.Sprintf("查詢雙色球數據失敗:%v", err)))
return
}
c.JSON(http.StatusOK, entity.ResultD(results))
})
// 分析1頁麵
t.GET("/analyze1", func(c *gin.Context) {
err := processTemplate(c.Writer, "static/html/twocolorball/analyze1.html", nil)
if err != nil {
log.Print(err)
}
})
// 分析1查詢
t.GET("/doanalyze1", func(c *gin.Context) {
reds := c.Query("reds")
blues := c.Query("blues")
// 紅球
redNums := make([]int, 0)
if len(reds) > 0 {
parts := strings.Split(reds, ",")
for _, value := range parts {
i, err := strconv.Atoi(value)
if err != nil {
c.JSON(http.StatusOK, entity.ResultSM(false, fmt.Sprintf("輸入的參數有誤:%s", value)))
return
}
redNums = append(redNums, i)
}
}
// 藍球
blueNum, err := strconv.Atoi(blues)
// 查詢
results, err := twocolorball.Analyze1(redNums, blueNum)
if err != nil {
c.JSON(http.StatusOK, entity.ResultSM(false, fmt.Sprintf("分析雙色球數據失敗:%v", err)))
return
}
c.JSON(http.StatusOK, entity.ResultD(results))
})
// 分析2頁麵
t.GET("/analyze2", func(c *gin.Context) {
err := processTemplate(c.Writer, "static/html/twocolorball/analyze2.html", nil)
if err != nil {
log.Print(err)
}
})
//.........這裏部分代碼省略.........