Documentation ¶
Overview ¶
Package handles error logs via nats message broker
Index ¶
- Variables
- func AccessCookieMiddleware(i jwt.Claims) echo.MiddlewareFunc
- func BindAndValidate(c echo.Context, i interface{}) error
- func HTTPErrorHandler(err error, c echo.Context)
- func KeyAuthMiddleware() echo.MiddlewareFunc
- func RandomBase64(n int) (string, error)
- func RandomBytes(n int) ([]byte, error)
- func RefreshCookieMiddleware() echo.MiddlewareFunc
- func RefreshCookieUserID(c echo.Context) (string, error)
- func ResetAccessCookie() *http.Cookie
- func ResetRefreshCookie() *http.Cookie
- func SignedString(token jwt.Claims) (string, error)
- func SliceContains(list []string, element string) bool
- type AccessToken
- type AdminRequest
- type AuthToken
- type Callback
- type Context
- func (i *Context) AccessToken(token interface{}) (err error)
- func (i *Context) BadRequest(message string, payload interface{}) (err error)
- func (i *Context) BindAndValidate(body interface{}) error
- func (i *Context) Created(payload interface{}) (err error)
- func (i *Context) Ctx() context.Context
- func (i *Context) Deleted(payload interface{}) (err error)
- func (i *Context) ErrorResponse(err error) error
- func (i *Context) Listed(payload interface{}, listSize int64) (err error)
- func (i *Context) Log(err error)
- func (i *Context) RefreshTokenID() (string, error)
- func (i *Context) Selected(payload interface{}) (err error)
- func (i *Context) SuccessResponse(status int, message string, model string, payload interface{}) (err error)
- func (i *Context) Updated(payload interface{}) (err error)
- type CookieConfig
- type CycularMail
- type Error
- func (i *Error) AddModel(model string) *Error
- func (i *Error) BindResponse() (int, interface{})
- func (i *Error) Error() string
- func (i *Error) Log() string
- func (i *Error) MongoResponse() (int, interface{})
- func (i *Error) Print(id string)
- func (i *Error) Response() (int, interface{})
- func (i *Error) ValidationResponse() (int, interface{})
- type Handler
- type HydraClient
- type IDjangoError
- type IDjangoHandler
- type LinkToken
- type LogError
- type LoggingHandler
- type MailData
- func (i *MailData) AddContactUser(id string, email string, firstName string, lastName string)
- func (i *MailData) AddContent(content *vmod.Content)
- func (i *MailData) AddCurrentUser(id string, email string, firstName string, lastName string)
- func (i *MailData) AddLinkToken(token *LinkToken)
- func (i *MailData) AddUser(user *vmod.User)
- func (i *MailData) Send() (err error)
- type MailSend
- type MailUser
- type NatsDAO
- type NotificationData
- type NotificationResponse
- type RefreshToken
- type Response
- func NewBadRequest(model string, message string, payload ...interface{}) *Response
- func NewConflict(model string, payload ...interface{}) *Response
- func NewCreated(model string, payload interface{}) *Response
- func NewDeleted(model string, payload interface{}) *Response
- func NewExecuted(model string, payload interface{}) *Response
- func NewInternalServerError(model string, payload ...interface{}) *Response
- func NewListed(model string, payload interface{}, listSize int64) *Response
- func NewNotFound(model string, payload ...interface{}) *Response
- func NewPermissionDenied(model string, payload ...interface{}) *Response
- func NewResp(status int, typ string, message string, model string, payload interface{}) *Response
- func NewSelected(model string, payload interface{}) *Response
- func NewUpdated(model string, payload interface{}) *Response
- type Server
- type SettingHandler
- func (i *SettingHandler) Bool(key string, lvl string, dVal bool) bool
- func (i *SettingHandler) Int(key string, lvl string, dVal int) int
- func (i *SettingHandler) Load()
- func (i *SettingHandler) String(key string, lvl string, dVal string) string
- func (i *SettingHandler) StringList(key string, lvl string, dVal []string) []string
- type Test
- func (i *Test) DELETEContext(data string, rec *httptest.ResponseRecorder, token *jwt.Token) Context
- func (i *Test) GETByIDContext(data string, rec *httptest.ResponseRecorder, token *jwt.Token) Context
- func (i *Test) GETContext(data string, rec *httptest.ResponseRecorder, token *jwt.Token) Context
- func (i *Test) POSTContext(data string, rec *httptest.ResponseRecorder, token *jwt.Token) Context
- func (i *Test) PUTContext(data string, rec *httptest.ResponseRecorder, token *jwt.Token) Context
- type UserClaims
- type ValidationError
- type Validator
Constants ¶
This section is empty.
Variables ¶
var APIKey = Settings.String("API_KEY", "w", "secret")
APIKey represents the api Bearer token
var JSONValidator = NewValidator()
var LogLevel = Settings.String("LOG_LEVEL", "w", "DEBUG")
var Logger = new(LoggingHandler)
Logger is the global LoggingHandler
var Nats = new(NatsDAO)
Nats used for Nats connection
var Settings = SettingHandlerLoad()
Settings represents the global SettingType variable and can be used for load config parameters.
Functions ¶
func AccessCookieMiddleware ¶ added in v1.3.0
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)
func KeyAuthMiddleware ¶ added in v1.1.14
func KeyAuthMiddleware() echo.MiddlewareFunc
KeyAuthMiddleware middleware function for handling authentication via key.
func RandomBase64 ¶ added in v1.0.2
RandomBase64 generate random Base64 string
func RandomBytes ¶ added in v1.0.2
RandomBytes return random bytes
func RefreshCookieMiddleware ¶ added in v1.3.0
func RefreshCookieMiddleware() 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 vmod.RoleListCookie `json:"system_roles"` Country string `json:"country"` PrivacyPolicy bool `json:"privacy_policy"` Confirmed bool `json:"confirmed"` LastUpdate string `json:"last_update"` jwt.StandardClaims }
AccessToken represents the default access_token contains the basic user informations.
func NewAccessToken ¶ added in v1.1.6
func NewAccessToken(user *vmod.User) *AccessToken
NewAccessToken creates an new access_token from vmod.User model.
func (*AccessToken) SignedString ¶ added in v1.1.6
func (i *AccessToken) SignedString(secret string) (string, error)
SignedString is used for Sign an accesstoken based on the secret param.
type AdminRequest ¶ added in v1.2.10
type AdminRequest struct {
URL string
}
AdminRequest represents model for admin requests.
func NewAdminRequest ¶ added in v1.2.10
func NewAdminRequest() *AdminRequest
NewAdminRequest initial the AdminRequest model.
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 Context ¶ added in v1.3.0
type Context struct { Model string echo.Context }
Context extends an echo.Context type. Inititial an Context for an echo.Group via echo.Group.Use(Handler.Context()). The Context model is set by the Model param of the Handler model.
Example:
func (i *ExampleHandler) Routes(group echo.Group) { group.Use(i.Context) }
Echo need and function that provide an echo.Context as parameter. So you need to convert the echo.Context to an Context in a function block.
Example:
func (i *ExampleHandler) Create(cc echo.Context) (err error) { c := cc.(vcago.Context) ... }
func (*Context) AccessToken ¶ added in v1.3.0
AccessToken binds the accessToken form an cookie into the token interface. The token needs to extends jwt.StandardClaims.
func (*Context) BadRequest ¶ added in v1.4.11
func (*Context) BindAndValidate ¶ added in v1.3.0
BindAndValidate binds the request data in an the body interface. Define param:"" for bind the params in a struct. Define json:"" for bind the request body as json in a struct. Define query:"" for bind the query parameters in a struct.
func (*Context) Created ¶ added in v1.3.0
Created returns an Created response.
Status: 201 Created
JSON: model == "example"
{ "type": "success", "message": "successfully_created", "model": "example", "payload": payload }
func (*Context) Deleted ¶ added in v1.3.0
Deleted returns an Deleted response.
Status: 200 OK
JSON: model == "example"
{ "type": "success", "message": "successfully_deleted", "model": "example", "payload": payload }
func (*Context) ErrorResponse ¶ added in v1.4.0
ErrorResonse match the error and returns the correct error response.
Error: mongo.IsDuplicateKeyError
Status: 409 Conflict
JSON:
{ "type": "error", "message": "duplicate_key_error", "model": model, "payload": key from error }
Error: mongo.ErrNoDocument
Status: 404 Not Found
JSON:
{ "type": "error", "message": "not_found", "model": model }
Error: default
Status: 500 Internal Server Error
JSON:
{ "type": "error", "message": "internal_server_error", "model": model }
func (*Context) Listed ¶ added in v1.3.0
Listed return an List response.
Status: 200 OK
JSON: model == "example"
{ "type": "success", "message": "successfully_selected", "model": "example_list", "payload": payload, "list_size": listSize }
func (*Context) Log ¶ added in v1.4.0
Log return a function call for handling Debug and Error logs. Usage: c.Log(err)(err)
func (*Context) RefreshTokenID ¶ added in v1.4.5
RefreshToken returns the user id of an refresh token.
func (*Context) Selected ¶ added in v1.3.0
Selected returns an Selected response.
Status: 200 OK
JSON: model == "example"
{ "type": "success", "message": "successfully_selected", "model": "example", "payload": payload }
func (*Context) SuccessResponse ¶ added in v1.4.0
func (i *Context) SuccessResponse(status int, message string, model string, payload interface{}) (err error)
SuccessResponse returns an new success 200 OK response with an custom message string.
Status: 200 OK
JSON: model == "example"
{ "type": "success", "message": message, "model": "example", "payload": payload }
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 CycularMail ¶ added in v1.2.4
type CycularMail struct { Email string `json:"email"` Emails []string `json:"emails"` Subject string `json:"subject"` Message string `json:"message"` }
func NewCycularMail ¶ added in v1.2.4
func NewCycularMail(email string, emails []string, subject string, message string) *CycularMail
type Error ¶ added in v1.4.1
type Error struct { ID string `json:"id"` Time string `json:"time"` Level string `json:"level"` File string `json:"file"` Line int `json:"line"` Message string `json:"message"` Err error `json:"-"` Model string `json:"model,omitempty"` Type string `json:"type"` }
func (*Error) BindResponse ¶ added in v1.4.1
func (*Error) MongoResponse ¶ added in v1.4.1
func (*Error) Response ¶ added in v1.4.1
MongoErrorResponseHandler handles the response for the MongoError type.
func (*Error) ValidationResponse ¶ added in v1.4.1
type Handler ¶ added in v1.3.0
type Handler struct {
Model string
}
Handler represents an network handler for echo framework
func NewHandler ¶ added in v1.3.0
NewHandler creates an new `Handler`.
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 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
func (*IDjangoError) Log ¶ added in v1.4.4
func (i *IDjangoError) Log() string
type IDjangoHandler ¶ added in v1.4.4
Mongo represents the initial struct for an Mongo connection.
func NewIDjangoHandler ¶ added in v1.4.4
func NewIDjangoHandler() *IDjangoHandler
LoadEnv loads the Host and Port From .env file. Host can be set via NATS_HOST Port can be set via NATS_PORT
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 vmod.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 LogError ¶ added in v1.0.2
type LogError struct { ID string `json:"id" bson:"_id"` Time string `json:"time" bson:"time"` RemoteIP string `json:"remote_ip" bson:"remote_ip"` 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"` }
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
}
LoggingHandler represents a struct for handling response logging.
func (*LoggingHandler) Init ¶ added in v1.1.2
func (i *LoggingHandler) Init() echo.MiddlewareFunc
Init initial the config for echo middleware Logger.
type MailData ¶ added in v1.1.6
type MailData struct { TO string `json:"to" bson:"to"` Service string `json:"service" bson:"service"` Name string `json:"name" bson:"name"` Scope string `json:"scope" bson:"scope"` Lang string `json:"lang" bson:"lang"` User vmod.User `json:"user" bson:"user"` Content vmod.Content `json:"content" bson:"content"` LinkToken LinkToken `json:"link_token" bson:"link_token"` CurrentUser MailUser `json:"current_user" bson:"current_user"` ContactUser MailUser `json:"contact_user" bson:"contact_user"` }
func NewMailData ¶ added in v1.1.6
func (*MailData) AddContactUser ¶ added in v1.2.3
func (*MailData) AddContent ¶ added in v1.4.35
func (*MailData) AddCurrentUser ¶ added in v1.2.3
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
func (*MailSend) PostCycularMail ¶ added in v1.2.4
func (i *MailSend) PostCycularMail(data *CycularMail)
type NatsDAO ¶ added in v1.0.2
type NatsDAO struct {
// contains filtered or unexported fields
}
Nats represents the config struct for Nats service.
type NotificationData ¶ added in v1.4.37
type NotificationData 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"` Name string `json:"name" bson:"name"` Content vmod.Content `json:"content" bson:"content"` User vmod.User `json:"user" bson:"user"` OriginUserID string `json:"origin_user_id" bson:"origin_user_id"` }
func NewMNotificationData ¶ added in v1.4.37
func (*NotificationData) AddContent ¶ added in v1.4.37
func (i *NotificationData) AddContent(content *vmod.Content)
func (*NotificationData) AddUser ¶ added in v1.4.37
func (i *NotificationData) AddUser(user *vmod.User)
func (*NotificationData) Response ¶ added in v1.4.37
func (i *NotificationData) Response() *NotificationResponse
type NotificationResponse ¶ added in v1.4.37
type NotificationResponse 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"` Name string `json:"name" bson:"name"` Content vmod.Content `json:"content" bson:"content"` User vmod.User `json:"user" bson:"user"` OriginUserID string `json:"origin_user_id" bson:"origin_user_id"` From string `json:"from" bson:"from"` Subject string `json:"subject" bson:"subject"` Body string `json:"body" bson:"body"` }
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
type Response ¶ added in v1.0.3
type Response struct { Status int `json:"-"` Type string `json:"type" bson:"type"` Message string `json:"message" bson:"message"` Model string `json:"model,omitempty" bson:"model,omitempty"` Payload interface{} `json:"payload,omitempty" bson:"payload,omitempty"` ListSize int64 `json:"list_size,omitempty" bson:"list_size,omitempty"` }
Response represents the default api response struct Status defines the response status code Type defines the response type. Can be success or error Message shows action information Model shows the collection that would be attached Payload contains the response model
func NewBadRequest ¶ added in v1.2.8
NewBadRequest returns an Response model intended for an bad request response.
Status: 400 Bad Request
JSON with payload:
{ "type": "error", "message": message, "model": model, "payload": payload }
JSON without payload:
{ "type": "error", "message": message, "model": model, }
func NewConflict ¶ added in v1.2.8
NewConflict returns an Response model intended for an conflict error response.
Status: 409 Conflict
JSON with payload:
{ "type": "error", "message": "conflict", "model": model, "payload": payload }
JSON without payload:
{ "type": "error", "message": "conflict", "model": model }
func NewCreated ¶ added in v1.2.10
NewCreated returns a Response model intended for a POST request that creates a model.
Status: 201 Created
JSON:
{ "type": "success", "message": "successfully_created", "model": model, "payload": payload }
func NewDeleted ¶ added in v1.2.10
NewDeleted returns a Response model intended for a DELETE request that deletes a model.
Status: 200 OK
JSON:
{ "type": "success", "message": "successfully_deleted", "model": model, "payload": payload }
func NewExecuted ¶ added in v1.2.10
NewExecuted returns an Response model intended for a request that execute an process.
Status: 200 OK
JSON:
{ "type": "success", "message": "successfully_executed", "model": model, "payload": payload }
func NewInternalServerError ¶ added in v1.2.10
NewInternalServerError returns an Response model intended for an internal server error response. The payload param is optional.
Status: 500 Internal Server Error
JSON with payload:
{ "type": "error", "message": "internal_server_error", "model": model, "payload": payload }
JSON without payload:
{ "type": "error", "message": "internal_server_error", "model": model }
func NewListed ¶ added in v1.4.26
NewListeded returns a Response model intended for a GET request that selects a list.
Status: 200 OK
JSON:
{ "type": "success", "message": "successfully_selected", "model": model, "payload": payload, "list_size": listSize }
func NewNotFound ¶ added in v1.2.8
NewNotFound returns an Response model intended for an not found error response.
Status: 404 Not Found
JSON with payload:
{ "type": "error", "message": "not_found", "model": model, "payload": payload }
JSON without payload:
{ "type": "error", "message": "not_found", "model": model }
func NewPermissionDenied ¶ added in v1.2.10
NewPermissionDenied returns an Response model intended for an permission denied error response.
Status: 400 Bad Request
JSON with payload:
{ "type": "error", "message": "permission_denied", "model": model, "payload": payload }
JSON without payload:
{ "type": "error", "message": "permission_denied", "model": model }
func NewSelected ¶ added in v1.2.10
NewSelected returns a Response model intended for a GET request that selects a model or list.
Status: 200 OK
JSON:
{ "type": "success", "message": "successfully_selected", "model": model, "payload": payload }
func NewUpdated ¶ added in v1.2.10
NewUpdated returns a Response model intended for a PUT request that updates a model.
Status: 200 OK
JSON:
{ "type": "success", "message": "successfully_updated", "model": model, "payload": payload }
type Server ¶ added in v1.4.6
type Server struct {
echo.Echo
}
Server represents an echo.Echo interface.
type SettingHandler ¶ added in v1.4.6
SettingHandler represents and handler for load Settings via flag or environment variable.
func SettingHandlerLoad ¶ added in v1.4.6
func SettingHandlerLoad() *SettingHandler
SettingHandlerLoad loads all variables form an .env file and return an SettingHandler.
func (*SettingHandler) Bool ¶ added in v1.4.6
func (i *SettingHandler) Bool(key string, lvl string, dVal bool) bool
func (*SettingHandler) Int ¶ added in v1.4.6
func (i *SettingHandler) Int(key string, lvl string, dVal int) int
func (*SettingHandler) Load ¶ added in v1.4.6
func (i *SettingHandler) Load()
func (*SettingHandler) String ¶ added in v1.4.6
func (i *SettingHandler) String(key string, lvl string, dVal string) string
String loads an string config variable. The function will first looking for an flag, than the environment variables and as default dVal.
func (*SettingHandler) StringList ¶ added in v1.4.6
func (i *SettingHandler) StringList(key string, lvl string, dVal []string) []string
type Test ¶ added in v1.4.6
type Test struct {
Server Server
}
func (*Test) DELETEContext ¶ added in v1.4.6
func (*Test) GETByIDContext ¶ added in v1.4.6
func (*Test) GETContext ¶ added in v1.4.6
func (*Test) POSTContext ¶ added in v1.4.6
func (*Test) PUTContext ¶ added in v1.4.6
type UserClaims ¶ added in v1.1.4
type ValidationError ¶ added in v1.0.2
type ValidationError struct {
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) Valid ¶ added in v1.0.2
func (i *ValidationError) Valid(err error)
Source Files ¶
- access_token.go
- admin_request.go
- auth_token.go
- context.go
- cookie.go
- cors.go
- error.go
- error_handler.go
- handler.go
- hydra.go
- idjango.go
- key_auth.go
- linktoken.go
- log.go
- mail_cycular.go
- mail_data.go
- mail_send.go
- nats.go
- notification.go
- random.go
- refresh_token.go
- response.go
- server.go
- settings.go
- tests.go
- utils.go
- validation.go