miabase

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: MIT Imports: 18 Imported by: 0

README

Miabase

Test and Build Go Report Card

Simplify building Mia-Platform custom plugins in Go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadEnv

func LoadEnv(c []configlib.EnvConfig, env interface{})

Types

type Plugin

type Plugin struct {
	Path string
	// contains filtered or unexported fields
}

func NewPlugin

func NewPlugin(path string) *Plugin

NewPlugin create a new plugin that groups a set of routes under it

func (*Plugin) AddRoute

func (p *Plugin) AddRoute(method, path string, handler http.HandlerFunc)

AddRoute add a new endpoint to the plugin associated with the logic that should be executed when the route is called

func (*Plugin) Inject added in v0.2.2

func (p *Plugin) Inject(w http.ResponseWriter, r *http.Request)

Inject allow to test plugin routes by injecting the request and recording the response

type Service

type Service struct {

	// Logger a zerolog instance that can be employed to log service details within plugins
	Logger *zerolog.Logger
	// contains filtered or unexported fields
}

Service is the main structure that contains all the service details, the methods to attach custom plugins and the ones to start it

func NewService

func NewService(opts ServiceOpts) *Service

NewService instantiate a Service which can be employed to connect custom plugin and start listening on defined endpoints

func (*Service) Inject added in v0.2.1

func (s *Service) Inject(w http.ResponseWriter, r *http.Request)

Inject allows to test an endpoint by passing a request and response recorder

func (*Service) Register

func (s *Service) Register(plugin *Plugin)

Register include the new plugin into the set of plugins that the service must load.

func (*Service) Start

func (s *Service) Start(httpPort int)

Start launch the configured service, mounting customized plugin and starting the webserver

func (*Service) Stop

func (s *Service) Stop()

Stop terminates service webserver execution

type ServiceOpts added in v0.2.0

type ServiceOpts struct {
	// Name represents the designation emplyoyed to indentify the service's deploy
	Name string
	// Version is a semver string that represents the current version of deployed service
	Version string
	// LogLevel is a string indicating the minimum log level that is shown on the standard out
	LogLevel string
	// StatusManager is an interface providing the three status routes handlers
	StatusManager status.Status
	// MetricsManager is an interface providing a method to register custom metrics in the service registry
	MetricsManager metrics.Metrics
}

ServiceOpts defines which options are needed to customize a Service initialization

Directories

Path Synopsis
examples
pkg

Jump to

Keyboard shortcuts

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