gin

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: MIT Imports: 26 Imported by: 3

README

Gin

Doc Go Release Test Report Card Codecov License

Gin http driver for Goravel.

Version

goravel/gin goravel/framework
v1.1.x v1.13.x

Install

  1. Add package
go get -u github.com/goravel/gin
  1. Register service provider, make sure it is registered first.
// config/app.go
import "github.com/goravel/gin"

"providers": []foundation.ServiceProvider{
    &gin.ServiceProvider{},
    ...
}
  1. Add gin config to config/http.go file
// config/http.go
import (
    ginfacades "github.com/goravel/gin/facades"
)

"default": "gin",

"drivers": map[string]any{
    ...
    "gin": map[string]any{
        "context": func() (http.Context, error) {
            return ginfacades.Context(), nil
        },
        "route": func() (route.Engine, error) {
            return ginfacades.Route(), nil
        },
    },
}

Testing

Run command below to run test:

go test ./...

Documentation

Index

Constants

View Source
const HttpBinding = "goravel.gin.http"
View Source
const RouteBinding = "goravel.gin.route"

Variables

View Source
var (
	ConfigFacade     config.Config
	LogFacade        log.Log
	ValidationFacade validation.Validation
)

Functions

func Background

func Background() http.Context

func NewContext added in v1.1.0

func NewContext(ctx *gin.Context) http.Context

func NewGinStatus

func NewGinStatus(instance *gin.Context, code int) httpcontract.ResponseSuccess

func NewGinSuccess

func NewGinSuccess(instance *gin.Context) httpcontract.ResponseSuccess

func NewGroup added in v1.1.0

func NewGroup(instance gin.IRouter, prefix string, originMiddlewares []httpcontract.Middleware, lastMiddlewares []httpcontract.Middleware) route.Route

func NewRequest added in v1.1.0

func NewRequest(ctx *Context, log log.Log, validation validatecontract.Validation) httpcontract.Request

func ResponseMiddleware added in v1.1.0

func ResponseMiddleware() httpcontract.Middleware

Types

type BodyWriter

type BodyWriter struct {
	gin.ResponseWriter
	// contains filtered or unexported fields
}

func (*BodyWriter) Body

func (w *BodyWriter) Body() *bytes.Buffer

func (*BodyWriter) Header added in v1.1.0

func (w *BodyWriter) Header() http.Header

func (*BodyWriter) Write

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

func (*BodyWriter) WriteString

func (w *BodyWriter) WriteString(s string) (int, error)

type Context added in v1.1.0

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

func (*Context) Context added in v1.1.0

func (c *Context) Context() context.Context

func (*Context) Deadline added in v1.1.0

func (c *Context) Deadline() (deadline time.Time, ok bool)

func (*Context) Done added in v1.1.0

func (c *Context) Done() <-chan struct{}

func (*Context) Err added in v1.1.0

func (c *Context) Err() error

func (*Context) Instance added in v1.1.0

func (c *Context) Instance() *gin.Context

func (*Context) Request added in v1.1.0

func (c *Context) Request() http.Request

func (*Context) Response added in v1.1.0

func (c *Context) Response() http.Response

func (*Context) Value added in v1.1.0

func (c *Context) Value(key any) any

func (*Context) WithValue added in v1.1.0

func (c *Context) WithValue(key string, value any)

type Group added in v1.1.0

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

func (*Group) Any added in v1.1.0

func (r *Group) Any(relativePath string, handler httpcontract.HandlerFunc)

func (*Group) Delete added in v1.1.0

func (r *Group) Delete(relativePath string, handler httpcontract.HandlerFunc)

func (*Group) Get added in v1.1.0

func (r *Group) Get(relativePath string, handler httpcontract.HandlerFunc)

func (*Group) Group added in v1.1.0

func (r *Group) Group(handler route.GroupFunc)

func (*Group) Middleware added in v1.1.0

func (r *Group) Middleware(middlewares ...httpcontract.Middleware) route.Route

func (*Group) Options added in v1.1.0

func (r *Group) Options(relativePath string, handler httpcontract.HandlerFunc)

func (*Group) Patch added in v1.1.0

func (r *Group) Patch(relativePath string, handler httpcontract.HandlerFunc)

func (*Group) Post added in v1.1.0

func (r *Group) Post(relativePath string, handler httpcontract.HandlerFunc)

func (*Group) Prefix added in v1.1.0

func (r *Group) Prefix(addr string) route.Route

func (*Group) Put added in v1.1.0

func (r *Group) Put(relativePath string, handler httpcontract.HandlerFunc)

func (*Group) Resource added in v1.1.0

func (r *Group) Resource(relativePath string, controller httpcontract.ResourceController)

func (*Group) Static added in v1.1.0

func (r *Group) Static(relativePath, root string)

func (*Group) StaticFS added in v1.1.0

func (r *Group) StaticFS(relativePath string, fs http.FileSystem)

func (*Group) StaticFile added in v1.1.0

func (r *Group) StaticFile(relativePath, filepath string)

type Request added in v1.1.0

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

func (*Request) AbortWithStatus added in v1.1.0

func (r *Request) AbortWithStatus(code int)

func (*Request) AbortWithStatusJson added in v1.1.0

func (r *Request) AbortWithStatusJson(code int, jsonObj any)

func (*Request) All added in v1.1.0

func (r *Request) All() map[string]any

func (*Request) Bind added in v1.1.0

func (r *Request) Bind(obj any) error

func (*Request) File added in v1.1.0

func (r *Request) File(name string) (filesystemcontract.File, error)

func (*Request) Form added in v1.1.0

func (r *Request) Form(key string, defaultValue ...string) string

func (*Request) FullUrl added in v1.1.0

func (r *Request) FullUrl() string

func (*Request) Header added in v1.1.0

func (r *Request) Header(key string, defaultValue ...string) string

func (*Request) Headers added in v1.1.0

func (r *Request) Headers() http.Header

func (*Request) Host added in v1.1.0

func (r *Request) Host() string

func (*Request) Input added in v1.1.0

func (r *Request) Input(key string, defaultValue ...string) string

func (*Request) InputBool added in v1.1.0

func (r *Request) InputBool(key string, defaultValue ...bool) bool

func (*Request) InputInt added in v1.1.0

func (r *Request) InputInt(key string, defaultValue ...int) int

func (*Request) InputInt64 added in v1.1.0

func (r *Request) InputInt64(key string, defaultValue ...int64) int64

func (*Request) Ip added in v1.1.0

func (r *Request) Ip() string

func (*Request) Json added in v1.1.0

func (r *Request) Json(key string, defaultValue ...string) string

func (*Request) Method added in v1.1.0

func (r *Request) Method() string

func (*Request) Next added in v1.1.0

func (r *Request) Next()

func (*Request) Origin added in v1.1.0

func (r *Request) Origin() *http.Request

func (*Request) Path added in v1.1.0

func (r *Request) Path() string

func (*Request) Queries added in v1.1.0

func (r *Request) Queries() map[string]string

func (*Request) Query added in v1.1.0

func (r *Request) Query(key string, defaultValue ...string) string

func (*Request) QueryArray added in v1.1.0

func (r *Request) QueryArray(key string) []string

func (*Request) QueryBool added in v1.1.0

func (r *Request) QueryBool(key string, defaultValue ...bool) bool

func (*Request) QueryInt added in v1.1.0

func (r *Request) QueryInt(key string, defaultValue ...int) int

func (*Request) QueryInt64 added in v1.1.0

func (r *Request) QueryInt64(key string, defaultValue ...int64) int64

func (*Request) QueryMap added in v1.1.0

func (r *Request) QueryMap(key string) map[string]string

func (*Request) Route added in v1.1.0

func (r *Request) Route(key string) string

func (*Request) RouteInt added in v1.1.0

func (r *Request) RouteInt(key string) int

func (*Request) RouteInt64 added in v1.1.0

func (r *Request) RouteInt64(key string) int64

func (*Request) Url added in v1.1.0

func (r *Request) Url() string

func (*Request) Validate added in v1.1.0

func (r *Request) Validate(rules map[string]string, options ...validatecontract.Option) (validatecontract.Validator, error)

func (*Request) ValidateRequest added in v1.1.0

func (r *Request) ValidateRequest(request httpcontract.FormRequest) (validatecontract.Errors, error)

type Response added in v1.1.0

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

func NewResponse added in v1.1.0

func NewResponse(instance *gin.Context, origin httpcontract.ResponseOrigin) *Response

func (*Response) Data added in v1.1.0

func (r *Response) Data(code int, contentType string, data []byte)

func (*Response) Download added in v1.1.0

func (r *Response) Download(filepath, filename string)

func (*Response) File added in v1.1.0

func (r *Response) File(filepath string)

func (*Response) Header added in v1.1.0

func (r *Response) Header(key, value string) httpcontract.Response

func (*Response) Json added in v1.1.0

func (r *Response) Json(code int, obj any)

func (*Response) Origin added in v1.1.0

func (r *Response) Origin() httpcontract.ResponseOrigin

func (*Response) Redirect added in v1.1.0

func (r *Response) Redirect(code int, location string)

func (*Response) Status added in v1.1.0

func (r *Response) Status(code int) httpcontract.ResponseStatus

func (*Response) String added in v1.1.0

func (r *Response) String(code int, format string, values ...any)

func (*Response) Success added in v1.1.0

func (r *Response) Success() httpcontract.ResponseSuccess

func (*Response) Writer added in v1.1.0

func (r *Response) Writer() http.ResponseWriter

type Route added in v1.1.0

type Route struct {
	route.Route
	// contains filtered or unexported fields
}

func NewRoute added in v1.1.0

func NewRoute(config config.Config) *Route

func (*Route) Fallback added in v1.1.0

func (r *Route) Fallback(handler httpcontract.HandlerFunc)

func (*Route) GlobalMiddleware added in v1.1.0

func (r *Route) GlobalMiddleware(middlewares ...httpcontract.Middleware)

func (*Route) Run added in v1.1.0

func (r *Route) Run(host ...string) error

func (*Route) RunTLS added in v1.1.0

func (r *Route) RunTLS(host ...string) error

func (*Route) RunTLSWithCert added in v1.1.0

func (r *Route) RunTLSWithCert(host, certFile, keyFile string) error

func (*Route) ServeHTTP added in v1.1.0

func (r *Route) ServeHTTP(writer http.ResponseWriter, request *http.Request)

type ServiceProvider

type ServiceProvider struct {
}

func (*ServiceProvider) Boot

func (receiver *ServiceProvider) Boot(app foundation.Application)

func (*ServiceProvider) Register

func (receiver *ServiceProvider) Register(app foundation.Application)

type Status added in v1.1.0

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

func (*Status) Data added in v1.1.0

func (r *Status) Data(contentType string, data []byte)

func (*Status) Json added in v1.1.0

func (r *Status) Json(obj any)

func (*Status) String added in v1.1.0

func (r *Status) String(format string, values ...any)

type Success added in v1.1.0

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

func (*Success) Data added in v1.1.0

func (r *Success) Data(contentType string, data []byte)

func (*Success) Json added in v1.1.0

func (r *Success) Json(obj any)

func (*Success) String added in v1.1.0

func (r *Success) String(format string, values ...any)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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