keel

package module
v0.10.21 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2022 License: MIT Imports: 30 Imported by: 30

README

keel

Go Report Card godoc GitHub Super-Linter

Opinionated way to run services.

Stack

  • Zap
  • Viper
  • Open Telemetry
  • Nats
  • GoTSRPC

Examples

See the examples folder for usages

package main

import (
  "net/http"

  "github.com/foomo/keel"
)

func main() {
  svr := keel.NewServer(
    keel.WithHTTPZapService(true),
    keel.WithHTTPViperService(true),
    keel.WithHTTPPrometheusService(true),
  )

  l := svr.Logger()

  svs := newService()

  svr.AddService(
    keel.NewServiceHTTP(l, "demo", ":8080", svs),
  )

  svr.Run()
}

func newService() *http.ServeMux {
  s := http.NewServeMux()
  s.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    w.WriteHeader(http.StatusOK)
    _, _ = w.Write([]byte("OK"))
  })
  return s
}

How to Contribute

Make a pull request...

License

Distributed under MIT License, please see license file within the code for more details.

Documentation

Index

Constants

View Source
const (
	DefaultServiceHTTPHealthzName = "healthz"
	DefaultServiceHTTPHealthzAddr = ":9400"
	DefaultServiceHTTPHealthzPath = "/healthz"
)
View Source
const (
	DefaultServiceHTTPPrometheusName = "prometheus"
	DefaultServiceHTTPPrometheusAddr = ":9200"
	DefaultServiceHTTPPrometheusPath = "/metrics"
)
View Source
const (
	DefaultServiceHTTPViperName = "viper"
	DefaultServiceHTTPViperAddr = "localhost:9300"
	DefaultServiceHTTPViperPath = "/config"
)
View Source
const (
	DefaultServiceHTTPZapName = "zap"
	DefaultServiceHTTPZapAddr = "localhost:9100"
	DefaultServiceHTTPZapPath = "/log"
)

Variables

View Source
var (
	ErrServerNotRunning  = errors.New("server not running")
	ErrServiceNotRunning = errors.New("service not running")
)
View Source
var (
	// Version usage -ldflags "-X github.com/foomo/keel/server.Version=$VERSION"
	Version string
	// GitCommit usage -ldflags "-X github.com/foomo/keel/server.GitCommit=$GIT_COMMIT"
	GitCommit string
	// BuildTime usage -ldflags "-X 'github.com/foomo/keel/server.BuildTime=$(date -u '+%Y-%m-%d %H:%M:%S')'"
	BuildTime string
)

Functions

func NewCloserFn added in v0.9.3

func NewCloserFn(handle func(context.Context) error) closer

func NewHealthzerFn added in v0.9.3

func NewHealthzerFn(handle func(context.Context) error) healther

Types

type BoolHealthzer added in v0.9.2

type BoolHealthzer interface {
	Healthz() bool
}

BoolHealthzer interface

type BoolHealthzerWithContext added in v0.9.2

type BoolHealthzerWithContext interface {
	Healthz(ctx context.Context) bool
}

BoolHealthzerWithContext interface

type Closer

type Closer interface {
	Close()
}

Closer interface

type CloserWithContext

type CloserWithContext interface {
	Close(ctx context.Context)
}

CloserWithContext interface

type ErrorCloser added in v0.2.10

type ErrorCloser interface {
	Close() error
}

ErrorCloser interface

type ErrorCloserWithContext added in v0.2.10

type ErrorCloserWithContext interface {
	Close(ctx context.Context) error
}

ErrorCloserWithContext interface

type ErrorHealthzWithContext added in v0.9.0

type ErrorHealthzWithContext interface {
	Healthz(ctx context.Context) error
}

ErrorHealthzWithContext interface

type ErrorHealthzer added in v0.9.2

type ErrorHealthzer interface {
	Healthz() error
}

ErrorHealthzer interface

type ErrorPinger added in v0.9.2

type ErrorPinger interface {
	Ping() error
}

ErrorPinger interface

type ErrorPingerWithContext added in v0.9.2

type ErrorPingerWithContext interface {
	Ping(context.Context) error
}

ErrorPingerWithContext interface

type ErrorShutdowner added in v0.2.10

type ErrorShutdowner interface {
	Shutdown() error
}

ErrorShutdowner interface

type ErrorShutdownerWithContext added in v0.2.10

type ErrorShutdownerWithContext interface {
	Shutdown(ctx context.Context) error
}

ErrorShutdownerWithContext interface

type ErrorStopper added in v0.9.11

type ErrorStopper interface {
	Stop() error
}

ErrorStopper interface

type ErrorStopperWithContext added in v0.9.11

type ErrorStopperWithContext interface {
	Stop(ctx context.Context) error
}

ErrorStopperWithContext interface

type ErrorUnsubscriber added in v0.2.10

type ErrorUnsubscriber interface {
	Unsubscribe() error
}

ErrorUnsubscriber interface

type ErrorUnsubscriberWithContext added in v0.2.10

type ErrorUnsubscriberWithContext interface {
	Unsubscribe(ctx context.Context) error
}

ErrorUnsubscriberWithContext interface

type HealthzType added in v0.9.2

type HealthzType string

HealthzType type https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/

const (
	// HealthzTypeAlways will run on any checks
	HealthzTypeAlways HealthzType = "always"
	// HealthzTypeStartup will run on /healthz/startup checks
	// > The kubelet uses startup probes to know when a container application has started. If such a probe is configured,
	// > it disables liveness and readiness checks until it succeeds, making sure those probes don't interfere with the
	// > application startup. This can be used to adopt liveness checks on slow starting containers, avoiding them getting
	// > killed by the kubelet before they are up and running.
	HealthzTypeStartup HealthzType = "startup"
	// HealthzTypeReadiness will run on /healthz/readiness checks
	// > The kubelet uses readiness probes to know when a container is ready to start accepting traffic.
	// > A Pod is considered ready when all of its containers are ready. One use of this signal is to control
	// > which Pods are used as backends for Services. When a Pod is not ready, it is removed from Service load balancers.
	HealthzTypeReadiness HealthzType = "readiness"
	// HealthzTypeLiveness  will run on /healthz/liveness checks
	// > The kubelet uses liveness probes to know when to restart a container. For example, liveness probes could catch
	// > a deadlock, where an application is running, but unable to make progress. Restarting a container in such a state
	// > can help to make the application more available despite bugs.
	HealthzTypeLiveness HealthzType = "liveness"
)

func (HealthzType) String added in v0.9.2

func (t HealthzType) String() string

String interface

type Option

type Option func(inst *Server)

Option func

func WithConfig

func WithConfig(c *viper.Viper) Option

WithConfig option

func WithContext

func WithContext(ctx context.Context) Option

WithContext option

func WithHTTPHealthzService added in v0.9.2

func WithHTTPHealthzService(enabled bool) Option

func WithHTTPPrometheusService added in v0.2.0

func WithHTTPPrometheusService(enabled bool) Option

WithHTTPPrometheusService option with default value

func WithHTTPViperService added in v0.2.0

func WithHTTPViperService(enabled bool) Option

WithHTTPViperService option with default value

func WithHTTPZapService added in v0.2.0

func WithHTTPZapService(enabled bool) Option

WithHTTPZapService option with default value

func WithLogFields

func WithLogFields(fields ...zap.Field) Option

WithLogFields option

func WithLogger

func WithLogger(l *zap.Logger) Option

WithLogger option

func WithOTLPGRPCTracer added in v0.8.0

func WithOTLPGRPCTracer(enabled bool) Option

WithOTLPGRPCTracer option with default value

func WithOTLPHTTPTracer added in v0.8.0

func WithOTLPHTTPTracer(enabled bool) Option

WithOTLPHTTPTracer option with default value

func WithPrometheusMeter added in v0.8.0

func WithPrometheusMeter(enabled bool) Option

WithPrometheusMeter option with default value

func WithRemoteConfig added in v0.10.0

func WithRemoteConfig(provider, endpoint, path string) Option

WithRemoteConfig option

func WithShutdownSignals added in v0.6.4

func WithShutdownSignals(shutdownSignals ...os.Signal) Option

WithShutdownSignals option

func WithShutdownTimeout

func WithShutdownTimeout(shutdownTimeout time.Duration) Option

WithShutdownTimeout option

func WithStdOutMeter added in v0.8.0

func WithStdOutMeter(enabled bool) Option

WithStdOutMeter option with default value

func WithStdOutTracer added in v0.8.0

func WithStdOutTracer(enabled bool) Option

WithStdOutTracer option with default value

type Server

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

Server struct

func NewServer

func NewServer(opts ...Option) *Server

func (*Server) AddAlwaysHealthzers added in v0.9.3

func (s *Server) AddAlwaysHealthzers(probes ...interface{})

AddAlwaysHealthzers adds the probes to be called on any healthz checks

func (*Server) AddCloser

func (s *Server) AddCloser(closer interface{})

AddCloser adds a closer to be called on shutdown

func (*Server) AddClosers

func (s *Server) AddClosers(closers ...interface{})

AddClosers adds the given closers to be called on shutdown

func (*Server) AddHealthzer added in v0.9.3

func (s *Server) AddHealthzer(typ HealthzType, probe interface{})

AddHealthzer adds a probe to be called on healthz checks

func (*Server) AddHealthzers added in v0.9.3

func (s *Server) AddHealthzers(typ HealthzType, probes ...interface{})

AddHealthzers adds the given probes to be called on healthz checks

func (*Server) AddLivenessHealthzers added in v0.9.3

func (s *Server) AddLivenessHealthzers(probes ...interface{})

AddLivenessHealthzers adds the liveness probes to be called on healthz checks

func (*Server) AddReadinessHealthzers added in v0.9.3

func (s *Server) AddReadinessHealthzers(probes ...interface{})

AddReadinessHealthzers adds the readiness probes to be called on healthz checks

func (*Server) AddService

func (s *Server) AddService(service Service)

AddService add a single service

func (*Server) AddServices

func (s *Server) AddServices(services ...Service)

AddServices adds multiple service

func (*Server) AddStartupHealthzers added in v0.9.3

func (s *Server) AddStartupHealthzers(probes ...interface{})

AddStartupHealthzers adds the startup probes to be called on healthz checks

func (*Server) CancelContext added in v0.9.4

func (s *Server) CancelContext() context.Context

CancelContext returns server's cancel context

func (*Server) Config

func (s *Server) Config() *viper.Viper

Config returns server config

func (*Server) Context

func (s *Server) Context() context.Context

Context returns server context

func (*Server) Healthz added in v0.9.1

func (s *Server) Healthz() error

Healthz returns true if the server is running

func (*Server) IsCanceled added in v0.9.1

func (s *Server) IsCanceled() bool

IsCanceled returns true if the internal errgroup has been canceled

func (*Server) Logger

func (s *Server) Logger() *zap.Logger

Logger returns server logger

func (*Server) Meter added in v0.8.0

func (s *Server) Meter() metric.Meter

Meter returns the implementation meter

func (*Server) Run

func (s *Server) Run()

Run runs the server

func (*Server) Tracer added in v0.8.0

func (s *Server) Tracer() trace.Tracer

Tracer returns the implementation tracer

type Service

type Service interface {
	Name() string
	Start(ctx context.Context) error
	Close(ctx context.Context) error
}

Service interface

type ServiceEnabler added in v0.10.12

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

func NewServiceEnabler added in v0.10.12

func NewServiceEnabler(l *zap.Logger, name string, serviceFn ServiceFunc, enabledFn func() bool) *ServiceEnabler

func (*ServiceEnabler) Close added in v0.10.12

func (w *ServiceEnabler) Close(ctx context.Context) error

func (*ServiceEnabler) Name added in v0.10.12

func (w *ServiceEnabler) Name() string

func (*ServiceEnabler) Start added in v0.10.12

func (w *ServiceEnabler) Start(ctx context.Context) error

type ServiceFunc added in v0.10.12

type ServiceFunc func() Service

type ServiceHTTP

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

ServiceHTTP struct

func NewDefaultServiceHTTPProbes added in v0.9.0

func NewDefaultServiceHTTPProbes(probes map[HealthzType][]interface{}) *ServiceHTTP

func NewDefaultServiceHTTPPrometheus

func NewDefaultServiceHTTPPrometheus() *ServiceHTTP

func NewDefaultServiceHTTPViper

func NewDefaultServiceHTTPViper() *ServiceHTTP

func NewDefaultServiceHTTPZap

func NewDefaultServiceHTTPZap() *ServiceHTTP

func NewServiceHTTP

func NewServiceHTTP(l *zap.Logger, name, addr string, handler http.Handler, middlewares ...middleware.Middleware) *ServiceHTTP

func NewServiceHTTPHealthz added in v0.9.2

func NewServiceHTTPHealthz(l *zap.Logger, name, addr, path string, probes map[HealthzType][]interface{}) *ServiceHTTP

func NewServiceHTTPPrometheus

func NewServiceHTTPPrometheus(l *zap.Logger, name, addr, path string) *ServiceHTTP

func NewServiceHTTPViper

func NewServiceHTTPViper(l *zap.Logger, c *viper.Viper, name, addr, path string) *ServiceHTTP

func NewServiceHTTPZap

func NewServiceHTTPZap(l *zap.Logger, name, addr, path string) *ServiceHTTP

func (*ServiceHTTP) Close

func (s *ServiceHTTP) Close(ctx context.Context) error

func (*ServiceHTTP) Healthz added in v0.9.1

func (s *ServiceHTTP) Healthz() error

func (*ServiceHTTP) Name added in v0.3.3

func (s *ServiceHTTP) Name() string

func (*ServiceHTTP) Start

func (s *ServiceHTTP) Start(ctx context.Context) error

type Shutdowner

type Shutdowner interface {
	Shutdown()
}

Shutdowner interface

type ShutdownerWithContext

type ShutdownerWithContext interface {
	Shutdown(ctx context.Context)
}

ShutdownerWithContext interface

type Stopper added in v0.9.11

type Stopper interface {
	Stop()
}

Stopper interface

type StopperWithContext added in v0.9.11

type StopperWithContext interface {
	Stop(ctx context.Context)
}

StopperWithContext interface

type Unsubscriber added in v0.2.0

type Unsubscriber interface {
	Unsubscribe()
}

Unsubscriber interface

type UnsubscriberWithContext added in v0.2.0

type UnsubscriberWithContext interface {
	Unsubscribe(ctx context.Context)
}

UnsubscriberWithContext interface

Jump to

Keyboard shortcuts

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