justgo

package module
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2019 License: Apache-2.0 Imports: 25 Imported by: 0

README

justgo

Simple Api Provider

usage:
custom config file

as default, justgo scan app folder for application.yml for config. use this command to override where to get the config file

justgo.Config.ConfigFile("./sample/anything.yml")
in code config
justgo.Config.Add("APP_NAME", "My Volatile Config")
http

http interface is enabled by default. if you only want to use http server only, simply add route and start justgo

justgo.AddRoute(http.MethodGet, "/with-middleware", headerPrinterHandler, middleWareDummyOne, otherAuthHandler)
justgo.AddRoute(http.MethodGet, "/no-middleware", headerPrinterHandler)
justgo.Start()
connecting to Database
// this is required for sql package to have registered database driver.
// corresponding driver will register it self to available driver in sql package
import _ "github.com/lib/pq"

// enable database
justgo.Config.Add("DB_DRIVER", "postgres")
justgo.Config.Add("DB_CONNECTION_STRING", "dbname=postgres user=postgres password=abcdef host=localhost sslmode=disable")

// get the db instance and inject it in your repository
// or you can simply call it anywhere in the app
// the db instance won't be initialized until justgo.Initialize() or justgo.Start()
db := &justgo.Storage.DB
Cli

adding another interface in same app

// add cli handler via telnet
cliInterface := &justgo.CliInterface{Address: ":12345"}

// add command on telnet command
cliInterface.AddCommand("test", echo)
cliInterface.AddCommand("panic", panicCommand)
cliInterface.AddCommand("fatal", fatalCommand)

// register interface
justgo.RegisterInterface(cliInterface)

justgo.Start()
Features:
  • app interface
    • http
    • telnet
    • kafka
  • metric
    • newrelic
    • custom hooks
    • StatsD integration
    • sentry reporting
  • database
  • i18n
  • api client with hystrix

Documentation

Overview

Package justgo is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var Config *config
View Source
var ConfigKey configKey
View Source
var DEFAULT_CONFIGS = map[string]string{}

Functions

func AddRoute

func AddRoute(method string, pattern string, handler http.HandlerFunc, middlewares ...func(http.Handler) http.Handler)

func AlwaysUseMiddleware

func AlwaysUseMiddleware(middleWares ...func(handler http.Handler) http.Handler)

func GetInstrument added in v1.4.2

func GetInstrument() *instrument

func GetLogger added in v1.4.4

func GetLogger() *justGoLog

func GetRouter added in v1.1.1

func GetRouter() http.Handler

func Initialise added in v1.1.1

func Initialise()

func InstantiateNewRouter

func InstantiateNewRouter()

func NewSentryHook added in v1.2.0

func NewSentryHook(dsn string, level []logrus.Level) (*sentryHook, error)

func RegisterInterface

func RegisterInterface(appInterface AppInterface)

func RunAppInterfaces added in v1.3.0

func RunAppInterfaces()

func Start

func Start()

func WaitForShutdown added in v1.3.0

func WaitForShutdown()

Types

type AppInterface added in v1.3.0

type AppInterface interface {
	Serve()
	ShutDown()
}

type CliCommand added in v1.3.0

type CliCommand func(string) string

type CliInterface added in v1.3.0

type CliInterface struct {
	Address string
	// contains filtered or unexported fields
}

func (*CliInterface) AddCommand added in v1.3.0

func (cli *CliInterface) AddCommand(command string, function CliCommand)

func (*CliInterface) Serve added in v1.3.0

func (cli *CliInterface) Serve()

func (*CliInterface) ShutDown added in v1.3.0

func (cli *CliInterface) ShutDown()

type DB added in v1.4.1

type DB struct {
	*sqlx.DB
}

func GetDB added in v1.4.0

func GetDB() *DB

type HttpInterface

type HttpInterface struct {
	Handler http.Handler
	// contains filtered or unexported fields
}

func GetDefaultHttpInterface added in v1.3.0

func GetDefaultHttpInterface() *HttpInterface

func (HttpInterface) Serve

func (httpInterface HttpInterface) Serve()

func (HttpInterface) ShutDown added in v1.3.0

func (httpInterface HttpInterface) ShutDown()

type Metric

type Metric interface {
	Increment(key string)
}

type MockAppInterface added in v1.4.2

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

MockAppInterface is a mock of AppInterface interface

func NewMockAppInterface added in v1.4.2

func NewMockAppInterface(ctrl *gomock.Controller) *MockAppInterface

NewMockAppInterface creates a new mock instance

func (*MockAppInterface) EXPECT added in v1.4.2

EXPECT returns an object that allows the caller to indicate expected use

func (*MockAppInterface) Serve added in v1.4.2

func (m *MockAppInterface) Serve()

Serve mocks base method

func (*MockAppInterface) ShutDown added in v1.4.2

func (m *MockAppInterface) ShutDown()

ShutDown mocks base method

type MockAppInterfaceMockRecorder added in v1.4.2

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

MockAppInterfaceMockRecorder is the mock recorder for MockAppInterface

func (*MockAppInterfaceMockRecorder) Serve added in v1.4.2

Serve indicates an expected call of Serve

func (*MockAppInterfaceMockRecorder) ShutDown added in v1.4.2

func (mr *MockAppInterfaceMockRecorder) ShutDown() *gomock.Call

ShutDown indicates an expected call of ShutDown

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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