microapp

package module
v1.1.11-sm-12 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2021 License: MIT Imports: 45 Imported by: 0

README

microapp

Simple microservice framework in go!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCorrelationIDFromRequest added in v1.0.0

func GetCorrelationIDFromRequest(r *http.Request) string

GetCorrelationIDFromRequest returns correlationId from request header

Types

type App

type App struct {
	Name   string
	Config *config.Config
	DB     *gorm.DB
	Router *mux.Router
	// contains filtered or unexported fields
}

App structure for tenant microservice

func New

func New(appName string, appConfigDefaults map[string]interface{}, appLog zerolog.Logger, appDB *gorm.DB, appEventDispatcher event.Dispatcher) *App

New creates a new microApp

func NewWithEnvValues added in v1.0.0

func NewWithEnvValues(appName string, appConfigDefaults map[string]interface{}) *App

NewWithEnvValues creates a new application with environment variable values for initializing database, event dispatcher and logger.

func (*App) DispatchEvent

func (app *App) DispatchEvent(token string, corelationID string, topic string, payload interface{})

DispatchEvent delegates to eventDispatcher.

func (*App) GetConnectionString added in v1.0.0

func (app *App) GetConnectionString() string

GetConnectionString gets database connection string

func (*App) Initialize

func (app *App) Initialize(routeSpecifiers []RouteSpecifier)

Initialize initializes properties of the app

func (*App) Logger

func (app *App) Logger(module string) *zerolog.Logger

Logger returns logger for specified module

func (*App) MigrateDB added in v0.0.48

func (app *App) MigrateDB()

MigrateDB Looks for migrations directory and runs the migrations scripts in that directory

func (*App) NewExecutionContext added in v1.0.0

func (app *App) NewExecutionContext(token *security.JwtToken, correlationID string, action string, isUOWReqd, isUOWReadonly bool) microappCtx.ExecutionContext

NewExecutionContext creates new exectuion context

func (*App) NewExecutionContextWithCustomToken added in v1.0.0

func (app *App) NewExecutionContextWithCustomToken(tenantID uuid.UUID, userID uuid.UUID, username string, correlationID string, action string, admin, isUOWReqd, isUOWReadonly bool) microappCtx.ExecutionContext

NewExecutionContextWithCustomToken creates new exectuion context with custom made token

func (*App) NewExecutionContextWithSystemToken added in v1.0.0

func (app *App) NewExecutionContextWithSystemToken(correlationID string, action string, admin, isUOWReqd, isUOWReadonly bool) microappCtx.ExecutionContext

NewExecutionContextWithSystemToken creates new exectuion context with sys default token

func (*App) NewUnitOfWork added in v0.0.2

func (app *App) NewUnitOfWork(readOnly bool, logger zerolog.Logger) *repository.UnitOfWork

NewUnitOfWork creates new UnitOfWork

func (*App) Start

func (app *App) Start()

Start http server and start listening to the requests

func (*App) StartSecure added in v0.0.109

func (app *App) StartSecure(tlsCert string, tlsKey string)

StartSecure starts https server and listens to the requests

func (*App) Stop

func (app *App) Stop()

Stop http server

type RouteSpecifier

type RouteSpecifier interface {
	RegisterRoutes(router *mux.Router)
}

RouteSpecifier should be implemented by the class that sets routes for the API endpoints

type TestApp added in v0.0.7

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

TestApp Provides convinience methods for test

func NewTestApp added in v0.0.7

func NewTestApp(appName string, controllerRouteProvider func(*App) []RouteSpecifier, dbInitializer func(db *gorm.DB), verbose, isSingularTable bool) *TestApp

NewTestApp returns new instance of TestApp

func (*TestApp) AddAssociations added in v0.0.104

func (testApp *TestApp) AddAssociations(entity interface{}, associationName string, associations ...interface{}) error

AddAssociations adds associations to the given entity

func (*TestApp) AssertEqualWithFieldsToCheck added in v0.0.101

func (testApp *TestApp) AssertEqualWithFieldsToCheck(t *testing.T, expected interface{}, actual interface{}, fieldsToChk []string, mapOfExpectedToActualField map[string]string)

AssertEqualWithFieldsToCheck asserts whether two objects are equal

func (*TestApp) AssertEqualWithFieldsToIgnore added in v0.0.101

func (testApp *TestApp) AssertEqualWithFieldsToIgnore(t *testing.T, expected interface{}, actual interface{}, fieldsToIgnore []string, mapOfExpectedToActualField map[string]string)

AssertEqualWithFieldsToIgnore asserts whether two objects are equal

func (*TestApp) AssertErrorResponse added in v0.0.98

func (testApp *TestApp) AssertErrorResponse(t *testing.T, response *httptest.ResponseRecorder, expectedErrorKey string, expectedErrorField string, expectedError string)

AssertErrorResponse checks if the http response contains expected errorKey, errorField and errorMessage

func (*TestApp) AssertXTotalCount added in v0.0.98

func (testApp *TestApp) AssertXTotalCount(t *testing.T, response *httptest.ResponseRecorder, expectedXTotalCount int)

AssertXTotalCount checks if the http response header contains expected x-total-count

func (*TestApp) CallAPI added in v0.0.107

func (testApp *TestApp) CallAPI(httpMethod string, apiURL string, token string, req interface{}) *httptest.ResponseRecorder

CallAPI invokes http API

func (*TestApp) Check added in v1.0.0

func (testApp *TestApp) Check(t *testing.T, name string, expected, actual interface{}, failNow bool)

Check checks whether the expected and actual value matches

func (*TestApp) CheckResponseCode added in v0.0.7

func (testApp *TestApp) CheckResponseCode(t *testing.T, expected, actual int)

CheckResponseCode checks if the http response is as expected

func (*TestApp) ExecuteRequest added in v0.0.7

func (testApp *TestApp) ExecuteRequest(req *http.Request) *httptest.ResponseRecorder

ExecuteRequest executes the http request

func (*TestApp) GetAdminToken added in v0.0.8

func (testApp *TestApp) GetAdminToken(tenantID string, userID string, scope []string) string

GetAdminToken returns a test token

func (*TestApp) GetAll added in v0.0.107

func (testApp *TestApp) GetAll(out interface{}, preloads []string, whereClause string, whereParams []interface{}, orderBy string) error

GetAll gets all from DB

func (*TestApp) GetByID added in v0.0.89

func (testApp *TestApp) GetByID(out interface{}, preloads []string, id string) error

GetByID gets entity by ids

func (*TestApp) GetFullAdminToken added in v0.0.46

func (testApp *TestApp) GetFullAdminToken(tenantID string, userID string, username string, name string, externalID string, externalIDType string, scope []string) string

GetFullAdminToken returns a test token with all the fields along with different external IDs for types such as Appliance, Session, User. These external IDs are used with REST api is invoked from another REST API service as opposed to the getting hit from UI by the user.

func (*TestApp) GetFullToken added in v0.0.45

func (testApp *TestApp) GetFullToken(tenantID string, userID string, username string, name string, externalID string, externalIDType string, scope []string) string

GetFullToken returns a test token with all the fields along with different external IDs for types such as Appliance, Session, User. These external IDs are used with REST api is invoked from another REST API service as opposed to the getting hit from UI by the user.

func (*TestApp) GetStandardAdminToken added in v1.0.0

func (testApp *TestApp) GetStandardAdminToken(tenantID string, userID string, username string, name string, scope []string) string

GetStandardAdminToken returns a test admin token with all standard fields.

func (*TestApp) GetStandardToken added in v1.0.0

func (testApp *TestApp) GetStandardToken(tenantID string, userID string, username string, name string, scope []string) string

GetStandardToken returns a test token with all standard fields

func (*TestApp) GetToken added in v0.0.7

func (testApp *TestApp) GetToken(tenantID string, userID string, scope []string) string

GetToken gets a token to connect to API

func (*TestApp) Initialize added in v0.0.7

func (testApp *TestApp) Initialize()

Initialize prepares the app for testing

func (*TestApp) PrepareEmptyTables added in v0.0.7

func (testApp *TestApp) PrepareEmptyTables()

PrepareEmptyTables clears all table of data

func (*TestApp) SaveToDB added in v0.0.89

func (testApp *TestApp) SaveToDB(entity interface{}) error

SaveToDB saves the entity to database

func (*TestApp) SetControllerRouteProviderAndInitialize added in v0.0.88

func (testApp *TestApp) SetControllerRouteProviderAndInitialize(controllerRouteProvider func(*App) []RouteSpecifier)

SetControllerRouteProviderAndInitialize sets the controllerRouteProvider and initializes application

func (*TestApp) Stop added in v0.0.7

func (testApp *TestApp) Stop()

Stop the app

Jump to

Keyboard shortcuts

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