keel

package module
v0.17.3 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: MIT Imports: 32 Imported by: 30

README

keel

Build Status Go Report Card Coverage Status GoDoc

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"
  "github.com/foomo/keel/service"
)

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

  l := svr.Logger()

  svs := newService()

  svr.AddService(
    service.NewHTTP(l, "demo", "localhost: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

This section is empty.

Variables

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
)
View Source
var (
	ErrServerNotRunning = errors.New("server not running")
)

Functions

func IsCloser added in v0.17.0

func IsCloser(v any) bool

func IsHealthz added in v0.17.0

func IsHealthz(v any) bool

Types

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

WithHTTPHealthzService option with default value

func WithHTTPPProfService added in v0.16.0

func WithHTTPPProfService(enabled bool) Option

WithHTTPPProfService option with default value

func WithHTTPPrometheusService added in v0.2.0

func WithHTTPPrometheusService(enabled bool) Option

WithHTTPPrometheusService option with default value

func WithHTTPReadmeService added in v0.17.0

func WithHTTPReadmeService(enabled bool) Option

WithHTTPReadmeService 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 healthz.Type, 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 healthz.Type, 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) AddReadmer added in v0.17.0

func (s *Server) AddReadmer(readmer interfaces.Readmer)

AddReadmer adds a readmer to be added to the exposed readme

func (*Server) AddReadmers added in v0.17.0

func (s *Server) AddReadmers(readmers ...interfaces.Readmer)

AddReadmers adds readmers to be added to the exposed readme

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) Readme added in v0.17.0

func (s *Server) Readme() string

Readme returns the self-documenting string

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

Jump to

Keyboard shortcuts

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