keel

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2021 License: MIT Imports: 20 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 (
	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

WithConfig option

func WithContext

func WithContext(ctx context.Context) Option

WithContext 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 WithShutdownTimeout

func WithShutdownTimeout(shutdownTimeout time.Duration) Option

WithShutdownTimeout 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 a 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, name, addr string, handler http.Handler, middlewares ...middleware.Middleware) *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) 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

type Unsubscriber added in v0.2.0

type Unsubscriber interface {
	Unsubscribe() error
}

Unsubscriber interface

type UnsubscriberWithContext added in v0.2.0

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

UnsubscriberWithContext interface

Directories

Path Synopsis
example module
jetbench Module
examples
net
utils

Jump to

Keyboard shortcuts

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