Help us shape the future of Go! Take the 2026 Go Developer Survey

accepter

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2019 License: BSD-3-Clause Imports: 6 Imported by: 0

README

accepter

GoDoc

Package accepter provides an Accepter and utilities for net.Listener. It seems like GoLang's http.Server.

Documentation

Overview

Package accepter provides an Accepter and utilities for net.Listener.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Accepter

type Accepter struct {
	// Handler to invoke.
	Handler Handler

	// TLSConfig optionally provides a TLS configuration.
	TLSConfig *tls.Config

	// ErrorLog specifies an optional logger for errors in Handler.
	ErrorLog *log.Logger
	// contains filtered or unexported fields
}

An Accepter defines parameters to accept connections. It seems like GoLang's http.Server.

func (*Accepter) Close

func (a *Accepter) Close() (err error)

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) Serve

func (a *Accepter) Serve(l net.Listener) (err error)

Serve accepts incoming connections on the Listener l, creating a new service goroutine for each. The service goroutines read requests and then call a.Handler to reply to them. Serve returns a nil error after Close or Shutdown method called.

func (*Accepter) ServeTLS

func (a *Accepter) ServeTLS(l net.Listener, certFile, keyFile string) (err error)

ServeTLS accepts incoming connections on the Listener l, creating a new service goroutine for each. The service goroutines read requests and then call a.Handler to reply to them. 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

func (a *Accepter) Shutdown(ctx context.Context) (err error)

Shutdown gracefully shuts down the Accepter without interrupting any connections. Shutdown works by first closing the Accepter's underlying Listener, then fills closeCh 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, TCPListenAndServe, and TCPListenAndServeTLS immediately return nil. Make sure the program doesn't exit and waits instead for Shutdown to return.

func (*Accepter) TCPListenAndServe

func (a *Accepter) TCPListenAndServe(addr string) error

TCPListenAndServe listens on the TCP network address addr and then calls Serve to handle requests on incoming connections. TCPListenAndServe returns a nil error after Close or Shutdown method called.

func (*Accepter) TCPListenAndServeTLS

func (a *Accepter) TCPListenAndServeTLS(addr string, certFile, keyFile string) error

TCPListenAndServeTLS listens on the TCP network address addr and then calls Serve to handle requests on 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.

type Handler

type Handler interface {
	Serve(conn net.Conn, closeCh <-chan struct{})
}

A Handler responds to an incoming connection.

type HandlerFunc

type HandlerFunc func(conn net.Conn, closeCh <-chan struct{})

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.

func (HandlerFunc) Serve

func (f HandlerFunc) Serve(conn net.Conn, closeCh <-chan struct{})

Serve calls f(conn, closeCh)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL