server

package module
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: Apache-2.0 Imports: 16 Imported by: 1

README

go-kit/server

Go Reference GitHub Release GoCard GitHub license

Пакет для сборки сервиса, запускающего воркеры и, если нужен, HTTP-сервер.

Использование

Использование пакета добавляет в сервис следующие опции:

Server Options:
      --srv.listen=              Addr and port which server listens at (default: :8080) [$SRV_LISTEN]
      --srv.maxheader=           MaxHeaderBytes
      --srv.rto=                 HTTP read timeout (default: 10s)
      --srv.wto=                 HTTP write timeout (default: 60s)
      --srv.grace=               Stop grace period (default: 10s)
      --srv.ip_header=           HTTP Request Header for remote IP (default: X-Real-IP) [$SRV_IP_HEADER]
      --srv.user_header=         HTTP Request Header for username (default: X-Username) [$SRV_USER_HEADER]

HTTPS Options:
      --srv.tls.cert=            CertFile for serving HTTPS instead HTTP [$SRV_TLS_CERT]
      --srv.tls.key=             KeyFile for serving HTTPS instead HTTP [$SRV_TLS_KEY]
      --srv.tls.no-check         disable tls certificate validation

Version response Options:
      --srv.vr.prefix=           URL for version response (default: /js/version.js)
      --srv.vr.format=           Format string for version response (default: "document.addEventListener('DOMContentLoaded', () => { appVersion.innerText = '%s'; });\n")
      --srv.vr.ctype=            js code Content-Type header (default: text/javascript)

Help Options:
  -h, --help                     Show this help message


Documentation

Index

Constants

View Source
const AccessLogDisabled = "-"

AccessLogDisabled holds access_log value for access logging disabling.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Listen string `long:"listen" default:":8080" description:"Addr and port which server listens at" env:"LISTEN"`

	MaxHeaderBytes    int           `long:"maxheader" description:"MaxHeaderBytes"`
	ReadTimeout       time.Duration `long:"rto" default:"10s" description:"HTTP read timeout"`
	WriteTimeout      time.Duration `long:"wto" default:"60s" description:"HTTP write timeout, '0' means disable"`
	ReadHeaderTimeout time.Duration `long:"rhto" default:"10s" description:"HTTP read header timeout"`
	IdleTimeout       time.Duration `long:"ito" default:"10s" description:"HTTP idle timeout"`
	GracePeriod       time.Duration `long:"grace" default:"10s" description:"Stop grace period"`

	IPHeader   string `long:"ip_header" env:"IP_HEADER" default:"X-Real-IP" description:"HTTP Request Header for remote IP"`
	UserHeader string `long:"user_header" env:"USER_HEADER" default:"X-Username" description:"HTTP Request Header for username"`
	AccessLog  string `long:"access_log" env:"ACCESS_LOG" description:"HTTP access log filename (default: STDOUT, '-' means disable)"`
	UseETag    bool   `long:"etag" env:"ETAG" description:"Add ETAG in HTTP response"`

	TLS     TLSConfig             `group:"HTTPS Options"            namespace:"tls"  env-namespace:"TLS"`
	Version VersionResponseConfig `group:"Version response Options" namespace:"vr"`
}

Config holds all config vars.

type Handler

type Handler func(http.Handler) http.Handler

Handler is a http midleware handler.

type Service

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

Service holds service attributes.

func New

func New(cfg Config) *Service

New returns *Service.

func (*Service) Run

func (srv *Service) Run(ctx context.Context, workers ...Worker) error

Run runs HTTP(s) service and workers. HTTP Workers will be registered if none.

func (*Service) RunWorkers added in v0.15.0

func (srv *Service) RunWorkers(ctx context.Context, workers ...Worker) error

RunWorkers runs workers without HTTP service.

func (Service) ServeMux

func (srv Service) ServeMux() *http.ServeMux

ServeMux returns service muxer.

func (Service) ServeMuxWithHandlers added in v0.16.0

func (srv Service) ServeMuxWithHandlers() http.Handler

ServeMuxWithHandlers return mux joined with defined by Use handlers.

func (*Service) Use

func (srv *Service) Use(handler Handler) *Service

Use adds handler for muxer.

func (*Service) WithHTTPWorkers added in v0.16.0

func (srv *Service) WithHTTPWorkers() *Service

WithHTTPWorkers registers HTTP workers.

func (*Service) WithListener

func (srv *Service) WithListener(listener net.Listener) *Service

WithListener sets service listener.

func (*Service) WithNWorkers added in v0.16.0

func (srv *Service) WithNWorkers(n int, worker Worker) *Service

WithNWorkers registers N copies of worker.

func (*Service) WithShutdown

func (srv *Service) WithShutdown(worker Worker) *Service

WithShutdown registers worker for call on shutdown.

func (*Service) WithStatic

func (srv *Service) WithStatic(fSystem fs.FS) *Service

WithStatic sets static filesystem for serve via http.

func (*Service) WithVersion

func (srv *Service) WithVersion(version string) *Service

WithVersion sets hanler returning source code version as js.

func (*Service) WithWorkers added in v0.16.0

func (srv *Service) WithWorkers(workers ...Worker) *Service

WithWorkers registers workers.

type TLSConfig added in v0.13.0

type TLSConfig struct {
	CertFile           string `long:"cert" description:"CertFile for serving HTTPS instead HTTP" env:"CERT"`
	KeyFile            string `long:"key"  description:"KeyFile for serving HTTPS instead HTTP" env:"KEY"`
	NoCheckCertificate bool   `long:"no-check" description:"disable tls certificate validation"`
}

TLSConfig holds TLS config options.

type VersionResponseConfig added in v0.13.0

type VersionResponseConfig struct {
	Prefix string `long:"prefix" default:"/js/version.js" description:"URL for version response"`
	Format string `` /* 161-byte string literal not displayed */
	CType  string `long:"ctype"  default:"text/javascript" description:"js code Content-Type header"`
}

VersionResponseConfig holds settings for HTTP version response.

type Worker

type Worker func(ctx context.Context) error

Worker is a server goroutene worker.

Jump to

Keyboard shortcuts

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