api

package
v2.17.6 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: CC0-1.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrContains

func ArrContains[T string | int | float32](arr []T, val T) bool

func GenerateQueryComponenFromStruct

func GenerateQueryComponenFromStruct(model interface{}, skips []string) (string, []interface{}, string)

func GetStructKey

func GetStructKey(field reflect.StructField) string

func GetStructValue

func GetStructValue(value reflect.Value) interface{}

func InitHandler

func InitHandler(router http.Handler) http.Handler

func MethodNotAllowedHandler

func MethodNotAllowedHandler(w http.ResponseWriter, r *http.Request)

func PanicHandler

func PanicHandler(next http.Handler) http.Handler

func RouteNotFoundHandler

func RouteNotFoundHandler(w http.ResponseWriter, r *http.Request)

func WriteJson

func WriteJson(w http.ResponseWriter, data interface{})

Types

type App

type App struct {
	Http *chi.Mux
	*server.Config
	TotalEndpoints int
	// contains filtered or unexported fields
}

func NewApp

func NewApp(opts ...Options) *App

func (*App) AddController

func (app *App) AddController(ctrl Controller)

func (*App) AddScheduler added in v2.8.1

func (app *App) AddScheduler(pattern string, handler cron.HandlerFunc)

func (*App) Cache added in v2.13.2

func (app *App) Cache() cache.Caches

func (*App) DB added in v2.13.2

func (app *App) DB() database.ISQL

func (*App) Init

func (app *App) Init()

func (*App) Start

func (app *App) Start() error

func (*App) Trx added in v2.13.2

func (app *App) Trx() database.Transactions

func (*App) WrapScheduler added in v2.8.7

func (app *App) WrapScheduler(wrapper cron.Wrapper)

func (*App) WrapToContext added in v2.3.0

func (app *App) WrapToContext(wrapper Wrapper)

type Apps

type Apps interface {
	LoadModules()
	LoadWrapper()
}

type Controller

type Controller interface {
	GetConfig() ControllerConfig
}

type ControllerConfig

type ControllerConfig struct {
	Path        string
	Routes      []Route
	Middlewares *[]func(http.Handler) http.Handler
}

type ControllerImpl

type ControllerImpl struct {
}

func (*ControllerImpl) JoinMiddleware

func (ctrl *ControllerImpl) JoinMiddleware(handlers ...func(http.Handler) http.Handler) *[]func(http.Handler) http.Handler

type ErrorOption

type ErrorOption func(*HttpError)

func WithErrorCallerPath added in v2.9.7

func WithErrorCallerPath(callerPath string) ErrorOption

func WithErrorCode added in v2.9.6

func WithErrorCode(code string) ErrorOption

func WithErrorData added in v2.9.6

func WithErrorData(data interface{}) ErrorOption

func WithErrorMessage added in v2.9.6

func WithErrorMessage(message string) ErrorOption

func WithErrorStatus added in v2.9.6

func WithErrorStatus(status int) ErrorOption

type Handler

type Handler func(Request, context.Context) *Response

type HttpError

type HttpError struct {
	Message    string      `json:"message"`
	Code       string      `json:"code"`
	Status     int         `json:"-"`
	TraceId    string      `json:"trace_id"`
	Data       interface{} `json:"data,omitempty"`
	CallerPath string      `json:"caller_path,omitempty"`
}

func BadRequest

func BadRequest(message, code string) *HttpError

func Forbidden

func Forbidden(message, code string) *HttpError

func InternalServerError

func InternalServerError(message, code string) *HttpError

func MethodNotAllowed

func MethodNotAllowed(message, code string) *HttpError

func NewErr

func NewErr(opts ...ErrorOption) *HttpError

func NotFound

func NotFound(message, code string) *HttpError

func TooManyRequest

func TooManyRequest(message, code string) *HttpError

func Unauthorized

func Unauthorized(message, code string) *HttpError

func UnprocessableEntity

func UnprocessableEntity(message, code string) *HttpError

func (*HttpError) Error

func (e *HttpError) Error() string

func (*HttpError) SetTraceId added in v2.5.6

func (e *HttpError) SetTraceId(traceId string)

func (*HttpError) Write

func (e *HttpError) Write(w http.ResponseWriter)

type Map

type Map map[string]interface{}

type Options

type Options func(api *App)

func ReadTimeout

func ReadTimeout(readTimeout int) Options

func WithAPITimeout

func WithAPITimeout(apiTimeout int) Options

func WithAppPort

func WithAppPort(port int) Options

func WithCronJob added in v2.8.0

func WithCronJob(timezone ...string) Options

func WriteTimeout

func WriteTimeout(writeTimeout int) Options

type Request

type Request struct {
	GetParams  func(key string, defaultValue ...string) string
	GetFile    func(key string) (multipart.File, *multipart.FileHeader, error)
	GetQuery   func(interface{}) error
	GetBody    func(interface{}) error
	GetHeaders func(interface{}) error
}

type Response

type Response struct {
	Message string      `json:"message,omitempty"`
	Data    interface{} `json:"data,omitempty"`
	Err     error       `json:"error,omitempty"`

	InternalError *HttpError                 `json:"-"`
	MetaData      *database.ResponseMetaData `json:"metadata,omitempty"`
	// contains filtered or unexported fields
}

func NewResponse

func NewResponse() *Response

func (*Response) Send added in v2.3.9

func (resp *Response) Send(w http.ResponseWriter)

func (*Response) SentNotif added in v2.2.0

func (resp *Response) SentNotif(ctx contextpkg.Context, err *HttpError, r *http.Request, traceId string)

func (*Response) SetData

func (resp *Response) SetData(data interface{}) *Response

func (*Response) SetError

func (resp *Response) SetError(err error) *Response

func (*Response) SetHTTPError

func (resp *Response) SetHTTPError(err *HttpError) *Response

func (*Response) SetMessage

func (resp *Response) SetMessage(msg string) *Response

func (*Response) SetStatusCode added in v2.17.5

func (resp *Response) SetStatusCode(statusCode int) *Response

type Route

type Route struct {
	Method      string
	Path        string
	Handler     Handler
	Version     int
	Middlewares *[]func(http.Handler) http.Handler
}

func NewRoute

func NewRoute(method string, handler Handler, opts ...RouteOption) Route

func (*Route) GetVersionedPath

func (r *Route) GetVersionedPath(controllerPath string) string

type RouteOption

type RouteOption func(*Route)

func WithMiddleware

func WithMiddleware(handlers ...func(http.Handler) http.Handler) RouteOption

func WithPath

func WithPath(path string) RouteOption

func WithVersion

func WithVersion(version int) RouteOption

type StringMap

type StringMap map[string]string

type ValidationError

type ValidationError struct {
	Field string `json:"field"`
	Tag   string `json:"tag"`
	Value string `json:"value"`
}

func ValidateStruct

func ValidateStruct(data interface{}) []*ValidationError

type Wrapper added in v2.3.0

type Wrapper interface {
	WrapToHandler(handler http.Handler) http.Handler
	WrapToContext(ctx context.Context) context.Context
}

type WrittenResponseWriter

type WrittenResponseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func (*WrittenResponseWriter) Write

func (w *WrittenResponseWriter) Write(b []byte) (int, error)

func (*WrittenResponseWriter) WriteHeader

func (w *WrittenResponseWriter) WriteHeader(status int)

func (*WrittenResponseWriter) Written

func (w *WrittenResponseWriter) Written() bool

Jump to

Keyboard shortcuts

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