governor

package module
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2020 License: MPL-2.0 Imports: 25 Imported by: 0

README

governor

yet another microservice framework

import via xorkevin.dev/governor

Motivation

Governor is an opinionated framework for building microservices.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorStatus

func ErrorStatus(target error) int

ErrorStatus reports the error status of the top most governor error in the chain

func NewError

func NewError(message string, status int, err error) error

NewError creates a new governor Error

func NewErrorUser

func NewErrorUser(message string, status int, err error) error

NewErrorUser creates a new governor User Error

Types

type Config

type Config struct {
	Appname       string
	Version       string
	VersionHash   string
	LogLevel      int
	LogOutput     io.Writer
	Port          string
	BaseURL       string
	PublicDir     string
	MaxReqSize    string
	FrontendProxy []string
	Origins       []string
	RouteRewrite  map[string]string
	// contains filtered or unexported fields
}

Config is the complete server configuration including the dynamic (runtime) options

func (*Config) IsDebug

func (c *Config) IsDebug() bool

IsDebug returns if the configuration is in debug mode

type ConfigOpts

type ConfigOpts struct {
	DefaultFile string
	Appname     string
	Description string
	Version     string
	VersionHash string
	EnvPrefix   string
}

ConfigOpts is the server base configuration

type ConfigReader

type ConfigReader interface {
	Name() string
	URL() string
	GetStrMap(key string) map[string]string
	GetBool(key string) bool
	GetInt(key string) int
	GetStr(key string) string
	GetStrSlice(key string) []string
}

ConfigReader gets values from the config parser

type ConfigRegistrar

type ConfigRegistrar interface {
	SetDefault(key string, value interface{})
}

ConfigRegistrar sets default values on the config parser

type JobRegistrar

type JobRegistrar interface {
}

type Logger

type Logger interface {
	Debug(msg string, data map[string]string)
	Info(msg string, data map[string]string)
	Warn(msg string, data map[string]string)
	Error(msg string, data map[string]string)
	Fatal(msg string, data map[string]string)
	Subtree(module string) Logger
	WithData(data map[string]string) Logger
}

Logger is a governor logging interface that may write logs to a configurable io.Writer

type ReqSetup

type ReqSetup struct {
	Username  string `json:"username"`
	Password  string `json:"password"`
	Email     string `json:"email"`
	Firstname string `json:"first_name"`
	Lastname  string `json:"last_name"`
	Orgname   string `json:"orgname"`
}

ReqSetup is the option struct that is passed to all services during setup

type Server

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

Server is a governor server to which services may be registered

func New

func New(conf ConfigOpts, stateService state.State) *Server

New creates a new Server

func (*Server) Execute

func (s *Server) Execute()

Execute runs the governor cmd

func (*Server) Register

func (s *Server) Register(name string, url string, r Service)

Register adds the service to the governor Server and runs service.Register

func (*Server) Setup

func (s *Server) Setup(req ReqSetup) error

Setup runs the setup procedures for all services

func (*Server) Start

func (s *Server) Start() error

Start starts the registered services and the server

type Service

type Service interface {
	Register(r ConfigRegistrar, jr JobRegistrar)
	Init(ctx context.Context, c Config, r ConfigReader, l Logger, g *echo.Group) error
	Setup(req ReqSetup) error
	Start(ctx context.Context) error
	Stop(ctx context.Context)
	Health() error
}

Service is an interface for governor services

A governor service may be in one of 5 stages in its lifecycle.

1. Register: register the service on the config

2. Init: initialize any connections necessary for the service to function

3. Setup: sets up the service for the first time such as creating database tables and mounting routes

4. Start: start the service

5. Stop: stop the service

Register and Init always occur first when a governor application is launched. Then Setup and Start may occur in either order, or not at all. Stop runs when the server begins the shutdown process

Jump to

Keyboard shortcuts

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