func (ri *RequestId) Init(env zerver.Environment) error { defval.Nil(&ri.Store, new(MemIDStore)) ri.Store.Init(env) defval.String(&ri.HeaderName, "X-Request-Id") defval.String(&ri.Error, "header value X-Request-Id can't be empty") defval.String(&ri.ErrorOverlap, "request already accepted before, please wait") ri.logger = env.Logger().Prefix("[RequestID]") return nil }
func (j *JWTAuth) Init(s *zerver.Server) error { if j.JWT == nil { return ErrNilJWT } if j.JWT.Keyfunc == nil { return ErrNilKeyFunc } defval.String(&j.AuthTokenAttrName, "AuthToken") defval.Nil(&j.JWT.SigningMethod, jwt.SigningMethodHS256) return nil }
func (x *Xsrf) Init(env zerver.Environment) error { if x.Secret == "" { return errors.Err("xsrf secret can't be empty") } defval.Int64(&x.Timeout, _DEF_XSRF_TIMEOUT) defval.Nil(&x.HashMethod, sha256.New) defval.String(&x.Error, "xsrf token is invalid or not found") if x.UsePool { if x.Pool == nil { x.Pool = bytes2.NewSyncPool(0, true) } } else { x.Pool = bytes2.FakePool{} } defval.Nil(&x.TokenInfo, jsonToken{}) x.logger = env.Logger().Prefix("[XSRF]") return nil }
func (c *CORS) Init(zerver.Environment) error { if l := len(c.Origins); l == 0 || (l == 1 && c.Origins[0] == "*") { c.allowAll = true c.Origins = nil } defval.Nil(&c.Methods, defAllowMethods) c.methods = strings.Join(c.Methods, ",") defval.Nil(&c.Headers, defAllowHeaders) c.headers = strings.Join(c.Headers, ",") for i := range c.Headers { c.Headers[i] = strings.ToLower(c.Headers[i]) // chrome browser will use lower header } c.exposeHeaders = strings.Join(c.ExposeHeaders, ",") defval.BoolStr(c.AllowCredentials, &c.allowCredentials) if c.PreflightMaxage != 0 { c.preflightMaxage = strconv.Itoa(c.PreflightMaxage) } return nil }