fmk

package module
v0.0.0-...-b1b4505 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2022 License: MIT Imports: 17 Imported by: 0

README

fmk

Disclaimer: Not a utility to use

Build, install cli

add bin into shell path

export PATH=$PATH:/Users/jesus.r/workspace/fmk/fmk/bin
go build -o ./bin fmk.go 

now you can access fmk everywhere

Documentation

Index

Constants

View Source
const (
	InternalServerErrorCategory ApiErrorCategory = "ISE"
	RequestErrorCategory                         = "RQE"
	DBErrorCategory                              = "DBE"
	CacheErrorCategory                           = "CCE"
	ServiceErrorCategory                         = "SVE"
	UtilityErrorCategory                         = "UTE"
)
View Source
const (
	INFO    logLevel = 1
	DEBUG            = 2
	WARNING          = 3
	ERROR            = 4
)
View Source
const (
	HeaderFieldValidation EType = "headerField"
	BodyFieldValidation         = "bodyField"
	QueryFieldValidation        = "queryField"
	ParamFieldValidation        = "paramField"
	GenericValidation           = "generic"
)

Variables

This section is empty.

Functions

func ApiLog

func ApiLog() *apiLog

ApiLog gets a concurrent-safe api apiLogger instance

Types

type ApiError

type ApiError struct {
	Service    string           `json:"Service"`
	Operation  string           `json:"Operation"`
	Category   ApiErrorCategory `json:"Category"`
	StatusCode int              `json:"-"`
	Messages   []ErrorField     `json:"Messages"`
}

ApiError is the error that will be processed and formatted to the client on the response.

func (*ApiError) AddFieldMessage

func (e *ApiError) AddFieldMessage(etype EType, tag string, message string)

func (*ApiError) AddGenericMessage

func (e *ApiError) AddGenericMessage(etype EType, message string)

func (*ApiError) ContainsErrors

func (e *ApiError) ContainsErrors() bool

func (*ApiError) Error

func (e *ApiError) Error() string

Error will print out an error with all its data required to build said error. Contains ErrorCode & Service & message

type ApiErrorCategory

type ApiErrorCategory string

ApiErrorCategory describes the type of error thrown by the api

type Context

type Context struct {
	Res   http.ResponseWriter
	Req   *http.Request
	Param httprouter.Params
}

func (*Context) Json

func (c *Context) Json(statusCode int, body interface{})

func (*Context) ValidateBody

func (c *Context) ValidateBody(b interface{}) error

func (*Context) ValidateHeader

func (c *Context) ValidateHeader(h interface{}) error

func (*Context) ValidateParam

func (c *Context) ValidateParam(p interface{}) error

func (*Context) ValidateQuery

func (c *Context) ValidateQuery(q interface{}) error

type EType

type EType string

type Endpoint

type Endpoint func(c *Context) error

func RequireTenantToken

func RequireTenantToken(auth IAuthSdk) Endpoint

type ErrorField

type ErrorField struct {
	EType  EType  `json:"eType,omitempty"`
	EField string `json:"eField,omitempty"`
	ETag   string `json:"eTag,omitempty"`
}

type IAuthSdk

type IAuthSdk interface {
	HasPermission(tenantId, userId, roleId, method, path string) bool
}

type IContext

type IContext interface {
	Json(statusCode int, body interface{})

	ValidateBody(body interface{}) error
	ValidateHeader(header interface{}) error
	ValidateQuery(query interface{}) error
	ValidateParam(param interface{}) error
	TenantDoc() *TenantDoc
}

type IDb

type IDb interface {
	Disconnect() error
	GetModel(colName string) IModel
}

IDb required interface for DB connectivity

type IModel

type IModel interface {
	Insert(doc interface{}) (string, error)
	UpdateByFilter(filter interface{}, toChange interface{}) error
	FindByFilter(filter interface{}, sort interface{}, pagination MPagination, docs interface{}) error
	DeleteByFilter(filter interface{}) error
}

IModel required interface for CRUD Model operations for both all data associated to a single resource

type IServer

type IServer interface {
	Get(url string, handler Endpoint)
	Post(url string, handler Endpoint)
	Put(url string, handler Endpoint)
	Delete(url string, handler Endpoint)
	ServeHTTP(w http.ResponseWriter, req *http.Request)
	Run() error
	// contains filtered or unexported methods
}

type MDb

type MDb struct {
	*mongo.Database
}

func NewDb

func NewDb(dbUrl string, dbName string) (*MDb, error)

NewDb creates Database instance, connects to mongo and complies with IMongoDatabase interface

func (*MDb) Disconnect

func (d *MDb) Disconnect() error

func (*MDb) GetModel

func (d *MDb) GetModel(colName string) *MModel

type MModel

type MModel struct {
	*mongo.Collection
}

func (*MModel) DeleteByFilter

func (m *MModel) DeleteByFilter(filter interface{}) error

func (*MModel) FindByFilter

func (m *MModel) FindByFilter(filter interface{}, sort interface{}, pagination MPagination, docs interface{}) error

func (*MModel) Insert

func (m *MModel) Insert(doc interface{}) (string, error)

func (*MModel) UpdateByFilter

func (m *MModel) UpdateByFilter(filter interface{}, toChange interface{}) error

type MPagination

type MPagination struct {
	Limit int64
	Next  string
}

type MSortType

type MSortType int
const (
	ASC  MSortType = 1
	DESC           = -1
)

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer() *Server

func (*Server) Delete

func (a *Server) Delete(url string, handler Endpoint)

func (*Server) Get

func (a *Server) Get(url string, handler Endpoint)

func (*Server) LoadEnv

func (a *Server) LoadEnv(filenames ...string) error

func (*Server) Post

func (a *Server) Post(url string, handler Endpoint)

func (*Server) Put

func (a *Server) Put(url string, handler Endpoint)

func (*Server) Run

func (a *Server) Run() error

func (*Server) ServeHTTP

func (a *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

type TenantDoc

type TenantDoc struct {
	UserId   string
	TenantId string
	RoleId   string
}

type Void

type Void struct{}

Directories

Path Synopsis
Package mock_fmk is a generated GoMock package.
Package mock_fmk is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL