Beispiel #1
0
func NewKit(c *cli.Context, conf *config.Config) *Kit {
	co, err := conf.Get(c.String("config"))
	co.Env() // parse environ variables
	Must(err)

	// set up gin
	if !co.UBool("debug") {
		gin.SetMode(gin.ReleaseMode)
	}

	return &Kit{
		Conf: co,
	}
}
func session(config *config.Config) (s sessions.Store, err error) {

	secret := []byte(config.UString("secret", "go-default-secret"))
	t := config.UString("type", "cookie")

	switch t {
	case "cookie":
		s = sessions.NewCookieStore(secret)
	case "redis":
		s, err = sessions.NewRedisStore(
			config.UInt("size"),
			config.UString("network"),
			config.UString("address"),
			config.UString("password"),
			secret,
		)
	default:
		err = errors.New("No session type allowed.")
	}

	if err != nil {
		return nil, err
	}

	o, _ := config.Get("options")

	if o != nil {
		s.Options(sessions.Options{
			Path:     o.UString("path"),
			Domain:   o.UString("domain"),
			MaxAge:   o.UInt("max_age", int(30*time.Minute)),
			Secure:   o.UBool("secure"),
			HttpOnly: o.UBool("http_only"),
		})
	}

	return s, nil
}