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


Golang Engine.Static方法代码示例

本文整理汇总了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)
}
开发者ID:cultome,项目名称:tickets,代码行数:33,代码来源:routes.go

示例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)
	//	})

}
开发者ID:wataru420,项目名称:gin-template,代码行数:35,代码来源:router.go

示例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")
}
开发者ID:mitre,项目名称:ptmatch,代码行数:29,代码来源:server_setup.go

示例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)
	}
}
开发者ID:robvdl,项目名称:gcms,代码行数:28,代码来源:web.go

示例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
}
开发者ID:Depado,项目名称:goploader,代码行数:34,代码来源:assets.go

示例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
}
开发者ID:caducorrea,项目名称:gojira,代码行数:15,代码来源:static.go

示例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(""))
}
开发者ID:wangmingjob,项目名称:goyangi,代码行数:18,代码来源:index.go

示例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)
}
开发者ID:goodplayer,项目名称:Princess,代码行数:20,代码来源:route.go

示例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")
}
开发者ID:ivan-uskov,项目名称:automat-course-labs,代码行数:5,代码来源:main.go

示例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)

//.........这里部分代码省略.........
开发者ID:earaujoassis,项目名称:space,代码行数:101,代码来源:views.go

示例11: route

func route(r *gin.Engine) {
	r.Static("/assets", "assets")
	r.GET("/", getApp)
	r.GET("/search", getSearch)
	r.POST("/result", postResult)
}
开发者ID:yatuhata,项目名称:golang,代码行数:6,代码来源:app.go

示例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)
			}
		})
//.........这里部分代码省略.........
开发者ID:nzai,项目名称:lottery,代码行数:101,代码来源:route.go


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