keel

package module
v0.1.16 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2021 License: MIT Imports: 20 Imported by: 30

README

keel

Go Report Card godoc GitHub Super-Linter

Opinionated way to run services.

Stack

  • Metrics: Prometheus
  • Logging: Zap
  • Telemetry: Open Telemetry
  • Configuration: Viper

Example

package main

import (
	"net/http"
	"os"

	"github.com/foomo/keel"
	"github.com/foomo/keel/log"
)

func main() {
	svr := keel.NewServer()

	l := svr.Logger()

	// add zap service listening on localhost:9100
	// allows you to view / change the log level: GET / PUT localhost:9100/log
	svr.AddServices(keel.NewDefaultServiceHTTPZap())

	// add viper service listening on localhost:9300
	// allows you to view / change the configuration: GET / PUT localhost:9300/config
	svr.AddServices(keel.NewDefaultServiceHTTPViper())

	// add prometheus service listening on 0.0.0.0:9200
	// allows you to collect prometheus metrics: GET 0.0.0.0:9200/metrics
	svr.AddServices(keel.NewDefaultServiceHTTPPrometheus())

	svr.AddService(
		keel.NewServiceHTTP(log.WithServiceName(l, "demo"), ":8080", newService()),
	)

	svr.Run()
}

func newService() *http.ServeMux {
	s := http.NewServeMux()
	s.HandleFunc("/panic", func(w http.ResponseWriter, r *http.Request) {
		panic("exiting")
	})
	s.HandleFunc("/exit", func(w http.ResponseWriter, r *http.Request) {
		os.Exit(1)
	})
	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 (
	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 (
	// 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

This section is empty.

Types

type Closer

type Closer interface {
	Close() error
}

Closer interface

type CloserWithContext

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

CloserWithContext interface

type Option

type Option func(inst *Server)

Option func

func WithConfig

func WithConfig(c *viper.Viper) Option

func WithContext

func WithContext(ctx context.Context) Option

func WithLogFields

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

func WithLogger

func WithLogger(l *zap.Logger) Option

func WithShutdownTimeout

func WithShutdownTimeout(shutdownTimeout time.Duration) Option

type Server

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

Server struct

func NewServer

func NewServer(opts ...Option) *Server

func (*Server) AddCloser

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

AddCloser adds an closer to be called on shutdown

func (*Server) AddClosers

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

AddClosers adds an closer to be called on shutdown

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) 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) Logger

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

Logger returns server logger

func (*Server) Run

func (s *Server) Run()

Run runs the server

type Service

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

Service interface

type ServiceHTTP

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

ServiceHTTP struct

func NewDefaultServiceHTTPPrometheus

func NewDefaultServiceHTTPPrometheus() *ServiceHTTP

func NewDefaultServiceHTTPViper

func NewDefaultServiceHTTPViper() *ServiceHTTP

func NewDefaultServiceHTTPZap

func NewDefaultServiceHTTPZap() *ServiceHTTP

func NewServiceHTTP

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

func NewServiceHTTPPrometheus

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

func NewServiceHTTPViper

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

func NewServiceHTTPZap

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

func (*ServiceHTTP) Close

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

func (*ServiceHTTP) Start

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

type Shutdowner

type Shutdowner interface {
	Shutdown() error
}

Shutdowner interface

type ShutdownerWithContext

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

ShutdownerWithContext interface

Directories

Path Synopsis
example module
jetbench Module
net
utils

Jump to

Keyboard shortcuts

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