nethttp server

net/http Server

Server

Server对象定义:

type Server struct {
    Addr    string  
    Handler Handler 
    TLSConfig *tls.Config

    ReadTimeout time.Duration
    ReadHeaderTimeout time.Duration 
    WriteTimeout time.Duration
    IdleTimeout time.Duration 
    MaxHeaderBytes int

    TLSNextProto map[string]func(*Server, *tls.Conn, Handler) 
    ConnState func(net.Conn, ConnState) 
    ErrorLog *log.Logger 
    BaseContext func(net.Listener) context.Context 
    ConnContext func(ctx context.Context, c net.Conn) context.Context 
}

属性

类型

版本

解释

Addr

string

监听端口的地址

Handler

Handler

Server请求的处理对象

TLSConfig

*tls.Config

监听端口的tls配置

ReadTimeout

time.Duration

ReadHeaderTimeout

time.Duration

1.8

WriteTimeout

time.Duration

IdleTimeout

time.Duration

1.8

MaxHeaderBytes

int

TLSNextProto

map[string]func(*Server, *tls.Conn, Handler)

1.1

ConnState

func(net.Conn, ConnState)

1.3

ErrorLog

*log.Logger

1.3

BaseContext

func(net.Listener) context.Context

1.13

ConnContext

func(ctx context.Context, c net.Conn) context.Context

1.13

Server Method

    func (srv *Server) Serve(l net.Listener) error
    func (srv *Server) SetKeepAlivesEnabled(v bool)
    func (srv *Server) RegisterOnShutdown(f func())
    func (srv *Server) Shutdown(ctx context.Context) error
    func (srv *Server) Close() error

    func (srv *Server) ListenAndServe() error
    func (srv *Server) ListenAndServeTLS(certFile, keyFile string) error
    func (srv *Server) ServeTLS(l net.Listener, certFile, keyFile string) error

Handler

Last updated

Was this helpful?