當前位置: 首頁>>代碼示例>>Golang>>正文


Golang sessions.NewCookieStore函數代碼示例

本文整理匯總了Golang中github.com/gin-gonic/contrib/sessions.NewCookieStore函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewCookieStore函數的具體用法?Golang NewCookieStore怎麽用?Golang NewCookieStore使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewCookieStore函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: main

func main() {

	r := gin.Default()
	r.Static("/assets", "assets")
	store := sessions.NewCookieStore([]byte("gssecret"))
	r.Use(sessions.Sessions("mysession", store))
	r.LoadHTMLGlob("templates/*")

	fc := new(FrontController)
	r.GET("/", fc.HomeCtr)
	r.GET("/about", fc.AboutCtr)
	r.GET("/view/:id", fc.ViewCtr)
	r.GET("/view.php", fc.ViewAltCtr)
	r.GET("/ping", fc.PingCtr)
	r.GET("/search", fc.SearchCtr)

	ac := new(AdminController)
	admin := r.Group("/admin")
	{
		admin.GET("/", ac.ListBlogCtr)
		admin.GET("/login", ac.LoginCtr)
		admin.POST("/login-process", ac.LoginProcessCtr)
		admin.GET("/logout", ac.LogoutCtr)
		admin.GET("/addblog", ac.AddBlogCtr)
		admin.POST("/save-blog-add", ac.SaveBlogAddCtr)
		admin.GET("/listblog", ac.ListBlogCtr)
		admin.GET("/deleteblog/:id", ac.DeleteBlogCtr)
		admin.POST("/save-blog-edit", ac.SaveBlogEditCtr)
		admin.GET("/editblog/:id", ac.EditBlogCtr)
	}
	// Listen and serve on 0.0.0.0:8080
	r.Run(":8080")
}
開發者ID:shitfSign,項目名稱:gosense,代碼行數:33,代碼來源:main.go

示例2: Init

func Init() {
	if router == nil {
		gin.SetMode(gin.TestMode)
		router = gin.Default()
		templ := template.New("index")
		router.SetHTMLTemplate(templ)
		store := sessions.NewCookieStore([]byte("foundation"))
		router.Use(sessions.Sessions("foundation", store))
		portNo := 0
		go func() {
			router.GET("/", func(c *gin.Context) {
				shared = *c
			})

			for portNo = 8124; true; portNo++ {

				addr := fmt.Sprintf(`:%d`, portNo)
				err := router.Run(addr)
				if err != nil {
					if strings.HasSuffix(err.Error(), `address already in use`) {
						continue
					}
				}

				break
			}

		}()
		time.Sleep(50 * time.Millisecond)
		http.Get(fmt.Sprintf("http://localhost:%d/", portNo)) // portNoが0じゃなくなるまでwaitしたほうが良い気もするが一旦
	}
}
開發者ID:gophergala2016,項目名稱:source,代碼行數:32,代碼來源:context.go

示例3: init

func init() {
	log.Logger.Info("init session ...")

	SessionStore = sessions.NewCookieStore([]byte("_IlikeUkeTravel.com_oyear"))

	log.Logger.Info("session inited")
}
開發者ID:sdvdxl,項目名稱:wine,代碼行數:7,代碼來源:session.go

示例4: main

func main() {
	r := gin.Default()
	store := sessions.NewCookieStore([]byte(helper.Cookiesecret))

	r.Use(sessions.Sessions("todo_session", store))

	r.LoadHTMLGlob("templates/*")

	r.GET("/todo", displayTodo)

	r.Run(":8200")
}
開發者ID:dolanor,項目名稱:microservices,代碼行數:12,代碼來源:todo.go

示例5: Sessions

func Sessions() gin.HandlerFunc {
	switch conf.SESSION_STORE {
	case conf.REDIS:
		store, err := gin_sessions.NewRedisStore(10, "tcp", conf.REDIS_SERVER, conf.REDIS_PWD, []byte("secret"))
		if err != nil {
			panic(err)
		}
		return gin_sessions.Sessions("mysession", store)
	default:
		store := gin_sessions.NewCookieStore([]byte("secret"))
		return gin_sessions.Sessions("mysession", store)
	}
}
開發者ID:hobo-c,項目名稱:gin_sample,代碼行數:13,代碼來源:sessions.go

示例6: main

func main() {
	r := gin.Default()
	store := sessions.NewCookieStore([]byte(helper.Cookiesecret))

	r.Use(sessions.Sessions("todo_session", store))

	r.LoadHTMLGlob("templates/*")

	r.GET("/login", displayLogin)
	r.POST("/login", postLogin)
	r.GET("/user/:username", displayProfile)

	r.Run(":8100")
}
開發者ID:dolanor,項目名稱:microservices,代碼行數:14,代碼來源:auth.go

示例7: Run

func Run(config *config.Config, etcd *store.Etcd) {
	oauthConf := oauth2.Config{
		ClientID:     config.GitHubClientID,
		ClientSecret: config.GitHubClientSecret,
		Scopes:       []string{"user", "read:public_key"},
		Endpoint:     githuboauth.Endpoint,
	}

	if config.ReleaseMode {
		gin.SetMode(gin.ReleaseMode)
	}

	sessionStore := sessions.NewCookieStore([]byte(config.SecretKeyBase))

	r := gin.Default()
	r.Use(sessions.Sessions(AppName, sessionStore))
	r.Static("/assets", "assets")
	r.LoadHTMLGlob("templates/*")

	rootController := controller.NewRootController(config, etcd)
	appController := controller.NewAppController(config, etcd)
	argController := controller.NewArgController(config, etcd)
	envController := controller.NewEnvController(config, etcd)
	healthcheckController := controller.NewHealthcheckController(config, etcd)
	sessionController := controller.NewSessionController(config, etcd, oauthConf)

	r.GET("/", rootController.Index)

	r.GET("/signin", sessionController.SignIn)
	r.GET("/signout", sessionController.SignOut)
	r.GET("/oauth/callback", sessionController.Callback)
	r.GET("/update-keys", sessionController.UpdateKeys)

	r.GET("/apps", appController.Index)
	r.POST("/apps", appController.New)

	r.GET("/apps/:appName", appController.Get)

	r.POST("/apps/:appName/build-args", argController.New)
	r.POST("/apps/:appName/build-args/delete", argController.Delete) // TODO: DELETE /apps/:appName/build-args

	r.POST("/apps/:appName/envs", envController.New)
	r.POST("/apps/:appName/envs/delete", envController.Delete) // TODO: DELETE /apps/:appName/envs
	r.POST("/apps/:appName/envs/upload", envController.Upload)

	r.POST("/apps/:appName/healthcheck", healthcheckController.Update)

	r.Run()
}
開發者ID:dtan4,項目名稱:paus-frontend,代碼行數:49,代碼來源:server.go

示例8: setSessions

//setSessions initializes sessions & csrf middlewares
func setSessions(router *gin.Engine) {
	config := system.GetConfig()
	//https://github.com/gin-gonic/contrib/tree/master/sessions
	store := sessions.NewCookieStore([]byte(config.SessionSecret))
	store.Options(sessions.Options{HttpOnly: true, MaxAge: 7 * 86400}) //Also set Secure: true if using SSL, you should though
	router.Use(sessions.Sessions("gin-session", store))
	//https://github.com/utrack/gin-csrf
	router.Use(csrf.Middleware(csrf.Options{
		Secret: config.SessionSecret,
		ErrorFunc: func(c *gin.Context) {
			c.String(400, "CSRF token mismatch")
			c.Abort()
		},
	}))
}
開發者ID:denisbakhtin,項目名稱:ginblog,代碼行數:16,代碼來源:main.go

示例9: init

func init() {
	gin.SetMode(gin.DebugMode)
	rand.Seed(time.Now().UnixNano())
	servidor = gin.Default()

	store := sessions.NewCookieStore([]byte("ef7fbfd3d599befe7a86cbf37c8f05c814dcad918b8dbefb441de846c4f62ea3"))
	servidor.Use(sessions.Sessions("mysession", store))

	cargarTemplates()
	servidor.Use(static.Serve("/", static.LocalFile("./public", false)))
	servidor.StaticFile("/login", "./public/index.html")
	servidor.NoRoute(func(c *gin.Context) {
		html.ExecuteTemplate(c.Writer, "404.html", nil)
	})
}
開發者ID:gophergala2016,項目名稱:kentia,代碼行數:15,代碼來源:router.go

示例10: NewRememberMe

func NewRememberMe(engine *gin.Engine, cookieKey string, maxAge int, secret string) {

	rememberMeConf = RememberMeConf{
		CookieKey: cookieKey,
		MaxAge:    maxAge,
		Secret:    secret,
	}

	options := sessions.Options{
		Path:     "/",
		MaxAge:   rememberMeConf.MaxAge,
		HttpOnly: true,
	}
	cookieStore = sessions.NewCookieStore([]byte(rememberMeConf.Secret))
	cookieStore.Options(options)
}
開發者ID:springCat,項目名稱:go_utils,代碼行數:16,代碼來源:rememberMe.go

示例11: Setup

// Setup the authorization path
func Setup(redirectURL, credFile string, scopes []string, secret []byte) {
	store = sessions.NewCookieStore(secret)
	var c Credentials
	file, err := ioutil.ReadFile(credFile)
	if err != nil {
		glog.Fatalf("[Gin-OAuth] File error: %v\n", err)
	}
	json.Unmarshal(file, &c)

	conf = &oauth2.Config{
		ClientID:     c.ClientID,
		ClientSecret: c.ClientSecret,
		RedirectURL:  redirectURL,
		Scopes:       scopes,
		Endpoint:     google.Endpoint,
	}
}
開發者ID:zalando,項目名稱:gin-oauth2,代碼行數:18,代碼來源:google.go

示例12: main

/*
 * Main function
 */
func main() {
	//fmt.Printf("Register function . Sqrt1(4) = %v\n", register.Sqrt1(4))

	r := gin.New()
	//	r := gin.Default()
	store := sessions.NewCookieStore([]byte("myappsecret"))
	r.Use(sessions.Sessions("mygroups", store))
	r.Use(Is_authorised())

	//r.LoadHTMLGlob("templates/*")

	templates := multitemplate.New()
	templates.AddFromFiles("home", "home.html", "header.html", "footer.html")
	templates.AddFromFiles("register", "register.html", "header.html", "footer.html")
	r.HTMLRender = templates

	//fmt.Println(register.Sqrt(2))
	//r.HTMLRender = loadTemplates("./templates")
	r.StaticFS("/css/", http.Dir("css"))
	r.StaticFS("/images/", http.Dir("images"))

	/*
		r.GET("/", func(c *gin.Context) {
			c.HTML(http.StatusOK,
				"home",
				gin.H{
					"Title": "Login Here",
				},
			)
		})
	*/

	r.GET("/", register.HomeHandler)
	r.POST("/", register.LoginHandler)
	r.POST("/register", register.RegisterHandler)
	r.GET("/register", func(c *gin.Context) {
		c.HTML(http.StatusOK,
			"register",
			gin.H{
				"Title": "New Registration",
			},
		)
	})
	r.Run(":8090")

}
開發者ID:gopagoninarsing,項目名稱:go-groups,代碼行數:49,代碼來源:main.go

示例13: main

func main() {
	r := gin.Default()
	store := sessions.NewCookieStore([]byte("secret"))
	r.Use(sessions.Sessions("mysession", store))

	r.GET("/incr", func(c *gin.Context) {
		session := sessions.Default(c)
		var count int
		v := session.Get("count")
		if v == nil {
			count = 0
		} else {
			count = v.(int)
			count += 1
		}
		session.Set("count", count)
		session.Save()
		c.JSON(200, gin.H{"count": count})
	})
	r.Run(":8000")
}
開發者ID:doubledutch,項目名稱:dd-vote,代碼行數:21,代碼來源:example_cookie.go

示例14: main

func main() {
	log.Printf("setting up gin ...")
	r := gin.Default()
	r.Static("/static", "static")
	r.LoadHTMLGlob("templates/*")

	log.Printf("setting up session store ...")
	store := sessions.NewCookieStore([]byte("secret"))
	r.Use(sessions.Sessions("whiskee", store))

	log.Printf("setting up database ...")
	r.Use(PostgresDatabase())

	log.Printf("setting up transloadit ...")
	r.Use(Transloadit())

	log.Printf("setting up routes ...")
	r.GET("/", HomeR)
	r.GET("/auth/callback", CallbackR)
	r.GET("/auth/logout", LogoutR)

	r.GET("/home", HomeR)
	r.GET("/whisky", WhiskyListR)
	r.GET("/whisky/:id", WhiskyR)
	r.GET("/user", UserListR)
	r.GET("/user/:id", UserR)

	r.GET("/add/whisky", AddWhiskyFormR)
	r.POST("/add/whisky", AddWhiskyR)
	r.GET("/edit/whisky/:id", EditWhiskyFormR)
	r.POST("/edit/whisky/:id", EditWhiskyR)

	r.POST("/add/review", AddReviewR)
	r.GET("/edit/review/:id", EditReviewFormR)
	r.POST("/edit/review/:id", EditReviewR)

	port := os.Getenv("PORT")
	log.Printf("listening on :%s", port)
	r.Run(":" + port)
}
開發者ID:sprungknoedl,項目名稱:whiskee,代碼行數:40,代碼來源:main.go

示例15: main

func main() {
	// database
	mgoSession, err := mgo.Dial("128.199.130.44:27017")
	if err != nil {
		panic(err)
	}

	// register services
	userService := user.New(userStore.New(mgoSession, "example"))
	loginService := login.New(userService)
	registerService := register.New(userService)

	// create server
	r := render.New(render.Options{
		Directory:     "server/views",
		Layout:        "layout",
		Extensions:    []string{".html"},
		Delims:        render.Delims{"[[", "]]"},
		IsDevelopment: true,
	})

	g := gin.New()
	g.Use(cors.Middleware(cors.Config{
		Origins:         "*",
		Methods:         "GET, PUT, POST, DELETE",
		RequestHeaders:  "Origin, Content-Type",
		Credentials:     true,
		ValidateHeaders: false,
	}))
	g.Use(sessions.Sessions("webadmin", sessions.NewCookieStore([]byte("something-very-secret"))))
	g.Static("/assets", "./public")

	// register handlers
	NewUserHandlers(userService, r).RegisterHandlers(g)
	NewFrontendHandlers(loginService, registerService, r).RegisterHandlers(g)

	// run server
	g.Run(":3000")
}
開發者ID:thanhliem89dn,項目名稱:microservices-book-code,代碼行數:39,代碼來源:main.go


注:本文中的github.com/gin-gonic/contrib/sessions.NewCookieStore函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。