Documentation
¶
Overview ¶
Package accepter provides an Accepter and utilities for net.Listener.
Index ¶
- Variables
- func SetMaxTempDelay(d time.Duration)
- type Accepter
- func (a *Accepter) Close() (err error)
- func (a *Accepter) ListenAndServe(network, address string) error
- func (a *Accepter) ListenAndServeTLS(network, address string, certFile, keyFile string) error
- func (a *Accepter) Serve(lis net.Listener) (err error)
- func (a *Accepter) ServeTLS(lis net.Listener, certFile, keyFile string) (err error)
- func (a *Accepter) Shutdown(ctx context.Context) (err error)
- type Handler
- type HandlerFunc
- type TLSError
Constants ¶
This section is empty.
Variables ¶
var ( // ErrAlreadyServed is returned when Serve or ServeTLS method has been already called ErrAlreadyServed = errors.New("the accepter has already served") )
Functions ¶
func SetMaxTempDelay ¶ added in v1.2.3
SetMaxTempDelay sets maximum temporary error wait duration as concurrent-safe. Zero or negative values mean to wait forever. By default, zero.
Types ¶
type Accepter ¶
type Accepter struct {
// Handler to invoke.
Handler Handler
// TLSConfig optionally provides a TLS configuration.
TLSConfig *tls.Config
// contains filtered or unexported fields
}
An Accepter defines parameters to accept connections. It is similar with GoLang's http.Server.
func (*Accepter) Close ¶
Close immediately closes the Accepter's underlying Listener and any connections. For a graceful shutdown, use Shutdown.
Close returns any error returned from closing the Accepter's underlying Listener.
func (*Accepter) ListenAndServe ¶ added in v1.2.3
ListenAndServe listens on the given network and address; and then calls Serve to handle incoming connections. ListenAndServe returns a nil error after Close or Shutdown method called.
func (*Accepter) ListenAndServeTLS ¶ added in v1.2.3
ListenAndServeTLS listens on the given network and address; and then calls ServeTLS to handle incoming TLS connections.
Filenames containing a certificate and matching private key for the Accepter must be provided if neither the Accepter's TLSConfig.Certificates nor TLSConfig.GetCertificate are populated. If the certificate is signed by a certificate authority, the certFile should be the concatenation of the Accepter's certificate, any intermediates, and the CA's certificate.
func (*Accepter) Serve ¶
Serve accepts incoming connections on the Listener lis, creating a new service goroutine for each. The service goroutines read requests and then call a.Handler to reply to them. Serve always closes lis if returned error is not ErrAlreadyServed. Serve returns a nil error after Close or Shutdown method called.
func (*Accepter) ServeTLS ¶
ServeTLS accepts incoming connections on the Listener lis, creating a new service goroutine for each. The service goroutines read requests and then call a.Handler to reply to them. ServeTLS always closes lis if returned error is not ErrAlreadyServed or as TLSError. ServeTLS returns a nil error after Close or Shutdown method called.
Additionally, files containing a certificate and matching private key for the Accepter must be provided if neither the Accepter's TLSConfig.Certificates nor TLSConfig.GetCertificate are populated. If the certificate is signed by a certificate authority, the certFile should be the concatenation of the Accepter's certificate, any intermediates, and the CA's certificate.
func (*Accepter) Shutdown ¶
Shutdown gracefully shuts down the Accepter without interrupting any connections. Shutdown works by first closing the Accepter's underlying Listener, then cancels the context on Serve method of Handler, and then waiting indefinitely for connections to exit Serve method of Handler and then close. If the provided context expires before the shutdown is complete, Shutdown returns the context's error, otherwise it returns any error returned from closing the Accepter's underlying Listener.
When Shutdown is called, Serve, ServeTLS, ListenAndServe, and ListenAndServeTLS immediately return nil. Make sure the program doesn't exit and waits instead for Shutdown to return.
type HandlerFunc ¶
The HandlerFunc type is an adapter to allow the use of ordinary functions as handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler that calls f.