Exemplo n.º 1
0
func (j *JSONP) Init(zerver.Env) error {
	if j.CallbackVar == "" {
		return errors.Err("callback name should not be empty")
	}
	j.log = log.Derive("Filter", "JSONP")
	return nil
}
Exemplo n.º 2
0
// Init must be called
func (h *Handler) Init(env zerver.Env) error {
	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")
	}

	h.log = log.Derive("Component", "ImageHandler")
	return nil
}
Exemplo n.º 3
0
func (ri *RequestId) Init(env zerver.Env) 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.log = log.Derive("Component", "RequestId")
	return nil
}
Exemplo n.º 4
0
func (o *ServerOption) init() {
	if o.Logger == nil {
		o.Logger = log.Derive("Framework", "Server")
	}

	defval.String(&o.ListenAddr, ":4000")
	if o.KeepAlivePeriod == 0 {
		o.KeepAlivePeriod = 3 * time.Minute // same as net/http/server.go:tcpKeepAliveListener
	}
	if o.Codec == nil {
		o.Codec = encoding.JSON
	}
}
Exemplo n.º 5
0
func New(clearInterval time.Duration, backend Backend) *Master {
	m := &Master{
		log:       log.Derive("TimingMsq", ""),
		Backend:   backend,
		undeleted: make(set.Strings),
	}

	ex, is := backend.(Expirer)
	if !(is && ex.HasExpiration()) {
		go m.start(clearInterval)
	}

	return m
}
Exemplo n.º 6
0
func RunRemote(tunnel proxy.Proxy, signal Signal) error {
	ln, err := net2.RetryListen("tcp", tunnel.Addr(), 5, 1000)
	if err != nil {
		return err
	}

	r := &Remote{
		tunnel:   tunnel,
		signal:   signal,
		listener: ln,
		log:      log.Derive("Remote", tunnel.Addr()),
	}
	go r.serve()
	return nil
}
Exemplo n.º 7
0
func (m *Queue) Init(env zerver.Env) error {
	if m.Processor == nil {
		return errors.Err("message processor shouldn't be nil")
	}
	if m.TaskBufsize == 0 {
		m.TaskBufsize = 256
	}
	if m.BytesPool == nil {
		m.BytesPool = bytes2.NewFakePool()
	}

	m.queue = make(chan zerver.Task, m.TaskBufsize)
	m.log = log.Derive("TaskHandler", "MessageQueue")
	go m.start()
	return nil
}
Exemplo n.º 8
0
func (x *Xsrf) Init(env zerver.Env) 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.log = log.Derive("Component", "Xsrf")
	return nil
}
Exemplo n.º 9
0
func RunLocal(sock proxy.Proxy, tunnels []proxy.Proxy, signal Signal, directList, tunnelList, suffixList *SiteList) error {
	ln, err := net2.RetryListen("tcp", sock.Addr(), 5, 1000)
	if err != nil {
		return err
	}

	local := &Local{
		directList: directList,
		tunnelList: tunnelList,
		suffixList: suffixList,

		sock:     sock,
		tunnels:  tunnels,
		listener: ln,
		signal:   signal,
		log:      log.Derive("Local", sock.Addr()),
	}

	go local.serve()
	return nil
}
Exemplo n.º 10
0
func (r *Recovery) Init(env zerver.Env) error {
	defval.Int(&r.Bufsize, 1024*4)
	r.log = log.Derive("Filter", "Recovery")
	return nil
}
Exemplo n.º 11
0
func (l *Log) Init(env zerver.Env) error {
	l.log = log.Derive("Filter", "Log")
	return nil
}