http

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server wraps up *HTTP.Server.

func NewServer

func NewServer(c *ServerConfig, logger *logger.Logger, preStartCallback func() error, router http.Handler) (*Server, error)

NewServer initialises a http server.

func (*Server) Addr

func (s *Server) Addr() string

Addr returns the server's network address.

func (*Server) GracefulShutdownHandler

func (s *Server) GracefulShutdownHandler() error

GracefulShutdownHandler is a function that runs before the HTTP server is gracefully shut down.

func (*Server) GracefulStop

func (s *Server) GracefulStop() error

GracefulStop stops the HTTP server gracefully. It stops the server from accepting new connections and blocks until all the pending requests are finished.

func (*Server) HTTPServer

func (s *Server) HTTPServer() *http.Server

HTTPServer returns the internal HTTP server instance.

func (*Server) IsHTTPS

func (s *Server) IsHTTPS() bool

IsHTTPS returns the flag indicating whether the server is HTTPS

func (*Server) PreStartCallback

func (s *Server) PreStartCallback() func() error

PreStartCallback is the callback function to trigger right before the server starts running.

func (*Server) Serve

func (s *Server) Serve() error

Serve accepts incoming connections on the listener lis, creating a new ServerTransport and service goroutine for each. The service goroutines read HTTP requests and then call the registered handlers to reply to them. Serve returns when lis.Accept fails with fatal errors. lis will be closed when this method returns. Serve will return a non-nil error unless Stop or GracefulStop is called.

func (*Server) TracerProviderShutdownHandler

func (s *Server) TracerProviderShutdownHandler() error

TracerProviderShutdownHandler is a function that shuts down the tracer's exporter/provider before the HTTP server is gracefully shut down.

func (*Server) Type

func (s *Server) Type() string

Type indicates if the server is HTTP or HTTPS server.

type ServerConfig

type ServerConfig struct {
	// Name of the server
	Name string

	// Address is the TCP address to listen on.
	Address string

	// GracefulShutdownHandler is a function that runs before the HTTP server is gracefully shut down.
	GracefulShutdownHandler func() error

	// KeepAlive indicates how the HTTP server should configure the connection's keep alive.
	KeepAlive struct {
		// EnforcementPolicy is used to set keepalive enforcement policy on the server-side. Server
		// will close connection with a client that violates this policy.
		EnforcementPolicy struct {
			// MinTime is the minimum amount of time a client should wait before sending a keepalive
			// ping. By default, it is 5 * time.Second.
			MinTime time.Duration

			// If true, server allows keepalive pings even when there are no active streams(RPCs). If
			// false, and client sends ping when there are no active streams, server will send GOAWAY
			// and close the connection. By default, it is false.
			PermitWithoutStream bool
		}

		// ServerParameters is used to set keepalive and max-age parameters on the server-side.
		ServerParameters struct {
			ReadTimeout       time.Duration
			ReadHeaderTimeout time.Duration
			WriteTimeout      time.Duration
			IdleTimeout       time.Duration
			MaxHeaderBytes    int
		}
	}

	// TracerProvider is the provider that uses the exporter to push traces to the collector.
	TracerProvider *tracer.Provider

	// TracerProviderShutdownHandler is a function that shuts down the tracer's exporter/provider before
	// the HTTP server is gracefully shut down.
	TracerProviderShutdownHandler func() error

	TLSConfig *tls.Config
}

ServerConfig indicates how a HTTP server should be initialised.

Directories

Path Synopsis
gin
errors
Package errors contains the error handler controller
Package errors contains the error handler controller

Jump to

Keyboard shortcuts

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