gin

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2023 License: MIT Imports: 27 Imported by: 8

README

Gin

Doc Go Release Test Report Card Codecov License

Gin http driver for Goravel.

Version

goravel/gin goravel/framework
v1.0.2 v1.13.0

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"
)

"driver": "gin",

"drivers": map[string]any{
    ...
    "gin": map[string]any{
        "http": func() (http.Context, error) {
            return ginfacades.Http(), 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
	CacheFacade       cache.Cache
	LogFacade         log.Log
	RateLimiterFacade http.RateLimiter
	ValidationFacade  validation.Validation
)

Functions

func Background

func Background() http.Context

func GinResponseMiddleware

func GinResponseMiddleware() httpcontract.Middleware

func NewGinContext

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

func NewGinGroup

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

func NewGinRequest

func NewGinRequest(ctx *GinContext, log log.Log, validation validatecontract.Validation) httpcontract.Request

func NewGinStatus

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

func NewGinSuccess

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

Types

type BodyWriter

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

func (*BodyWriter) Body

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

func (*BodyWriter) Write

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

func (*BodyWriter) WriteString

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

type GinContext

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

func (*GinContext) Context

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

func (*GinContext) Deadline

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

func (*GinContext) Done

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

func (*GinContext) Err

func (c *GinContext) Err() error

func (*GinContext) Instance

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

func (*GinContext) Request

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

func (*GinContext) Response

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

func (*GinContext) Value

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

func (*GinContext) WithValue

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

type GinGroup

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

func (*GinGroup) Any

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

func (*GinGroup) Delete

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

func (*GinGroup) Get

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

func (*GinGroup) Group

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

func (*GinGroup) Middleware

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

func (*GinGroup) Options

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

func (*GinGroup) Patch

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

func (*GinGroup) Post

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

func (*GinGroup) Prefix

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

func (*GinGroup) Put

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

func (*GinGroup) Resource

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

func (*GinGroup) Static

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

func (*GinGroup) StaticFS

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

func (*GinGroup) StaticFile

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

type GinRequest

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

func (*GinRequest) AbortWithStatus

func (r *GinRequest) AbortWithStatus(code int)

func (*GinRequest) AbortWithStatusJson

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

func (*GinRequest) All

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

func (*GinRequest) Bind

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

func (*GinRequest) File

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

func (*GinRequest) Form

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

func (*GinRequest) FullUrl

func (r *GinRequest) FullUrl() string

func (*GinRequest) Header

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

func (*GinRequest) Headers

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

func (*GinRequest) Host

func (r *GinRequest) Host() string

func (*GinRequest) Input

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

func (*GinRequest) InputBool

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

func (*GinRequest) InputInt

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

func (*GinRequest) InputInt64

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

func (*GinRequest) Ip

func (r *GinRequest) Ip() string

func (*GinRequest) Json

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

func (*GinRequest) Method

func (r *GinRequest) Method() string

func (*GinRequest) Next

func (r *GinRequest) Next()

func (*GinRequest) Origin

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

func (*GinRequest) Path

func (r *GinRequest) Path() string

func (*GinRequest) Queries

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

func (*GinRequest) Query

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

func (*GinRequest) QueryArray

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

func (*GinRequest) QueryBool

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

func (*GinRequest) QueryInt

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

func (*GinRequest) QueryInt64

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

func (*GinRequest) QueryMap

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

func (*GinRequest) Route

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

func (*GinRequest) RouteInt

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

func (*GinRequest) RouteInt64

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

func (*GinRequest) Url

func (r *GinRequest) Url() string

func (*GinRequest) Validate

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

func (*GinRequest) ValidateRequest

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

type GinResponse

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

func NewGinResponse

func NewGinResponse(instance *gin.Context, origin httpcontract.ResponseOrigin) *GinResponse

func (*GinResponse) Data

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

func (*GinResponse) Download

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

func (*GinResponse) File

func (r *GinResponse) File(filepath string)

func (*GinResponse) Header

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

func (*GinResponse) Json

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

func (*GinResponse) Origin

func (*GinResponse) Redirect

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

func (*GinResponse) Status

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

func (*GinResponse) String

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

func (*GinResponse) Success

func (*GinResponse) Writer

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

type GinRoute

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

func NewGinRoute

func NewGinRoute(config config.Config) *GinRoute

func (*GinRoute) Fallback

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

func (*GinRoute) GlobalMiddleware

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

func (*GinRoute) Run

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

func (*GinRoute) RunTLS

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

func (*GinRoute) RunTLSWithCert

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

func (*GinRoute) ServeHTTP

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

type GinStatus

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

func (*GinStatus) Data

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

func (*GinStatus) Json

func (r *GinStatus) Json(obj any)

func (*GinStatus) String

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

type GinSuccess

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

func (*GinSuccess) Data

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

func (*GinSuccess) Json

func (r *GinSuccess) Json(obj any)

func (*GinSuccess) String

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

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)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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