gingo

package module
v0.0.0-...-530df61 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2025 License: MIT Imports: 11 Imported by: 0

README

gingo

This project attempts to wrap around Gin and Gorm, to make them play nice together.

It started with me being unsatisfied with the error messages provided by the validation in Gin, but my goal is to make database validation, kind of like Laravel does it, and more. But we'll see where it goes.

I am still fairly new to the world of Go, so any suggestions or improvements are more than welcome.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitializeCacneCleanup

func InitializeCacneCleanup()

Types

type CachedFieldInfo

type CachedFieldInfo struct {
	JSONFieldMap   map[string]string
	RequiredFields []string
	LastAccessedAt time.Time
}

type Context

type Context struct {
	*gin.Context
	// contains filtered or unexported fields
}

func (*Context) Handler

func (c *Context) Handler() HandlerFunc

Handler returns the main handler.

func (*Context) HandlerName

func (c *Context) HandlerName() string

HandlerName returns the main handler's name. For example if the handler is "handleGetUsers()", this function will return "main.handleGetUsers".

func (*Context) HandlerNames

func (c *Context) HandlerNames() []string

HandlerNames returns a list of all registered handlers for this context in descending order, following the semantics of HandlerName()

func (*Context) Next

func (c *Context) Next()

Next is a convenience method to call Next on the underlying gin.Context

func (*Context) Reset

func (c *Context) Reset()

Reset prepares the context for reuse

func (*Context) ShouldBind

func (c *Context) ShouldBind(obj interface{}) error

ShouldBind checks the Method and Content-Type to select a binding engine automatically, Depending on the "Content-Type" header different bindings are used, for example:

"application/json" --> JSON binding
"application/xml"  --> XML binding

It parses the request's body as JSON if Content-Type == "application/json" using JSON or XML as a JSON input. It decodes the json payload into the struct specified as a pointer. Like c.Bind() but this method does not set the response status code to 400 or abort if input is not valid.

func (*Context) ShouldBindBodyWith

func (c *Context) ShouldBindBodyWith(obj interface{}, bb binding.BindingBody) (err error)

ShouldBindBodyWith is similar with ShouldBindWith, but it stores the request body into the context, and reuse when it is called again.

NOTE: This method reads the body before binding. So you should use ShouldBindWith for better performance if you need to call only once.

func (*Context) ShouldBindBodyWithJSON

func (c *Context) ShouldBindBodyWithJSON(obj interface{}) error

ShouldBindBodyWithJSON is a shortcut for c.ShouldBindBodyWith(obj, binding.JSON).

func (*Context) ShouldBindBodyWithPlain

func (c *Context) ShouldBindBodyWithPlain(obj interface{}) error

ShouldBindBodyWithPlain is a shortcut for c.ShouldBindBodyWith(obj, binding.Plain).

func (*Context) ShouldBindBodyWithTOML

func (c *Context) ShouldBindBodyWithTOML(obj interface{}) error

ShouldBindBodyWithTOML is a shortcut for c.ShouldBindBodyWith(obj, binding.TOML).

func (*Context) ShouldBindBodyWithXML

func (c *Context) ShouldBindBodyWithXML(obj interface{}) error

ShouldBindBodyWithXML is a shortcut for c.ShouldBindBodyWith(obj, binding.XML).

func (*Context) ShouldBindBodyWithYAML

func (c *Context) ShouldBindBodyWithYAML(obj interface{}) error

ShouldBindBodyWithYAML is a shortcut for c.ShouldBindBodyWith(obj, binding.YAML).

func (*Context) ShouldBindHeader

func (c *Context) ShouldBindHeader(obj interface{}) error

ShouldBindHeader is a shortcut for c.ShouldBindWith(obj, binding.Header).

func (*Context) ShouldBindJSON

func (c *Context) ShouldBindJSON(obj interface{}) error

ShouldBindJSON is a shortcut for c.ShouldBindWith(obj, binding.JSON).

func (*Context) ShouldBindPlain

func (c *Context) ShouldBindPlain(obj interface{}) error

ShouldBindPlain is a shortcut for c.ShouldBindWith(obj, binding.Plain).

func (*Context) ShouldBindQuery

func (c *Context) ShouldBindQuery(obj interface{}) error

ShouldBindQuery is a shortcut for c.ShouldBindWith(obj, binding.Query).

func (*Context) ShouldBindTOML

func (c *Context) ShouldBindTOML(obj interface{}) error

ShouldBindTOML is a shortcut for c.ShouldBindWith(obj, binding.TOML).

func (*Context) ShouldBindUri

func (c *Context) ShouldBindUri(obj interface{}) error

ShouldBindUri binds the passed struct pointer using the specified binding engine.

func (*Context) ShouldBindWith

func (c *Context) ShouldBindWith(obj interface{}, b binding.Binding) error

ShouldBindWith binds the passed struct pointer using the specified binding engine. See the binding package.

func (*Context) ShouldBindXML

func (c *Context) ShouldBindXML(obj interface{}) error

ShouldBindXML is a shortcut for c.ShouldBindWith(obj, binding.XML).

func (*Context) ShouldBindYAML

func (c *Context) ShouldBindYAML(obj interface{}) error

ShouldBindYAML is a shortcut for c.ShouldBindWith(obj, binding.YAML).

type Engine

type Engine struct {
	*gin.Engine
	// contains filtered or unexported fields
}

func Default

func Default(opts ...OptionFunc) *Engine

Default returns an Engine instance with the Logger and Recovery middleware already attached.

func New

func New(opts ...OptionFunc) *Engine

New returns a new blank Engine instance without any middleware attached. By default, the configuration is: - RedirectTrailingSlash: true - RedirectFixedPath: false - HandleMethodNotAllowed: false - ForwardedByClientIP: true - UseRawPath: false - UnescapePathValues: true

func (*Engine) DELETE

func (engine *Engine) DELETE(relativePath string, handlers ...HandlerFunc)

func (*Engine) GET

func (engine *Engine) GET(relativePath string, handlers ...HandlerFunc)

func (*Engine) Handle

func (engine *Engine) Handle(httpMethod string, relativePath string, handlers ...HandlerFunc)

func (*Engine) OPTIONS

func (engine *Engine) OPTIONS(relativePath string, handlers ...HandlerFunc)

func (*Engine) PATCH

func (engine *Engine) PATCH(relativePath string, handlers ...HandlerFunc)

func (*Engine) POST

func (engine *Engine) POST(relativePath string, handlers ...HandlerFunc)

func (*Engine) PUT

func (engine *Engine) PUT(relativePath string, handlers ...HandlerFunc)

func (*Engine) With

func (engine *Engine) With(opts ...OptionFunc) *Engine

type HandlerChain

type HandlerChain []HandlerFunc

type HandlerFunc

type HandlerFunc func(*Context)

type HookManager

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

HookManager manages hooks for different lifecycle events

func NewHookManager

func NewHookManager() *HookManager

NewHookManager creates a new hook manager

func (*HookManager) RegisterHook

func (m *HookManager) RegisterHook(hookType HookType, hook HandlerFunc)

RegisterHook adds a hook for a specific lifecycle event

type HookType

type HookType int

HookType represents different hook points in the request lifecycle

const (
	BeforeRequest HookType = iota
	AfterRequest
	AfterPanic
)

type OptionFunc

type OptionFunc func(*Engine)

type RouteDefinition

type RouteDefinition struct {
	Method                string
	Path                  string
	RequestHandler        HandlerFunc
	PreRequestMiddleware  HandlerChain
	PostRequestMiddleware HandlerChain
	Description           string
	Tags                  []string
}

type RouterGroup

type RouterGroup struct {
	*gin.RouterGroup
}

Jump to

Keyboard shortcuts

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