ginger

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HEADER_AUTHORIZATION = "Authorization"
	HEADER_X_LOCALE      = "X-Locale"
)
View Source
const (
	DB_TYPE_MYSQL = "mysql"
	DB_TYPE_PGSQL = "postgres"
	DB_TYPE_MEM   = "memory"
)

Variables

View Source
var ApiService = new(apiService)
View Source
var Engine = newEngine()

Engine is the framework's instance. It is supposed to be one per application.

View Source
var FileService = new(fileService)
View Source
var ModelService = new(modelService)

Functions

func Corn

func Corn(pattern string, handler func(), initExec bool)

func DELETE

func DELETE[T any](path string, handler func(ctx *Context[T]), opts ...*ApiOpts)

func Env

func Env(key string) string

Env returns the environment variable value by the key. The key will be stored in the engine.

func GET

func GET[T any](path string, handler func(ctx *Context[T]), opts ...*ApiOpts)

func InitJob

func InitJob(handler func(), after bool)

func Middleware

func Middleware(handler func(ctx *Context[struct{}]), matchPaths []string, skipPaths []string)

func NewMemMigrate added in v1.0.1

func NewMemMigrate(m ...any)

func NewMigrate added in v1.0.1

func NewMigrate(m ...any)

func POST

func POST[T any](path string, handler func(ctx *Context[T]), opts ...*ApiOpts)

func PUT

func PUT[T any](path string, handler func(ctx *Context[T]), opts ...*ApiOpts)

func WS

func WS[T any](path string, handler func(ctx *Context[T], ws *websocket.Conn))

Types

type ApiHandler

type ApiHandler struct {
	Handler gin.HandlerFunc `json:"-"`
	Method  string          `json:"method"`
	Path    string          `json:"path"`
	Opts    *ApiOpts        `json:"opts"`
}

type ApiInfo

type ApiInfo struct {
	Imports map[string]bool
	Content string
}

type ApiOpts

type ApiOpts struct {
	RateLimit  *RateLimitOpt  `json:"rate_limit"`
	Cache      *CacheOpt      `json:"cache"`
	Typescript *TypescriptOpt `json:"typescript"`
}

type CacheOpt

type CacheOpt struct {
	Duration time.Duration `json:"duration"`
}

type Context

type Context[T any] struct {
	Engine *engine
	GinCtx *gin.Context

	TraceId string

	Request  *T
	Response *Response
	// contains filtered or unexported fields
}

func NewContext

func NewContext[T any](ginCtx *gin.Context) *Context[T]

func (*Context[T]) Agent

func (c *Context[T]) Agent() string

Agent returns the client's user agent.

func (*Context[T]) Authorization

func (c *Context[T]) Authorization() string

Authorization returns the authorization from the request header.

func (*Context[T]) BearerToken

func (c *Context[T]) BearerToken() string

BearerToken returns the bearer token from the request header.

func (*Context[T]) Err

func (c *Context[T]) Err(message string)

Err is a helper function to respond with an error status code (400).

func (*Context[T]) Forbidden

func (c *Context[T]) Forbidden(message string)

Forbidden is a helper function to respond with a forbidden status code (403).

func (*Context[T]) IP

func (c *Context[T]) IP() string

IP returns the client's IP address.

func (*Context[T]) InternalServerError

func (c *Context[T]) InternalServerError(message string)

InternalServerError is a helper function to respond with an internal server error status code (500).

func (*Context[T]) Locale

func (c *Context[T]) Locale() string

Locale returns the locale from the request header.

func (*Context[T]) LogDebug

func (c *Context[T]) LogDebug(msg ...any)

LogDebug logs the debug message.

func (*Context[T]) LogErr

func (c *Context[T]) LogErr(msg ...any)

LogErr logs the error message.

func (*Context[T]) LogInfo

func (c *Context[T]) LogInfo(msg ...any)

LogInfo logs the info message.

func (*Context[T]) OK

func (c *Context[T]) OK(data any, page ...*gorm.Pagination)

OK returns a successful response.

func (*Context[T]) OKDownload

func (c *Context[T]) OKDownload(bytes []byte, filename ...string)

OKDownload is a helper function to respond with a 200 status code and file.

func (*Context[T]) OKFile

func (c *Context[T]) OKFile(bytes []byte, filename ...string)

OKFile returns a file response.

func (*Context[T]) Page

func (c *Context[T]) Page() *gorm.Pagination

Page returns the pagination object from the request.

func (*Context[T]) Sort

func (c *Context[T]) Sort() *gorm.Sorting

Sort returns the sorting object from the request.

func (*Context[T]) TraceID

func (c *Context[T]) TraceID() string

TraceID returns the trace id from the request header.

func (*Context[T]) Unauthorized

func (c *Context[T]) Unauthorized(message string)

Unauthorized is a helper function to respond with an unauthorized status code (401).

type CornHandler

type CornHandler struct {
	Handler  func() `json:"-"`
	InitExec bool   `json:"init_exec"`
	Pattern  string `json:"pattern"`
}

type InitJobHandler

type InitJobHandler struct {
	Handler func() `json:"-"`
	After   bool   `json:"after"`
}

type MiddlewareHandler

type MiddlewareHandler struct {
	Handler    gin.HandlerFunc `json:"-"`
	MatchPaths []string        `json:"match_paths"`
	SkipPaths  []string        `json:"exclude"`
}

type RateLimitOpt

type RateLimitOpt struct {
	Rate     int64         `json:"rate"`
	Duration time.Duration `json:"duration"`
}

type Response

type Response struct {
	Success    bool             `json:"success"`
	Time       string           `json:"time"`
	TraceId    string           `json:"trace_id"`
	Duration   int64            `json:"duration"`
	Pagination *gorm.Pagination `json:"pagination,omitempty"`
	ErrMessage string           `json:"err_message,omitempty"`
	Data       any              `json:"data,omitempty"`
}

type TypescriptOpt

type TypescriptOpt struct {
	Models       []any    `json:"models"`
	FunctionName string   `json:"function_name"`
	Paths        []string `json:"paths"`
	Forms        []string `json:"forms"`
	Body         string   `json:"body"`
	Response     string   `json:"response"`
}

type WsHandler

type WsHandler struct {
	Handler gin.HandlerFunc `json:"-"`
	Path    string          `json:"path"`
}

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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