server

package
v1.7.14 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package servers provides implementation of Go API for managing server flow

Package server provides implementation of Go API for managing server flow

Index

Constants

This section is empty.

Variables

View Source
var (
	HealthServerOpts = func(name, host, path string, port uint16) []Option {
		return []Option{
			WithName(name),
			WithErrorGroup(errgroup.Get()),
			WithHTTPHandler(func() http.Handler {
				mux := http.NewServeMux()
				mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
					if r.Method == http.MethodGet {
						w.Header().Set(rest.ContentType, rest.TextPlain+";"+rest.CharsetUTF8)
						w.WriteHeader(http.StatusOK)
						_, err := fmt.Fprint(w, http.StatusText(http.StatusOK))
						if err != nil {
							log.Error(err, info.Get())
						}
					}
				})
				return mux
			}()),
			WithHost(host),
			WithIdleTimeout("3s"),
			WithNetwork(net.TCP.String()),
			WithPort(port),
			WithProbeWaitTime("2s"),
			WithReadHeaderTimeout("3s"),
			WithReadTimeout("2s"),
			WithServerMode(REST),
			WithShutdownDuration("4s"),
			WithWriteTimeout("3s"),
		}
	}
)

Functions

This section is empty.

Types

type Option

type Option func(*server) error

func WithDisableRestart

func WithDisableRestart() Option

func WithEnableRestart

func WithEnableRestart() Option

func WithErrorGroup

func WithErrorGroup(eg errgroup.Group) Option

func WithGRPCConnectionTimeout

func WithGRPCConnectionTimeout(to string) Option

func WithGRPCHeaderTableSize

func WithGRPCHeaderTableSize(size uint32) Option

func WithGRPCInitialConnWindowSize

func WithGRPCInitialConnWindowSize(size int) Option

func WithGRPCInitialWindowSize

func WithGRPCInitialWindowSize(size int) Option

func WithGRPCInterceptors

func WithGRPCInterceptors(names ...string) Option

func WithGRPCKeepaliveMaxConnAge

func WithGRPCKeepaliveMaxConnAge(max string) Option

func WithGRPCKeepaliveMaxConnAgeGrace

func WithGRPCKeepaliveMaxConnAgeGrace(max string) Option

func WithGRPCKeepaliveMaxConnIdle

func WithGRPCKeepaliveMaxConnIdle(max string) Option

func WithGRPCKeepaliveMinTime added in v1.3.1

func WithGRPCKeepaliveMinTime(min string) Option

func WithGRPCKeepalivePermitWithoutStream added in v1.3.1

func WithGRPCKeepalivePermitWithoutStream(pws bool) Option

func WithGRPCKeepaliveTime

func WithGRPCKeepaliveTime(dur string) Option

func WithGRPCKeepaliveTimeout

func WithGRPCKeepaliveTimeout(dur string) Option

func WithGRPCMaxConcurrentStreams added in v1.7.14

func WithGRPCMaxConcurrentStreams(size uint32) Option

func WithGRPCMaxHeaderListSize

func WithGRPCMaxHeaderListSize(size uint32) Option

func WithGRPCMaxReceiveMessageSize

func WithGRPCMaxReceiveMessageSize(size int) Option

func WithGRPCMaxSendMessageSize

func WithGRPCMaxSendMessageSize(size int) Option

func WithGRPCNumStreamWorkers added in v1.7.14

func WithGRPCNumStreamWorkers(size uint32) Option

func WithGRPCOption

func WithGRPCOption(opts ...grpc.ServerOption) Option

func WithGRPCReadBufferSize

func WithGRPCReadBufferSize(size int) Option

func WithGRPCRegistFunc

func WithGRPCRegistFunc(f func(*grpc.Server)) Option

func WithGRPCServer

func WithGRPCServer(srv *grpc.Server) Option

func WithGRPCSharedWriteBuffer added in v1.7.14

func WithGRPCSharedWriteBuffer(enable bool) Option

func WithGRPCWaitForHandlers added in v1.7.14

func WithGRPCWaitForHandlers(wait bool) Option

func WithGRPCWriteBufferSize

func WithGRPCWriteBufferSize(size int) Option

func WithHTTP2Enabled added in v1.7.14

func WithHTTP2Enabled(enabled bool) Option

func WithHTTPHandler

func WithHTTPHandler(h http.Handler) Option

func WithHTTPServer

func WithHTTPServer(srv *http.Server) Option

func WithHandlerLimit added in v1.7.14

func WithHandlerLimit(size int) Option

func WithHost

func WithHost(host string) Option

func WithIdleTimeout

func WithIdleTimeout(dur string) Option

func WithListenConfig

func WithListenConfig(lc *net.ListenConfig) Option

func WithMaxConcurrentStreams added in v1.7.14

func WithMaxConcurrentStreams(size uint32) Option

func WithMaxDecoderHeaderTableSize added in v1.7.14

func WithMaxDecoderHeaderTableSize(size uint32) Option

func WithMaxEncoderHeaderTableSize added in v1.7.14

func WithMaxEncoderHeaderTableSize(size uint32) Option

func WithMaxReadFrameSize added in v1.7.14

func WithMaxReadFrameSize(size uint32) Option

func WithMaxUploadBufferPerConnection added in v1.7.14

func WithMaxUploadBufferPerConnection(size int32) Option

func WithMaxUploadBufferPerStream added in v1.7.14

func WithMaxUploadBufferPerStream(size int32) Option

func WithName

func WithName(name string) Option

func WithNetwork added in v1.0.3

func WithNetwork(network string) Option

func WithPermitProhibitedCipherSuites added in v1.7.14

func WithPermitProhibitedCipherSuites(perm bool) Option

func WithPort

func WithPort(port uint16) Option

func WithPreStartFunc

func WithPreStartFunc(f func() error) Option

func WithPreStopFunction

func WithPreStopFunction(f func() error) Option

func WithProbeWaitTime

func WithProbeWaitTime(dur string) Option

func WithReadHeaderTimeout

func WithReadHeaderTimeout(dur string) Option

func WithReadTimeout

func WithReadTimeout(dur string) Option

func WithServerMode

func WithServerMode(m ServerMode) Option

func WithShutdownDuration

func WithShutdownDuration(dur string) Option

func WithSocketFlag added in v1.0.3

func WithSocketFlag(flg control.SocketFlag) Option

func WithSocketPath added in v1.0.3

func WithSocketPath(path string) Option

func WithTLSConfig

func WithTLSConfig(cfg *tls.Config) Option

func WithWriteTimeout

func WithWriteTimeout(dur string) Option

type Server

type Server interface {
	Name() string
	IsRunning() bool
	ListenAndServe(context.Context, chan<- error) error
	Shutdown(context.Context) error
}

func New

func New(opts ...Option) (Server, error)

New returns Server implementation. skipcq: GO-R1005

type ServerMode added in v0.0.44

type ServerMode uint8
const (
	REST ServerMode = 1 + iota
	GRPC
	GQL
)

func Mode

func Mode(m string) ServerMode

func (ServerMode) String added in v0.0.44

func (m ServerMode) String() string

Jump to

Keyboard shortcuts

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