Documentation
¶
Overview ¶
Package config will have necessary configuration for the application
Index ¶
- Constants
- Variables
- func RegisterWebsocketEvents(namespace, event string, evtHandler interface{})
- func RegisterWebsocketOnConnect(namespace string, f func(socketio.Conn) error)
- func RegisterWebsocketOnDisconnect(namespace string, f func(socketio.Conn, string))
- func RegisterWebsocketOnError(namespace string, f func(socketio.Conn, error))
- func StartRPC()
- type AppContext
- type DbConfig
- type Logger
Constants ¶
const ( //DbHost is the environment variable storing the database access url DbHost = "DB_HOST" //DbPort is the environment variable storing the database access port DbPort = "DB_PORT" //DbDatabaseName is the environment variable storing the database name DbDatabaseName = "DB_DATABASE_NAME" //DbUsername is the environment variable storing the database username DbUsername = "DB_USERNAME" //DbPassword is the environment variable storing the database password DbPassword = "DB_PASSWORD" //EnabledDB is the environment variable stating whether the db is enabled or not EnabledDB = "ENABLE_DB" )
const (
//Namespace is websockets namespace
Namespace = "/"
)
Variables ¶
var ( //Port in which the application is being served Port = "8078" //IntPort is the port converted into integer IntPort = 8078 //RPCPort in which the application's rpc server is being served RPCPort = "8079" //RPCIntPort is the rpc port converted into integer RPCIntPort = 8079 //RequestRTimeout of the api request body read timeout in milliseconds RequestRTimeout = time.Duration(2000 * time.Millisecond) //ResponseWTimeout of the api response write timeout in milliseconds ResponseWTimeout = time.Duration(10000 * time.Millisecond) //IdleRequestTimeout is the timeout after which unauthenticated requests must be disconnected of the system IdleRequestTimeout = time.Duration(10000 * time.Millisecond) //MaxRequestLife is the max request life time :- ie 4 hours is the default value MaxRequestLife = time.Duration(14400000) //MaxRequests is the maximum no. of requests catered at a given point of time MaxRequests = 1000 //RequestCleanUpCheck is the time after which request cleanup check has to happen RequestCleanUpCheck = time.Duration(2 * time.Minute) //DiscoveryURL is the url of the discovery service DiscoveryURL = "127.0.0.1:8500" //DiscoveryToken is the token to communicate with discovery service DiscoveryToken = "" //ServiceDomain is the url on which the service will be available across the platform ServiceDomain = "127.0.0.1" )
var IsTest bool
IsTest indicates that the current runtime is for test
var ( //PRODUCTION is the switch to turn on and off the Production environment. //1: On, 0: Off PRODUCTION = 0 )
var SkipVault bool
SkipVault will skip the vault initialization if set true
var WebsocketsServerID = "Brain-Websockets-Server"
WebsocketsServerID is the service id to be used with the discovery service
var WebsocketsServerRPCID = "Brain-Websockets-Server-RPC"
WebsocketsServerRPCID is the rpc service id to be used with the discovery service
Functions ¶
func RegisterWebsocketEvents ¶
func RegisterWebsocketEvents(namespace, event string, evtHandler interface{})
RegisterWebsocketEvents will register websockets events to the websocket server instance
func RegisterWebsocketOnConnect ¶
RegisterWebsocketOnConnect will register the websocket on connect event callback
func RegisterWebsocketOnDisconnect ¶
RegisterWebsocketOnDisconnect will register the websocket on disconnect event callback
func RegisterWebsocketOnError ¶
RegisterWebsocketOnError will register the websocket on error event callback
Types ¶
type AppContext ¶
type AppContext struct {
//ID of the app context
ID int
//Db is the database connection
Db *gorm.DB
//Log for logging purposes
Log Logger
//Session is the session associated with the request
Session authConfig.Session
//WebSockets has the web sockets server instance
WebSockets *socketio.Server
}
AppContext contains the
func NewAppContext ¶
func NewAppContext(l Logger, id int) *AppContext
NewAppContext returns an initlized app context
func (*AppContext) ConnectToDB ¶
func (a *AppContext) ConnectToDB() error
ConnectToDB connects the database and updates the Db property of the context as new connection If any error happens in between , it will be returned and connection won't be set in the context
func (*AppContext) InitWebSockets ¶
func (a *AppContext) InitWebSockets() error
InitWebSockets will initiate the websockets server
type DbConfig ¶
type DbConfig struct {
//Host to be used to connect to the database
Host string
//Port with which the database can be accessed
Port string
//Database to connect
Database string
//Username to access the connection
Username string
//Password to access the connection
Password string
}
DbConfig is the database configuration to connect to it
func NewDbConfig ¶
func NewDbConfig() *DbConfig
NewDbConfig will read the db config from the os environment variables and set it in the config
type Logger ¶
type Logger interface {
//Info logs the informative logs
Info(l ...interface{})
//Debug logs for the debugging logs
Debug(l ...interface{})
//Warn logs the warning logs
Warn(l ...interface{})
//Error logs the error
Error(l ...interface{})
//Fatal logs the fatal issues
Fatal(l ...interface{})
//GetID returns the ID of the logger
GetID() int
}
Logger must be implemented by the logger utilities to be an app logger