Exemple #1
0
func (this *Server) Start() error {
	logger.Debug("serverConfig is %#v", this.config)
	this.router.matcher.sort()
	conf := this.config
	server := &http.Server{Handler: http.HandlerFunc(this.serverHttpHandler), MaxHeaderBytes: conf.MaxHeaderBytes, TLSConfig: conf.TLSConfig}
	if conf.ReadTimeout > 0 {
		server.ReadTimeout = conf.ReadTimeout
	}
	if conf.WriteTimeout > 0 {
		server.WriteTimeout = conf.WriteTimeout
	}
	http2.ConfigureServer(server, &http2.Server{})
	var err error
	this.listener, err = net.Listen("tcp", conf.serverAddr)
	if err != nil {
		return errors.New(logger.Error("listen [%s] fail:%s", conf.serverAddr, err))
	}
	logger.Info("start HttpServer :%s", conf.serverAddr)
	keepAliveListrener := tcpKeepAliveListener{this.listener.(*net.TCPListener)}
	if conf.TLSConfig != nil {
		conf.TLSConfig.NextProtos = append(conf.TLSConfig.NextProtos, "http/1.1")
		go server.Serve(tls.NewListener(keepAliveListrener, conf.TLSConfig))
	} else {
		go server.Serve(keepAliveListrener)
	}
	return nil
}
Exemple #2
0
func AccessLogFilter(request *http.Request, reply *Reply, chain FilterChain) {
	t1 := time.Now()
	chain(request, reply)
	delay := time.Since(t1)
	logger.Info("%s\t%s\t%s\t%s\t%d", t1, delay, request.RemoteAddr, request.URL, reply.GetStatusCode())
}