Documentation
¶
Index ¶
- Constants
- type Action
- type ActionError
- type ActionResponse
- func NewServerErrorResponse(ctx context.Context, identifier ErrorIdentifier, err error) ActionResponse
- func NewSuccessCreationResponse(response any) ActionResponse
- func NewSuccessResponse(response any) ActionResponse
- func NewUnprocessableEntityResponse(ctx context.Context, err error) ActionResponse
- func NewValidationErrorResponse(ctx context.Context, errors []ValidationError) ActionResponse
- type ActionRunner
- type Application
- type CloseApplicationListener
- type CommonError
- type Config
- func (c *Config) AppEnv() string
- func (c *Config) AppEnvIsProd() bool
- func (c *Config) GetEnv(key string) string
- func (c *Config) GetEnvAsBool(name string) bool
- func (c *Config) GetEnvAsInt(name string) int
- func (c *Config) GetEnvAsSlice(name string, sep string) []string
- func (c *Config) ProvidedServices() []interface{}
- type ConfigInitializer
- type ContainerHolder
- type DefaultJsonResponseWriter
- type DefaultLogger
- func (d *DefaultLogger) Debug(ctx context.Context, s string, i ...interface{})
- func (d *DefaultLogger) Error(ctx context.Context, s string, i ...interface{})
- func (d *DefaultLogger) Info(ctx context.Context, s string, i ...interface{})
- func (d *DefaultLogger) Panic(ctx context.Context, s string, i ...interface{})
- func (d *DefaultLogger) Warn(ctx context.Context, s string, i ...interface{})
- type DefaultValidator
- type ErrorIdentifier
- type HttpRoutesInitializer
- type JsonResponseWriter
- type Logger
- type RouteInfo
- type Router
- type Routes
- func (r *Routes) AddFromRoutes(routes *Routes)
- func (r *Routes) Delete(path string, handler http.HandlerFunc)
- func (r *Routes) Get(path string, handler http.HandlerFunc)
- func (r *Routes) GetRoutesInfo() []RouteInfo
- func (r *Routes) Options(path string, handler http.HandlerFunc)
- func (r *Routes) Post(path string, handler http.HandlerFunc)
- func (r *Routes) Put(path string, handler http.HandlerFunc)
- type ServiceProvider
- type StartApplicationListener
- type StructValidator
- type ValidatableStruct
- type ValidationError
- type VarValidator
Constants ¶
const ( TestEnv = "test" DevEnv = "dev" ProdEnv = "prod" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActionError ¶ added in v0.0.3
type ActionError struct { Ctx context.Context Identifier ErrorIdentifier Err error ValidationErrors []ValidationError }
func (*ActionError) Error ¶ added in v0.0.3
func (e *ActionError) Error() string
type ActionResponse ¶ added in v0.0.3
type ActionResponse struct { StatusCode int Response any Error *ActionError IsLoggingErrors bool }
func NewServerErrorResponse ¶ added in v0.0.4
func NewServerErrorResponse(ctx context.Context, identifier ErrorIdentifier, err error) ActionResponse
func NewSuccessCreationResponse ¶ added in v0.0.3
func NewSuccessCreationResponse(response any) ActionResponse
func NewSuccessResponse ¶ added in v0.0.3
func NewSuccessResponse(response any) ActionResponse
func NewUnprocessableEntityResponse ¶ added in v0.0.4
func NewUnprocessableEntityResponse(ctx context.Context, err error) ActionResponse
func NewValidationErrorResponse ¶ added in v0.0.4
func NewValidationErrorResponse(ctx context.Context, errors []ValidationError) ActionResponse
type ActionRunner ¶
type ActionRunner struct {
// contains filtered or unexported fields
}
func NewActionRunner ¶
func NewActionRunner(logger Logger, jsonWriter JsonResponseWriter, router Router) *ActionRunner
func (*ActionRunner) Run ¶
func (j *ActionRunner) Run( w http.ResponseWriter, r *http.Request, action func(ctx context.Context, request any) ActionResponse, request any, )
type Application ¶
type Application struct {
// contains filtered or unexported fields
}
func New ¶
func New(moduleConfigs []interface{}) *Application
func (*Application) Container ¶
func (a *Application) Container() *dig.Container
func (*Application) Run ¶
func (a *Application) Run() error
type CloseApplicationListener ¶
type CloseApplicationListener interface { // OnClose may close some resources of a module, for example a db connection OnClose() error }
CloseApplicationListener if service provider implements this method it will be called after stopping the application
type CommonError ¶ added in v0.0.4
type CommonError struct { Identifier ErrorIdentifier Err string }
func NewCommonError ¶ added in v0.0.4
func NewCommonError(identifier ErrorIdentifier, err string) *CommonError
func (*CommonError) Error ¶ added in v0.0.4
func (e *CommonError) Error() string
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
func (*Config) AppEnvIsProd ¶
func (*Config) GetEnvAsBool ¶
func (*Config) GetEnvAsInt ¶
func (*Config) ProvidedServices ¶
func (c *Config) ProvidedServices() []interface{}
type ConfigInitializer ¶
type ConfigInitializer interface { // InitConfig is called for each module to initialize module's variables InitConfig(config Config) error }
ConfigInitializer if service provider implements this method it will be called after providing dependencies of the module
type ContainerHolder ¶
type ContainerHolder interface { // SetContainer receives the dependency injection container from application SetContainer(*dig.Container) }
ContainerHolder allows module config to have a link to the dependency injection container
type DefaultJsonResponseWriter ¶ added in v0.0.3
type DefaultJsonResponseWriter struct {
// contains filtered or unexported fields
}
func (*DefaultJsonResponseWriter) Error ¶ added in v0.0.3
func (j *DefaultJsonResponseWriter) Error(w http.ResponseWriter, r *http.Request, response ActionResponse)
func (*DefaultJsonResponseWriter) Success ¶ added in v0.0.3
func (j *DefaultJsonResponseWriter) Success(w http.ResponseWriter, r *http.Request, response ActionResponse)
type DefaultLogger ¶
type DefaultLogger struct { }
func (*DefaultLogger) Debug ¶
func (d *DefaultLogger) Debug(ctx context.Context, s string, i ...interface{})
func (*DefaultLogger) Error ¶
func (d *DefaultLogger) Error(ctx context.Context, s string, i ...interface{})
func (*DefaultLogger) Info ¶
func (d *DefaultLogger) Info(ctx context.Context, s string, i ...interface{})
type DefaultValidator ¶
type DefaultValidator struct {
// contains filtered or unexported fields
}
func (*DefaultValidator) ValidateStruct ¶ added in v0.0.5
func (v *DefaultValidator) ValidateStruct(obj any) []ValidationError
func (*DefaultValidator) ValidateVar ¶ added in v0.0.5
func (v *DefaultValidator) ValidateVar(variable any, rule string) *ValidationError
type ErrorIdentifier ¶ added in v0.0.4
type ErrorIdentifier string
const InvalidRequest ErrorIdentifier = "InvalidRequest"
const UnknownError ErrorIdentifier = "UnknownError"
const UnprocessableEntity ErrorIdentifier = "UnprocessableEntity"
const WrongRequestDecoding ErrorIdentifier = "WrongRequestDecoding"
type HttpRoutesInitializer ¶
type HttpRoutesInitializer interface { // HttpRoutesInitializer Returns a set of http routes processed by the module ModuleRoutes() []RouteInfo }
HttpRoutesInitializer if service provider implements this method it will be called after initializing the configuration and its result will be added to the http routes listened by the application router
type JsonResponseWriter ¶
type JsonResponseWriter interface { Success(w http.ResponseWriter, r *http.Request, response ActionResponse) Error(w http.ResponseWriter, r *http.Request, response ActionResponse) }
func NewJsonResponseWriter ¶ added in v0.0.3
func NewJsonResponseWriter(logger Logger, config *Config) JsonResponseWriter
type Logger ¶
type Logger interface { Debug(ctx context.Context, s string, i ...interface{}) Info(ctx context.Context, s string, i ...interface{}) Warn(ctx context.Context, s string, i ...interface{}) Error(ctx context.Context, s string, i ...interface{}) Panic(ctx context.Context, s string, i ...interface{}) }
func NewDefaultLogger ¶
func NewDefaultLogger() Logger
type RouteInfo ¶
type RouteInfo struct {
// contains filtered or unexported fields
}
func NewRouteInfo ¶
func NewRouteInfo(method string, path string, handler http.HandlerFunc) *RouteInfo
func (RouteInfo) Handler ¶
func (r RouteInfo) Handler() http.HandlerFunc
type Routes ¶
type Routes struct {
// contains filtered or unexported fields
}
func (*Routes) AddFromRoutes ¶
func (*Routes) GetRoutesInfo ¶
type ServiceProvider ¶
type ServiceProvider interface { // ProvidedServices returns a list of constructors that presents all services of the module. // All of them will be placed in the dependency injection container ProvidedServices() []interface{} }
ServiceProvider describes all services of a module in the dependency injection container it is the first step of the application running
type StartApplicationListener ¶
type StartApplicationListener interface { // OnStart Starts module's application such as a web-server OnStart() error }
StartApplicationListener if service provider implements this method it will be called after initializing the routes
type StructValidator ¶ added in v0.0.5
type StructValidator interface {
ValidateStruct(obj any) []ValidationError
}
func NewDefaultValidator ¶
func NewDefaultValidator(logger Logger) StructValidator
type ValidatableStruct ¶ added in v0.0.5
type ValidatableStruct interface {
Validate(ctx context.Context) []ValidationError
}
type ValidationError ¶ added in v0.0.3
type ValidationError struct { Field string Identifier ErrorIdentifier Err string }
func NewValidationError ¶ added in v0.0.3
func NewValidationError(field string, err string, identifier ErrorIdentifier) *ValidationError
func (ValidationError) Error ¶ added in v0.0.3
func (e ValidationError) Error() string
type VarValidator ¶ added in v0.0.5
type VarValidator interface {
ValidateVar(variable any, rule string) *ValidationError
}