Exemple #1
0
// Init should be called anyway
func (h *Handler) Init() *Handler {
	if h.SaveImage == nil {
		panic("the function to save image should not be nil")
	}

	defval.Int64(&h.MaxMemory, 1<<19) // 512K

	defval.String(&h.FileKey, "image")
	if h.ErrNoFile == nil {
		h.ErrNoFile = httperrs.BadRequest.NewS("upload file not exists")
	}

	if h.Suffixes == nil {
		h.AddSuffixes("png", "jpg")
	}

	if h.ErrNonImage == nil {
		h.ErrNonImage = httperrs.BadRequest.NewS("the upload file is not an image")
	}

	defval.Int64(&h.MaxSize, 1<<18) // 256K
	if h.ErrTooLarge == nil {
		h.ErrTooLarge = httperrs.BadRequest.NewS("the upload file size is too large")
	}

	defval.String(&h.PathKey, "path")

	return h
}
Exemple #2
0
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
}
Exemple #3
0
func (r *RedisIDStore) Init(env zerver.Environment) error {
	redis, err := env.Component(component.REDIS)
	if err != nil {
		return err
	}

	r.redis = redis.(*component.Redis)
	defval.String(&r.Key, "RequestID")

	return nil
}
Exemple #4
0
func (o *ServerOption) init() {
	defval.String(&o.ListenAddr, ":4000")
	defval.Int(&o.PathVarCount, 3)
	defval.Int(&o.FilterCount, 5)
	if o.KeepAlivePeriod == 0 {
		o.KeepAlivePeriod = 3 * time.Minute // same as net/http/server.go:tcpKeepAliveListener
	}
	if o.Logger == nil {
		o.Logger = log2.Default()
	}
}
Exemple #5
0
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
}
Exemple #6
0
func (o *RedisOption) init() {
	if o.MaxIdle == 0 {
		o.MaxIdle = 8
	}

	if o.Dial == nil {
		defval.String(&o.Addr, ":6379")

		o.Dial = func() (redis.Conn, error) {
			return redis.Dial("tcp", o.Addr)
		}
	}
}
Exemple #7
0
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
}
Exemple #8
0
func (l *Log) Init(env zerver.Environment) error {
	defval.String(&l.Prefix, "[Access]")
	l.logger = env.Logger().Prefix(l.Prefix)
	return nil
}