Documentation ¶
Overview ¶
Package handles error logs via nats message broker
Index ¶
- Constants
- Variables
- func AccessCookieConfig() echo.MiddlewareFunc
- func BindAndValidate(c echo.Context, i interface{}) error
- func HTTPErrorHandler(err error, c echo.Context)
- func KeyAuthMiddleware() echo.MiddlewareFunc
- func MongoNoDeleted(err error) bool
- func MongoNoDocuments(err error) bool
- func MongoNoUpdated(err error) bool
- func RandomBase64(n int) (string, error)
- func RandomBytes(n int) ([]byte, error)
- func RefreshCookieConfig() echo.MiddlewareFunc
- func RefreshCookieUserID(c echo.Context) (string, error)
- func ResetAccessCookie() *http.Cookie
- func ResetRefreshCookie() *http.Cookie
- func SliceContains(list []string, element string) bool
- type AccessToken
- type AuthToken
- type CORSConfig
- type Callback
- type CookieConfig
- type ErrorResponse
- type HydraClient
- type IDjango
- type IDjangoError
- type LinkToken
- type LoadEnv
- func (l LoadEnv) GetEnvBool(key string, lvl string, dVal bool) bool
- func (l LoadEnv) GetEnvInt(key string, lvl string, dVal int) int
- func (l LoadEnv) GetEnvString(key string, lvl string, dVal string) string
- func (l LoadEnv) GetEnvStringList(key string, lvl string, dVal []string) []string
- func (l LoadEnv) Validate()
- type LogError
- type LoggingHandler
- type MailData
- type MailSend
- type Modified
- type ModifiedQuery
- type Money
- type MongoColl
- func (i *MongoColl) Aggregate(ctx context.Context, filter []bson.D, value interface{}) (err error)
- func (i *MongoColl) CreateIndex(field string, unique bool) *MongoColl
- func (i *MongoColl) CreateMultiIndex(filter bson.D, unique bool) *MongoColl
- func (i *MongoColl) DeleteMany(ctx context.Context, filter bson.M) (err error)
- func (i *MongoColl) DeleteOne(ctx context.Context, filter bson.M) (err error)
- func (i *MongoColl) Find(ctx context.Context, filter bson.M, value interface{}) (err error)
- func (i *MongoColl) FindOne(ctx context.Context, filter bson.M, value interface{}) (err error)
- func (i *MongoColl) InsertOne(ctx context.Context, value interface{}) (err error)
- func (i *MongoColl) InsertOrUpdate(ctx context.Context, filter bson.M, value interface{}) (err error)
- func (i *MongoColl) Permission(ctx context.Context, filter bson.M, value interface{}) (err error)
- func (i *MongoColl) UpdateOne(ctx context.Context, filter bson.M, value interface{}) (err error)
- type MongoDB
- type MongoError
- type MongoErrorResponse
- type MongoFilterM
- func (i *MongoFilterM) Equal(key string, value string)
- func (i *MongoFilterM) EqualIn64(key string, value string)
- func (i *MongoFilterM) EqualInt(key string, value string)
- func (i *MongoFilterM) GteInt(key string, value string)
- func (i *MongoFilterM) GteInt64(key string, value string)
- func (i *MongoFilterM) Like(key string, value string)
- func (i *MongoFilterM) LteInt(key string, value string)
- func (i *MongoFilterM) LteInt64(key string, value string)
- type MongoPipe
- type NatsDAO
- type RefreshToken
- type Response
- func (i *Response) BadRequest() (int, *Response)
- func (i *Response) Conflict() (int, *Response)
- func (i *Response) Created() (int, *Response)
- func (i *Response) Deleted() (int, *Response)
- func (i *Response) Executed() (int, *Response)
- func (i *Response) InternalServerError() (int, *Response)
- func (i *Response) NotFound() (int, *Response)
- func (i *Response) Selected() (int, *Response)
- func (i *Response) Updated() (int, *Response)
- type Role
- type RoleList
- type RoleListCookie
- type Status
- func (i *Status) Created(message string)
- func (i *Status) Done(message string)
- func (i *Status) Error() string
- func (i *Status) Failed(message string)
- func (i *Status) Internal(message string)
- func (i *Status) Open(message string)
- func (i *Status) Process(message string)
- func (i *Status) Response() (int, interface{})
- func (i *Status) Set(t string, message string) *Status
- func (i *Status) ValidateDone() error
- type User
- type UserClaims
- type ValidationError
- type Validator
Constants ¶
const StatusBADREQUEST = "bad_request"
const StatusCREATED = "created"
const StatusDONE = "done"
const StatusFAILED = "failed"
const StatusINTERNAL = "internal_error"
const StatusOPEN = "open"
const StatusPROCESS = "process"
Variables ¶
var APIKey = Config.GetEnvString("API_KEY", "w", "secret")
APIKey represents the api Bearer token
var CORS = new(CORSConfig)
var Config = LoadConfig()
Config represents the global configuration variables.
var ErrMongoDelete = errors.New("no delete document")
ErrMongoDelete represents an delete error in mongo case
var ErrMongoUpdate = errors.New("no updated document")
ErrMongoUpdate represents an update error in mongo case
var JSONValidator = NewValidator()
var Logger = new(LoggingHandler)
var Nats = new(NatsDAO)
Nats used for Nats connection
Functions ¶
func AccessCookieConfig ¶ added in v0.1.6
func AccessCookieConfig() echo.MiddlewareFunc
AccessCookieConfig can with echo for middleware.JWTWithConfig(vmod.AccessConfig) to handling access controll The token is reachable with c.Get("token")
func BindAndValidate ¶ added in v1.0.2
func BindAndValidate(c echo.Context, i interface{}) error
func HTTPErrorHandler ¶ added in v1.0.2
func HTTPErrorHandler(err error, c echo.Context)
HTTPErrorHandler handles echo.HTTPError and return the correct response.
func KeyAuthMiddleware ¶ added in v1.1.14
func KeyAuthMiddleware() echo.MiddlewareFunc
KeyAuthMiddleware middleware function for handling authentication via key.
func MongoNoDeleted ¶ added in v1.1.16
func MongoNoDocuments ¶ added in v1.1.2
func MongoNoUpdated ¶ added in v1.1.16
func RandomBase64 ¶ added in v1.0.2
RandomBase64 generate random Base64 string
func RandomBytes ¶ added in v1.0.2
RandomBytes return random bytes
func RefreshCookieConfig ¶ added in v0.1.6
func RefreshCookieConfig() echo.MiddlewareFunc
RefreshCookieConfig can with echo for middleware.JWTWithConfig(vmod.AccessConfig) to handling access controll The token is reachable with c.Get("token")
func RefreshCookieUserID ¶ added in v1.1.6
func ResetAccessCookie ¶ added in v1.1.6
ResetAccessCookie returns an cookie for reset the access_token.
func ResetRefreshCookie ¶ added in v1.1.6
ResetRefreshCookie returns an cookie for reset the refresh_token.
func SliceContains ¶ added in v1.1.6
Types ¶
type AccessToken ¶ added in v1.1.6
type AccessToken struct { ID string `json:"id,omitempty" bson:"_id"` Email string `json:"email" bson:"email" validate:"required,email"` FirstName string `json:"first_name" validate:"required"` LastName string `json:"last_name" validate:"required"` FullName string `json:"full_name"` DisplayName string `json:"display_name"` Roles RoleListCookie `json:"system_roles"` Country string `json:"country"` PrivacyPolicy bool `json:"privacy_policy"` Confirmed bool `json:"confirmed"` LastUpdate string `json:"last_update"` jwt.StandardClaims }
func AccessCookieUser ¶ added in v1.1.6
func AccessCookieUser(c echo.Context) (r *AccessToken, err error)
func NewAccessToken ¶ added in v1.1.6
func NewAccessToken(user *User) *AccessToken
func (*AccessToken) SignedString ¶ added in v1.1.6
func (i *AccessToken) SignedString(secret string) (string, error)
type AuthToken ¶ added in v1.1.6
type AuthToken struct { AccessToken string `json:"access_token" bson:"access_token"` RefreshToken string `json:"refresh_token" bson:"refresh_token"` ExpiresAt int64 `json:"expires_at" bson:"expires_at"` }
AuthToken represents the authentication tokens for handling access via jwt.
func NewAuthToken ¶ added in v1.1.6
NewAuthToken creates an new access and refresh token for the given user.
func (*AuthToken) AccessCookie ¶ added in v1.1.6
AccessCookie return an cookie conains the access_token.
func (*AuthToken) RefreshCookie ¶ added in v1.1.6
RefreshCookie returns an cookie conains the refresh_token.
type CORSConfig ¶ added in v0.0.7
type CORSConfig struct {
// contains filtered or unexported fields
}
func (*CORSConfig) Init ¶ added in v1.1.2
func (i *CORSConfig) Init() echo.MiddlewareFunc
NewCORSConfig create a echo middleware for cors handling.
type CookieConfig ¶ added in v1.2.0
CookieConfig represents the cookie parameters
func NewCookieConfig ¶ added in v1.2.0
func NewCookieConfig() *CookieConfig
NewCookieConfig loads the cookie parameters from the .env file and return a new CookieConfig.
type ErrorResponse ¶ added in v1.0.2
type ErrorResponse struct { Status int `json:"-"` Message string `json:"message"` Body interface{} `json:"body,omitempty"` Coll string `json:"collection,omitempty"` Model string `json:"model,omitempty"` }
Response represents an response json in case of an error.
func BadRequest ¶ added in v1.0.2
func BadRequest(message string, body ...interface{}) (int, *ErrorResponse)
BadRequest creates an echo.HTTPError with the status http.StatusBadRequest
func Conflict ¶ added in v1.0.2
func Conflict(message string, body ...interface{}) (int, *ErrorResponse)
Conflict creates an echo.HTTPError with the status http.StatusConflict
func InternalServerError ¶ added in v1.0.2
func InternalServerError() (int, ErrorResponse)
InternalServerError creates an echo.HTTPError with the status http.StatusInternalServerError
func NotFound ¶ added in v1.0.2
func NotFound(message string, body ...interface{}) (int, *ErrorResponse)
NotFound creates an echo.HTTPError with the status http.StatusNotFound
type HydraClient ¶ added in v1.1.4
type HydraClient struct { Oauth2Config oauth2.Config Verifier *oidc.IDTokenVerifier }
func NewHydraClient ¶ added in v1.1.4
func NewHydraClient() (r *HydraClient)
type IDjango ¶ added in v1.0.2
Mongo represents the initial struct for an Mongo connection.
type IDjangoError ¶ added in v1.0.2
type IDjangoError struct { Err error `json:"error" bson:"error"` Message string `json:"message" bson:"message"` Code int `json:"code" bson:"code"` Body interface{} `json:"body" bson:"body"` Line int `json:"line" bson:"line"` File string `json:"file" bson:"file"` }
func NewIDjangoError ¶ added in v1.0.2
func NewIDjangoError(err error, code int, body interface{}) *IDjangoError
func (*IDjangoError) Error ¶ added in v1.0.2
func (i *IDjangoError) Error() string
type LinkToken ¶ added in v1.0.2
type LinkToken struct { ID string `json:"id" bson:"_id"` Code string `json:"code" bson:"code"` ExpiresAt int64 `json:"expires_at" bson:"expires_at"` Scope string `json:"scope" bson:"scope"` UserID string `json:"user_id" bson:"user_id"` Modified Modified `json:"modified" bson:"modified"` }
LinkToken is used for handling link with token
func NewLinkToken ¶ added in v1.0.2
NewLinkToken initial a Token with a 32bit random string Base64 encoded for Web handling. Set expired time max 1 month.
type LoadEnv ¶ added in v0.1.1
type LoadEnv []bool
LoadEnv used for loading environment variables.
func LoadConfig ¶ added in v1.0.2
func LoadConfig() *LoadEnv
LoadConfig loads the .env file and return an LoadEnv type
func (LoadEnv) GetEnvBool ¶ added in v0.1.1
GetEnvBool load a key from environment variables as bool.
func (LoadEnv) GetEnvInt ¶ added in v0.1.1
GetEnvInt loads a key from enviroment variables as int. The lvl param defines the log level. For warnings set "w" and for error set "e". If the variable is not used or can be ignored use n for do nothing. The default value can be set by the dVal param.
func (LoadEnv) GetEnvString ¶ added in v0.1.1
GetEnvString loads a key from enviroment variables as string. The lvl param defines the log level. For warnings set "w" and for error set "e". If the variable is not used or can be ignored use n for do nothing. The default value can be set by the dVal param.
func (LoadEnv) GetEnvStringList ¶ added in v0.1.1
GetEnvStringList as
type LogError ¶ added in v1.0.2
type LogError struct { ID string `json:"id" bson:"_id"` Service string `json:"service" bson:"service"` Time string `json:"time" bson:"time"` RemoteIP string `json:"remote_ip" bson:"remote_io"` Host string `json:"host" bson:"host"` Method string `json:"method" bson:"method"` Uri string `json:"uri" bson:"uri"` UserAgent string `json:"user_agent" bson:"user_agent"` Status int `json:"status" bson:"status"` Error interface{} `json:"error" bson:"error"` Latency int64 `json:"latency" bson:"latency"` LatencyHuman string `json:"latency_human" bson:"latency_human"` ByteIn string `json:"byte_in" bson:"byte_in"` ByteOut string `json:"byte_out" bson:"byte_out"` ErrorType string `json:"error_type" bson:"error_type"` Modified Modified `json:"modified" bson:"modified"` }
LogError represents the an LogError for handling via nats and store into mongo databases. The struct matches the Config Format string as json.
type LoggingHandler ¶ added in v1.0.2
type LoggingHandler struct {
// contains filtered or unexported fields
}
Logger struct for handling the nats connection.
func (*LoggingHandler) Init ¶ added in v1.1.2
func (i *LoggingHandler) Init(service string) echo.MiddlewareFunc
Config for echo middleware Logger. Use logger for handle Nats connection.
func (*LoggingHandler) Log ¶ added in v1.0.2
func (i *LoggingHandler) Log(logError *LogError)
Log publish the LogError to nats route "logger.log".
type MailData ¶ added in v1.1.6
type MailData struct { TO string `json:"to" bson:"to"` Service string `json:"service" bson:"service"` Scope string `json:"scope" bson:"scope"` Lang string `json:"lang" bson:"lang"` User User `json:"user" bson:"user"` LinkToken LinkToken `json:"link_token" bson:"link_token"` }
func NewMailData ¶ added in v1.1.6
func (*MailData) AddLinkToken ¶ added in v1.1.6
type MailSend ¶ added in v1.1.14
func NewMailSend ¶ added in v1.1.14
func NewMailSend() *MailSend
type Modified ¶
type Modified struct { Updated int64 `json:"updated" bson:"updated"` Created int64 `json:"created" bson:"created"` }
func NewModified ¶ added in v1.1.2
func NewModified() Modified
NewModified initial Modified model, cTime is the current time Unix format.
type ModifiedQuery ¶ added in v1.1.5
type ModifiedQuery struct { UpdateFrom string `query:"update_from"` UpdateTo string `query:"update_to"` CreateFrom string `query:"create_from"` CreateTo string `query:"create_to"` }
func (*ModifiedQuery) Filter ¶ added in v1.1.5
func (i *ModifiedQuery) Filter(filter *MongoFilterM)
type Money ¶ added in v1.0.3
type Money struct { Amount int64 `bson:"amount" json:"amount" validate:"required"` Currency string `bson:"currency" json:"currency" validate:"required"` }
func (*Money) ValidateAmount ¶ added in v1.0.3
func (*Money) ValidateCurrency ¶ added in v1.0.3
type MongoColl ¶ added in v1.0.5
type MongoColl struct { Name string DatabaseName string Collection *mongo.Collection }
MongoColl represents an mongo db database collection
func (*MongoColl) CreateIndex ¶ added in v1.0.5
CreateIndex creates an index for a given collection.
func (*MongoColl) CreateMultiIndex ¶ added in v1.1.10
func (*MongoColl) DeleteMany ¶ added in v1.1.16
func (*MongoColl) DeleteOne ¶ added in v1.0.5
DeleteOne deletes an element from given collection by the bson.M filter.
func (*MongoColl) FindOne ¶ added in v1.0.5
FindOne select an element form database by using a given filter. The element will bind to the value interface{}. In error case it return an MongoError as error.
func (*MongoColl) InsertOne ¶ added in v1.0.5
InsertOne inserts a value and return an MongoError as error.
func (*MongoColl) InsertOrUpdate ¶ added in v1.1.2
func (i *MongoColl) InsertOrUpdate(ctx context.Context, filter bson.M, value interface{}) (err error)
InsertOrUpdate updates a value via "$set" and the given bson.M filter. Return an MongoError in case that no element has updated.
func (*MongoColl) Permission ¶ added in v1.1.13
type MongoDB ¶ added in v1.0.5
Mongo represents the initial struct for an Mongo connection.
func NewMongoDB ¶ added in v1.0.5
NewMongoDB creates a new MongoDB connects to mongoDB and return an Mongo struct.
func (*MongoDB) Collection ¶ added in v1.0.5
type MongoError ¶ added in v1.0.2
type MongoError struct { ErrorType string `json:"error_type" bson:"error_type"` Err error `json:"-" bson:"-"` Message string `json:"message" bson:"message"` Filter interface{} `json:"filter" bson:"filter"` Value interface{} `json:"value" bson:"value"` Database string `json:"database" bson:"database"` Collection string `json:"collection" bson:"collection"` Line int `json:"line" bson:"line"` File string `json:"file" bson:"file"` }
MongoError represents the struct of an mongo Error type.
func NewMongoError ¶ added in v1.0.2
func NewMongoError(err error, value interface{}, filter bson.M, database string, collection string) *MongoError
NewMongoError creates an mongo Error for an given parameter set
func (*MongoError) Error ¶ added in v1.0.2
func (i *MongoError) Error() string
Error return string of the error
func (*MongoError) Response ¶ added in v1.0.2
func (i *MongoError) Response() (int, interface{})
Response return the ErrorResponse for handling in httpErrorHandler
type MongoErrorResponse ¶ added in v1.1.12
type MongoErrorResponse struct { Filter interface{} `json:"filter" bson:"filter"` Collection string `json:"collection" bson:"collection"` }
type MongoFilterM ¶ added in v1.1.5
func NewMongoFilterM ¶ added in v1.1.5
func NewMongoFilterM() *MongoFilterM
func (*MongoFilterM) Equal ¶ added in v1.1.5
func (i *MongoFilterM) Equal(key string, value string)
func (*MongoFilterM) EqualIn64 ¶ added in v1.1.5
func (i *MongoFilterM) EqualIn64(key string, value string)
func (*MongoFilterM) EqualInt ¶ added in v1.1.5
func (i *MongoFilterM) EqualInt(key string, value string)
func (*MongoFilterM) GteInt ¶ added in v1.1.5
func (i *MongoFilterM) GteInt(key string, value string)
func (*MongoFilterM) GteInt64 ¶ added in v1.1.5
func (i *MongoFilterM) GteInt64(key string, value string)
func (*MongoFilterM) Like ¶ added in v1.1.5
func (i *MongoFilterM) Like(key string, value string)
func (*MongoFilterM) LteInt ¶ added in v1.1.5
func (i *MongoFilterM) LteInt(key string, value string)
func (*MongoFilterM) LteInt64 ¶ added in v1.1.5
func (i *MongoFilterM) LteInt64(key string, value string)
type MongoPipe ¶ added in v1.1.5
func NewMongoPipe ¶ added in v1.1.5
func NewMongoPipe() *MongoPipe
type NatsDAO ¶ added in v1.0.2
type NatsDAO struct {
// contains filtered or unexported fields
}
Nats represents the config struct for Nats service.
type RefreshToken ¶ added in v1.1.6
type RefreshToken struct { UserID string `json:"user_id"` jwt.StandardClaims }
func NewRefreshToken ¶ added in v1.1.6
func NewRefreshToken(userID string) *RefreshToken
func (*RefreshToken) SignedString ¶ added in v1.1.6
func (i *RefreshToken) SignedString(secret string) (string, error)
type Response ¶ added in v1.0.3
type Response struct { Message string `json:"message" bson:"message"` Model string `json:"model,omitempty" bson:"model,omitempty"` Payload interface{} `json:"payload,omitempty" bson:"payload,omitempty"` }
Response represents the default api response struct Message shows action information Model shows the collection that would be attached Payload contains the response model
func NewResponse ¶ added in v1.0.3
NewResponse can be used for create Response struct
func (*Response) BadRequest ¶ added in v1.1.2
func (*Response) InternalServerError ¶ added in v1.1.2
type Role ¶ added in v1.1.8
type Role struct { ID string `json:"id" bson:"_id"` Name string `json:"name" bson:"name"` Label string `json:"label" bson:"label"` Root string `json:"root" bson:"root"` UserID string `json:"user_id" bson:"user_id"` }
func RoleEmployee ¶ added in v1.1.8
func RoleMember ¶ added in v1.1.8
type RoleList ¶ added in v1.1.8
type RoleList []Role
func (*RoleList) Append ¶ added in v1.1.8
func (i *RoleList) Validate(roles string) bool { for n, _ := range *i { if strings.Contains(roles, (*i)[n].Name) { return true } } return false }
func (i *RoleList) CheckRoot(role *Role) bool { for n, _ := range *i { if strings.Contains(role.Root, (*i)[n].Name) { return true } } return false }
func (*RoleList) Cookie ¶ added in v1.2.2
func (i *RoleList) Cookie() (r *RoleListCookie)
type RoleListCookie ¶ added in v1.2.2
type RoleListCookie []string
func (*RoleListCookie) CheckRoot ¶ added in v1.2.2
func (i *RoleListCookie) CheckRoot(role *Role) bool
func (*RoleListCookie) Validate ¶ added in v1.2.2
func (i *RoleListCookie) Validate(roles string) bool
type Status ¶ added in v1.0.3
type Status struct { ErrorType string `bson:"error_type" json:"error_type"` StatusType string `bson:"status_type" json:"status_type"` StatusMessage string `bson:"status_message" json:"status_message"` }
func NewStatusBadRequest ¶ added in v1.1.9
func NewStatusInternal ¶ added in v1.0.3
func NewStatusPermissionDenied ¶ added in v1.1.13
func NewStatusPermissionDenied() *Status
func (*Status) ValidateDone ¶ added in v1.0.3
type User ¶
type User struct { ID string `json:"id,omitempty" bson:"_id"` Email string `json:"email" bson:"email" validate:"required,email"` FirstName string `bson:"first_name" json:"first_name" validate:"required"` LastName string `bson:"last_name" json:"last_name" validate:"required"` FullName string `bson:"full_name" json:"full_name"` DisplayName string `bson:"display_name" json:"display_name"` Roles RoleList `json:"system_roles" bson:"system_roles"` Country string `bson:"country" json:"country"` PrivacyPolicy bool `bson:"privacy_policy" json:"privacy_policy"` Confirmd bool `bson:"confirmed" json:"confirmed"` LastUpdate string `bson:"last_update" json:"last_update"` }
User represents the user model
func (*User) CheckUpdate ¶ added in v1.1.11
type UserClaims ¶ added in v1.1.4
type UserClaims struct {
User User `json:"user"`
}
type ValidationError ¶ added in v1.0.2
type ValidationError struct { ErrorType string `json:"error_type"` Errors []string `json:"errors"` }
func NewValidationError ¶ added in v1.1.2
func NewValidationError(err string) *ValidationError
func (*ValidationError) Bind ¶ added in v1.0.2
func (i *ValidationError) Bind(err error)
func (*ValidationError) Error ¶ added in v1.0.2
func (i *ValidationError) Error() string
func (*ValidationError) Response ¶ added in v1.0.3
func (i *ValidationError) Response() (int, interface{})
func (*ValidationError) Valid ¶ added in v1.0.2
func (i *ValidationError) Valid(err error)
Source Files ¶
- access_token.go
- auth_token.go
- cookie.go
- cors.go
- error_response.go
- hydra.go
- idjango.go
- key_auth.go
- linktoken.go
- loadenv.go
- log.go
- mail_data.go
- mail_send.go
- middleware.go
- modified.go
- money.go
- mongo_aggregate.go
- mongo_coll.go
- mongo_db.go
- mongo_error.go
- mongo_filter.go
- nats.go
- random.go
- refresh_token.go
- response.go
- roles.go
- service.go
- status.go
- user.go
- utils.go
- validation.go