thundersnake

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

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

Go to latest
Published: Aug 22, 2018 License: BSD-3-Clause Imports: 11 Imported by: 0

README

pipeline status coverage report

ThunderSnake

ThunderSnake is an application framework designed to bootstrap a Golang application easily with all required tooling to make it work properly in a production environment.

Example

Basic bootstrap

Here is how to bootstrap your application

// Define appServer singleton
var appServer *thundersnake.AppServer

func main() {
	configFile := "/etc/myapp/myapp.yml"
	appServer = thundersnake.NewAppServer(AppName, configFile, onStart)
	if appServer != nil {
		// Appserver will be started
		// * Logging manager will start
		// * Configuration will be loaded
		// * AppServer hooks are launched
		// * onStart callback function is called
		appServer.Start()
	}
}

// When appServer is ready it will call this callback function
func onStart() error {
	appServer.Log.Info("Application started")
	// Do your main code here
	appServer.Log.Info("Application Ended")
}

Custom configuration

We provide an interface if you want to include custom configuration in application configuration file.

First define a configuration structure depending on thundersnake CustomConfig object and implement loadDefaults() function:

type myConfig struct {
	thundersnake.CustomConfig
	foo int `yaml:"foo"`
	bar string `yaml:"bar"`
}

func (c *myConfig) loadDefaults() {
	c.foo = 1
	c.bar = "test"
}

Then overwrite the CustomConfig function in your main app just after creating application server.

var GConfig myConfig

func main() {
	configFile := "/etc/myapp/myapp.yml"
	appServer = thundersnake.NewAppServer(AppName, configFile, onStart)
	appServer.Config.Custom = &GConfig
	if appServer != nil {
		appServer.Start()
	}
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AppServerName = "ThunderSnake"

AppServerName application server name

View Source
var AppServerVersion = "[unk]"

AppServerVersion application version (from git tag)

Functions

This section is empty.

Types

type AppServer

type AppServer struct {
	Log    *logging.Logger
	Config *Config

	HTTP *httpserver.HTTPServer
	// contains filtered or unexported fields
}

AppServer application server object

func NewAppServer

func NewAppServer(appName string, onConfigFlagInitCallback func(), onStartCallBack func() error) *AppServer

NewAppServer creates AppServer object if basic prerequisites are satisfied

func (*AppServer) Start

func (app *AppServer) Start() error

Start starts the AppServer It will load the configuration, enable AppServer utils & run the onStartCallback function

type Config

type Config struct {
	EnableSigHUPReload bool              `yaml:"enable-sighup-reload"`
	NodeName           string            `yaml:"node-name"`
	HTTP               httpserver.Config `yaml:"http"`
	Custom             CustomConfig      `yaml:"custom"`
	// contains filtered or unexported fields
}

Config AppServer configuration object

type CustomConfig

type CustomConfig interface {
	// contains filtered or unexported methods
}

CustomConfig interface permitting to plug a specific configuration object for end users apps

type LogManager

type LogManager struct {
	Log *logging.Logger
	// contains filtered or unexported fields
}

LogManager AppServer logging manager object

func NewLogManager

func NewLogManager(name string) *LogManager

NewLogManager initialize logger

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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