本书未发布

3.2. Server对象

未匹配的标注

net/http Server

Server

Server对象定义:

type Server struct {
    Addr    string  // TCP address to listen on, ":http" if empty
    Handler Handler // handler to invoke, http.DefaultServeMux if nil
    TLSConfig *tls.Config

    ReadTimeout time.Duration
    ReadHeaderTimeout time.Duration // Go 1.8
    WriteTimeout time.Duration
    IdleTimeout time.Duration // Go 1.8
    MaxHeaderBytes int

    TLSNextProto map[string]func(*Server, *tls.Conn, Handler) // Go 1.1
    ConnState func(net.Conn, ConnState) // Go 1.3
    ErrorLog *log.Logger // Go 1.3
    BaseContext func(net.Listener) context.Context // Go 1.13
    ConnContext func(ctx context.Context, c net.Conn) context.Context // Go 1.13
}
属性 类型 版本 解释
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

反馈和交流请加群组:QQ群373278915

本文章首发在 LearnKu.com 网站上。

上一篇 下一篇
讨论数量: 0
发起讨论 只看当前版本


暂无话题~