Documentation ¶
Overview ¶
Package handles error logs via nats message broker
Index ¶
- Variables
- func BindAndValidate(c echo.Context, i interface{}) error
- func Env()
- func HTTPErrorHandler(err error, c echo.Context)
- func JWTNewAccessCookie(token *vmod.JWTToken) *http.Cookie
- func JWTNewRefreshCookie(token *vmod.JWTToken) *http.Cookie
- func JWTUser(c echo.Context) (u *vmod.User)
- func RandomBase64(n int) (string, error)
- func RandomBytes(n int) ([]byte, error)
- type CORSConfig
- type ErrorResponse
- type IDjango
- type IDjangoError
- type JWTMiddleware
- 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 Mongo
- func (i *Mongo) Aggregate(ctx context.Context, collection string, filter bson.D, value interface{}) (err error)
- func (i *Mongo) Connect(dbName string) (r *Mongo)
- func (i *Mongo) CreateIndex(collection string, field string, unique bool)
- func (i *Mongo) DeleteOne(ctx context.Context, collection string, filter bson.M) (err error)
- func (i *Mongo) Find(ctx context.Context, collection string, filter bson.M, value interface{}) (err error)
- func (i *Mongo) FindOne(ctx context.Context, collection string, filter bson.M, value interface{}) (err error)
- func (i Mongo) InsertOne(ctx context.Context, collection string, value interface{}) (err error)
- func (i *Mongo) LoadEnv() *Mongo
- func (i *Mongo) UpdateOne(ctx context.Context, collection string, filter bson.M, value interface{}) (err error)
- type MongoError
- type NatsDAO
- type ValidationError
- type Validator
Constants ¶
This section is empty.
Variables ¶
var AccessCookieConfig = middleware.JWTConfig{ Claims: &vmod.AccessToken{}, ContextKey: "token", TokenLookup: "cookie:access_token", SigningKey: []byte(os.Getenv("JWT_SECRET")), }
AccessCookieConfig can with echo for middleware.JWTWithConfig(vmod.AccessConfig) to handling access controll The token is reachable with c.Get("token")
var CORS = new(CORSConfig)
var Config = LoadConfig()
var DB = new(Mongo)
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 HTTPBaseCookie http.Cookie
HTTPBaseCookie defines the base cookie setup for vcago
var Logger = new(LoggingHandler)
var Nats = new(NatsDAO)
var NatsHost string
NatsHost is the ip of the nats service.
var NatsPort string
NatsPort is the port ot the nats service.
var RefreshCookieConfig = middleware.JWTConfig{ Claims: &vmod.RefreshToken{}, ContextKey: "token", TokenLookup: "cookie:refresh_token", SigningKey: []byte(os.Getenv("JWT_SECRET")), }
RefreshCookieConfig can with echo for middleware.JWTWithConfig(vmod.AccessConfig) to handling access controll The token is reachable with c.Get("token")
Functions ¶
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 JWTNewAccessCookie ¶ added in v0.1.6
JWTNewAccessCookie create a new http.Cookie contains the access_token.
func JWTNewRefreshCookie ¶ added in v0.1.6
JWTNewRefreshCookie create a new http.Cookie contains the refresh_token.
func RandomBase64 ¶ added in v1.0.2
RandomBase64 generate random Base64 string
func RandomBytes ¶ added in v1.0.2
RandomBytes return random bytes
Types ¶
type CORSConfig ¶ added in v0.0.7
type CORSConfig struct {
// contains filtered or unexported fields
}
func (*CORSConfig) LoadEnv ¶ added in v1.0.2
func (i *CORSConfig) LoadEnv() *CORSConfig
func (*CORSConfig) New ¶ added in v1.0.2
func (i *CORSConfig) New() middleware.CORSConfig
NewCORSConfig create a echo middleware for cors handling.
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 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 JWTMiddleware ¶ added in v0.1.6
type JWTMiddleware struct { RequestCount uint64 `json:"request_count"` Scope string `json:"scope"` }
JWTMiddleware handles authentication by jwt
type LinkToken ¶ added in v1.0.2
type LinkToken struct { ID string `bson:"_id" json:"token_id"` Code string `bson:"code" json:"code"` Tcase string `json:"t_case"` Scope string `json:"scope"` Expired int64 `json:"expired"` Created int64 `json:"created"` ModelID string `json:"model_id" bson:"model_id"` }
LinkToken is used for handling link with token
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
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"` Modified vmod.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) Config ¶ added in v1.0.2
func (i *LoggingHandler) Config() *middleware.LoggerConfig
Config for echo middleware Logger. Use logger for handle Nats connection.
func (*LoggingHandler) LoadEnv ¶ added in v1.0.2
func (i *LoggingHandler) LoadEnv() (r *LoggingHandler)
func (*LoggingHandler) Log ¶ added in v1.0.2
func (i *LoggingHandler) Log(logError *LogError)
Log publish the LogError to nats route "logger.log".
type Mongo ¶ added in v1.0.2
Mongo represents the initial struct for an Mongo connection.
func (*Mongo) CreateIndex ¶ added in v1.0.2
CreateIndex creates an index for a given collection.
func (*Mongo) DeleteOne ¶ added in v1.0.2
DeleteOne deletes an element from given collection by the bson.M filter.
func (*Mongo) FindOne ¶ added in v1.0.2
func (i *Mongo) FindOne(ctx context.Context, collection string, filter bson.M, value interface{}) (err error)
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 (Mongo) InsertOne ¶ added in v1.0.2
InsertOne inserts a value and return an MongoError as error.
type MongoError ¶ added in v1.0.2
type MongoError struct { 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 NatsDAO ¶ added in v1.0.2
type NatsDAO struct {
// contains filtered or unexported fields
}
Nats represents the config struct for Nats service.
type ValidationError ¶ added in v1.0.2
type ValidationError struct {
Errors []string `json:"errors"`
}
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)