Documentation ¶
Overview ¶
Package sgul defines common structures and functionalities for applications. config.go defines commons for application configuration.
Package sgul defines common structures and functionalities for applications. controller.go defines commons for a base api controller.
Package sgul defines common structures and functionalities for applications. log.go defines commons for application logging.
Package sgul defines common structures and functionalities for applications. repository.go defines commons for a Gorm based Repository structure.
Package sgul defines common structures and functionalities for applications. stringify.go converts a struct to its string representation.
Index ¶
- Variables
- func ContainsString(s []string, elem string) bool
- func Get(key string) interface{}
- func GetLogger() *zap.Logger
- func GetLoggerByConf(conf Log) *zap.Logger
- func IsSet(key string) bool
- func JWTAuthorizer(roles []string) func(next http.Handler) http.Handler
- func JWTRouteAuthorizer(roles []string) func(next http.HandlerFunc) http.HandlerFunc
- func LoadConfiguration(configStruct interface{})
- func MaskedStringify(strct interface{}, mask []string) string
- func NewHTTPError(err error, status int, detail interface{}, requestID string) error
- func Pager() func(next http.Handler) http.Handler
- func RenderError(w http.ResponseWriter, err error)
- func RoutePager(next http.HandlerFunc) http.HandlerFunc
- func Stringify(strct interface{}) string
- type AMQP
- type AMQPConnection
- type AMQPPublisher
- type AMQPSubscriber
- type API
- type ChiController
- type ClientError
- type Configuration
- type Controller
- type DB
- type Event
- type GormRepository
- type HTTPError
- type InTransaction
- type Ldap
- type Log
- type Management
- type Page
- type Principal
- type Service
Constants ¶
This section is empty.
Variables ¶
var ErrPagerNotInContext = errors.New("Pager info not in Context")
ErrPagerNotInContext is returned if there is no Pager in the request context.
var ErrPrincipalNotInContext = errors.New("No Principal in request context")
ErrPrincipalNotInContext is returned if there is no Principal in the request context.
Functions ¶
func ContainsString ¶
ContainsString checks if a slice of strings contains a string.
func Get ¶
func Get(key string) interface{}
Get returns a configuration map by key. Used for custom or gear configurations.
func IsSet ¶
IsSet checks to see if the key has been set in any of the data locations. IsSet is case-insensitive for a key.
func JWTAuthorizer ¶
JWTAuthorizer is the JWT authentication middleware to use on mux (a. e. Chi router or Groups).
func JWTRouteAuthorizer ¶
func JWTRouteAuthorizer(roles []string) func(next http.HandlerFunc) http.HandlerFunc
JWTRouteAuthorizer is the JWT authentication middleware to use on single route (a.e. Chi router get, post, ...).
func LoadConfiguration ¶
func LoadConfiguration(configStruct interface{})
LoadConfiguration reads the configuration file according to the ENV var and return unmarshalled struct.
func MaskedStringify ¶
MaskedStringify converts a struct to its string representation obfuscating values for the key passed in mask slice.
func NewHTTPError ¶
NewHTTPError returns a new HTTPError instance
func RenderError ¶
func RenderError(w http.ResponseWriter, err error)
RenderError exported to be used in this lib (a.e. in middlewares) returns error to the client.
func RoutePager ¶
func RoutePager(next http.HandlerFunc) http.HandlerFunc
RoutePager is the query paging middleware to be used on routes.
Types ¶
type AMQP ¶
type AMQP struct { User string Password string Host string Port int VHost string Exchange string Queue string }
AMQP configuration
type AMQPConnection ¶
type AMQPConnection struct { URI string Connection *amqp.Connection Channel *amqp.Channel }
AMQPConnection .
func NewAMQPConnection ¶
func NewAMQPConnection() *AMQPConnection
NewAMQPConnection return a new disconnected AMQP Connection structure.
func (*AMQPConnection) Close ¶
func (conn *AMQPConnection) Close()
Close closes AMQP channel and connection.
func (*AMQPConnection) Connect ¶
func (conn *AMQPConnection) Connect() error
Connect open an AMQP connection and setup the channel.
type AMQPPublisher ¶
type AMQPPublisher struct { Connection *AMQPConnection Exchange string ExchangeType string RoutingKey string }
AMQPPublisher define the AMQP Publisher structure.
func NewAMQPPublisher ¶
func NewAMQPPublisher(connection *AMQPConnection, exchange string, exchangeType string, routingKey string) (*AMQPPublisher, error)
NewAMQPPublisher return a new AMQP Publisher object.
func (*AMQPPublisher) Publish ¶
func (pub *AMQPPublisher) Publish(event Event) error
Publish send a message to the AMQP Exchange.
type AMQPSubscriber ¶
type AMQPSubscriber struct { }
AMQPSubscriber define the AMQP Subscriber structure.
type API ¶
type API struct { Endpoint struct { Port int BaseRoutingPath string } Security struct { Enabled bool Jwt struct { Secret string Expiration struct { Enabled bool Minutes int32 } } } }
API is the structure for the Http API server and app configuration.
type ChiController ¶
ChiController defines the interface for an API Controller with Chi Router
type ClientError ¶
type ClientError interface { Error() string // ResponseBody returns response body. ResponseBody() ([]byte, error) // ResponseHeaders returns http status code and headers. ResponseHeaders() (int, map[string]string) }
ClientError is an error whose details to be shared with client.
type Configuration ¶
type Configuration struct { Service Service API API DB DB Management Management Log Log Ldap Ldap AMQP AMQP }
Configuration describe the type for the configuration file
func GetConfiguration ¶
func GetConfiguration() *Configuration
GetConfiguration returns the Configuration structure singleton instance.
type Controller ¶
type Controller struct { // Path is the base routing path for each route of the controller Path string }
Controller defines the base API Controller structure
func NewController ¶
func NewController(path string) Controller
NewController return a new instance of Controller (useful in composition for api controllers).
func (*Controller) RenderError ¶
func (c *Controller) RenderError(w http.ResponseWriter, err error)
RenderError returns error to the client.
type DB ¶
type DB struct { Type string Host string Port int User string Password string Database string Log bool Migrations struct { Enabled bool Drop bool SingularTableNames bool } }
DB is the structure for the main database configuration.
type Event ¶
type Event struct { // Name is the global identifier for event. It MUST be // composed as "<action>_<resource>", a.e. "new_user", "upd_user", "del_user", ... Name string // Source is the global identifier for the client which push // the evt message. A.E. "uaa-servce", "acct-service", ... Source string // Payload is the struct containing all the event message information. // The AMQP Publisher will marshal it to json and the AMQP Subscriber // will unmarshal it into a specific request (something like a dto). Payload interface{} }
Event is the struct used to push event messages into AMQP queues.
type GormRepository ¶
GormRepository defines the base repository structure form gorm based db access
func NewRepository ¶
func NewRepository(db *gorm.DB) GormRepository
NewRepository returns a new Repository instance
func (GormRepository) DoInTransaction ¶
func (r GormRepository) DoInTransaction(fn InTransaction) error
DoInTransaction executes the fn() callback in a gorm transaction.
type HTTPError ¶
type HTTPError struct { Code int `json:"code"` Err string `json:"error"` Detail interface{} `json:"detail"` RequestID string `json:"requestId"` Timestamp time.Time `json:"timestamp"` }
HTTPError implements ClientError interface.
func (*HTTPError) ResponseBody ¶
ResponseBody returns JSON response body.
type InTransaction ¶
InTransaction defines the func type to be executed in a gorm transaction.
type Ldap ¶
type Ldap struct { Base string Host string Port int UseSSL bool Bind struct { DN string Password string } UserFilter string GroupFilter string Attributes []string }
Ldap configuration
type Log ¶
type Log struct { Path string Filename string Console bool Level string JSON bool MaxSize int MaxBackups int MaxAge int Compress bool Caller bool }
Log is the structure for the logger configuration. If not present, the Machinery will use a default logger provided by the "gm-log" package.
type Management ¶
type Management struct { Endpoint struct { Port int BaseRoutingPath string } Health struct { Path string Full bool } }
Management is the structure for the management http endpoint configuration.