server

package
v0.0.56 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2020 License: Apache-2.0 Imports: 19 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 uint) []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"),
			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)

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 int) Option

func WithGRPCInitialConnWindowSize

func WithGRPCInitialConnWindowSize(size int) Option

func WithGRPCInitialWindowSize

func WithGRPCInitialWindowSize(size int) Option

func WithGRPCInterceptors

func WithGRPCInterceptors(name ...string) Option

func WithGRPCKeepaliveMaxConnAge

func WithGRPCKeepaliveMaxConnAge(max string) Option

func WithGRPCKeepaliveMaxConnAgeGrace

func WithGRPCKeepaliveMaxConnAgeGrace(max string) Option

func WithGRPCKeepaliveMaxConnIdle

func WithGRPCKeepaliveMaxConnIdle(max string) Option

func WithGRPCKeepaliveTime

func WithGRPCKeepaliveTime(dur string) Option

func WithGRPCKeepaliveTimeout

func WithGRPCKeepaliveTimeout(dur string) Option

func WithGRPCMaxHeaderListSize

func WithGRPCMaxHeaderListSize(size int) Option

func WithGRPCMaxReceiveMessageSize

func WithGRPCMaxReceiveMessageSize(size int) Option

func WithGRPCMaxSendMessageSize

func WithGRPCMaxSendMessageSize(size int) 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 WithGRPCWriteBufferSize

func WithGRPCWriteBufferSize(size int) Option

func WithHTTPHandler

func WithHTTPHandler(h http.Handler) Option

func WithHTTPServer

func WithHTTPServer(srv *http.Server) Option

func WithHost

func WithHost(host string) Option

func WithIdleTimeout

func WithIdleTimeout(dur string) Option

func WithListenConfig

func WithListenConfig(lc *net.ListenConfig) Option

func WithName

func WithName(name string) Option

func WithPort

func WithPort(port uint) 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 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)

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