mises

package module
v0.0.0-...-c015335 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2020 License: BSD-3-Clause Imports: 12 Imported by: 0

README

Mises

Golang helper library for http microservices. Uses mux (router) & pop for database connections.

Status

License Unit test Coverage Issues
License Build Status codecov GitHub issues

Structure

package description comments
mises/ common service code
mises/cmd cobra bindings
mises/config global config
mises/runtime version info

ToDo

  • Base:
    • JWT middleware
    • Test setup (database cleaning?)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDatabaseConnection

func CreateDatabaseConnection(env string) (*pop.Connection, error)

CreateDatabaseConnection returns a pop connection

Types

type Logger

type Logger struct {
	*logrus.Logger
	Debug bool
	Color bool
}

Logger wraps a logrus logger & pop logger

func NewLogger

func NewLogger() *Logger

NewLogger returns a configured logger

type Server

type Server struct {
	IP       string
	Port     int
	Router   *mux.Router
	Config   config.Config
	Database *pop.Connection
	Logger   *Logger
}

Server holds all configuration or an http server

func NewServer

func NewServer(conf config.Config) Server

NewServer returns a default configured http server

func (*Server) AddRoutes

func (s *Server) AddRoutes(serviceName string, apiPrefix string, createServiceRoutes func(*mux.Router))

AddRoutes maps all common http endpoints & then calls the service routes function.

func (*Server) Decode

func (s *Server) Decode(w http.ResponseWriter, r *http.Request, data interface{}) error

Decode the json body from an http request

func (*Server) HandleCatchAll

func (s *Server) HandleCatchAll() http.HandlerFunc

HandleCatchAll handles all none specified routes. This needs to be added as the last route in setup of the individual service.

func (*Server) LoggingMiddleware

func (s *Server) LoggingMiddleware() func(h http.Handler) http.Handler

LoggingMiddleware logs every incoming request

func (*Server) Respond

func (s *Server) Respond(w http.ResponseWriter, r *http.Request, data interface{}, status int)

Respond helper function for http/json responses

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP dispatches the handler registered in the matched route.

func (*Server) StartHTTPServer

func (s *Server) StartHTTPServer()

StartHTTPServer starts the server

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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