ginext

package
v0.0.602 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BodyBuffer

func BodyBuffer(g *gin.Context)

func CorsMiddleware

func CorsMiddleware(allowheader []string, exposeheader []string) gin.HandlerFunc

func SetJSONFilter

func SetJSONFilter(g *gin.Context, filter string)

func Wrap

func WrapHTTPHandler added in v0.0.588

func WrapHTTPHandler(w *GinWrapper, fn http.Handler) gin.HandlerFunc

func WrapHTTPHandlerFunc added in v0.0.588

func WrapHTTPHandlerFunc(w *GinWrapper, fn http.HandlerFunc) gin.HandlerFunc

Types

type AppContext

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

func CreateAppContext

func CreateAppContext(g *gin.Context, innerCtx context.Context, cancelFn context.CancelFunc) *AppContext

func CreateBackgroundAppContext

func CreateBackgroundAppContext() *AppContext

func (*AppContext) Cancel

func (ac *AppContext) Cancel()

func (*AppContext) Deadline

func (ac *AppContext) Deadline() (deadline time.Time, ok bool)

func (*AppContext) Done

func (ac *AppContext) Done() <-chan struct{}

func (*AppContext) Err

func (ac *AppContext) Err() error

func (*AppContext) RequestURI

func (ac *AppContext) RequestURI() string

func (*AppContext) Set

func (ac *AppContext) Set(key, value any)

func (*AppContext) Value

func (ac *AppContext) Value(key any) any

type GinRouteBuilder

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

func (*GinRouteBuilder) Handle

func (w *GinRouteBuilder) Handle(handler WHandlerFunc)

func (*GinRouteBuilder) HandleRawHTTPHandler added in v0.0.588

func (w *GinRouteBuilder) HandleRawHTTPHandler(f http.Handler)

func (*GinRouteBuilder) HandleRawHTTPHandlerFunc added in v0.0.588

func (w *GinRouteBuilder) HandleRawHTTPHandlerFunc(f http.HandlerFunc)

func (*GinRouteBuilder) Use

func (w *GinRouteBuilder) Use(middleware ...gin.HandlerFunc) *GinRouteBuilder

func (*GinRouteBuilder) WithJSONFilter

func (w *GinRouteBuilder) WithJSONFilter(filter string) *GinRouteBuilder

type GinRoutesWrapper

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

func (*GinRoutesWrapper) Any

func (w *GinRoutesWrapper) Any(relativePath string) *GinRouteBuilder

func (*GinRoutesWrapper) COUNT

func (w *GinRoutesWrapper) COUNT(relativePath string) *GinRouteBuilder

func (*GinRoutesWrapper) DELETE

func (w *GinRoutesWrapper) DELETE(relativePath string) *GinRouteBuilder

func (*GinRoutesWrapper) GET

func (w *GinRoutesWrapper) GET(relativePath string) *GinRouteBuilder

func (*GinRoutesWrapper) Group

func (w *GinRoutesWrapper) Group(relativePath string) *GinRoutesWrapper

func (*GinRoutesWrapper) HEAD

func (w *GinRoutesWrapper) HEAD(relativePath string) *GinRouteBuilder

func (*GinRoutesWrapper) OPTIONS

func (w *GinRoutesWrapper) OPTIONS(relativePath string) *GinRouteBuilder

func (*GinRoutesWrapper) PATCH

func (w *GinRoutesWrapper) PATCH(relativePath string) *GinRouteBuilder

func (*GinRoutesWrapper) POST

func (w *GinRoutesWrapper) POST(relativePath string) *GinRouteBuilder

func (*GinRoutesWrapper) PUT

func (w *GinRoutesWrapper) PUT(relativePath string) *GinRouteBuilder

func (*GinRoutesWrapper) Use

func (w *GinRoutesWrapper) Use(middleware ...gin.HandlerFunc) *GinRoutesWrapper

func (*GinRoutesWrapper) WithJSONFilter

func (w *GinRoutesWrapper) WithJSONFilter(filter string) *GinRoutesWrapper

type GinWrapper

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

func NewEngine

func NewEngine(opt Options) *GinWrapper

NewEngine creates a new (wrapped) ginEngine

func (*GinWrapper) DebugPrintRoutes

func (w *GinWrapper) DebugPrintRoutes()

func (*GinWrapper) ForwardRequest

func (w *GinWrapper) ForwardRequest(writer http.ResponseWriter, req *http.Request)

ForwardRequest manually inserts a request into this router = behaves as if the request came from the outside (and writes the response to `writer`)

func (*GinWrapper) ListRoutes

func (w *GinWrapper) ListRoutes() []gin.RouteInfo

func (*GinWrapper) ListenAndServeHTTP

func (w *GinWrapper) ListenAndServeHTTP(addr string, postInit func(port string)) (chan error, *http.Server)

func (*GinWrapper) NoRoute

func (w *GinWrapper) NoRoute(handler WHandlerFunc)

func (*GinWrapper) Routes

func (w *GinWrapper) Routes() *GinRoutesWrapper

func (*GinWrapper) ServeHTTP

func (w *GinWrapper) ServeHTTP(req *http.Request) *httptest.ResponseRecorder

ServeHTTP only used for unit tests

type HTTPErrorResponse

type HTTPErrorResponse interface {
	HTTPResponse

	Error() error
}

type HTTPResponse

type HTTPResponse interface {
	Write(g *gin.Context)
	WithHeader(k string, v string) HTTPResponse
	WithCookie(name string, value string, maxAge int, path string, domain string, secure bool, httpOnly bool) HTTPResponse
	IsSuccess() bool
}

func Data

func Data(sc int, contentType string, data []byte) HTTPResponse

func Download

func Download(mimetype string, filepath string, filename string) HTTPResponse

func DownloadData

func DownloadData(status int, mimetype string, filename string, data []byte) HTTPResponse

func ErrWrap

func ErrWrap(e error, errorType exerr.ErrorType, msg string) HTTPResponse

func Error

func Error(e error) HTTPResponse

func File

func File(mimetype string, filepath string) HTTPResponse

func JSON

func JSON(sc int, data any) HTTPResponse

func JSONWithFilter

func JSONWithFilter(sc int, data any, f string) HTTPResponse

func NotImplemented

func NotImplemented() HTTPResponse

func Redirect

func Redirect(sc int, newURL string) HTTPResponse

func Seekable

func Seekable(filename string, contentType string, data io.ReadSeeker) HTTPResponse

func Status

func Status(sc int) HTTPResponse

func Text

func Text(sc int, data string) HTTPResponse

type InspectableHTTPResponse

type InspectableHTTPResponse interface {
	HTTPResponse

	Statuscode() int
	BodyString(g *gin.Context) *string
	ContentType() string
	Headers() []string
}

type Options

type Options struct {
	AllowCors                *bool                                                          // Add cors handler to allow all CORS requests on the default http methods
	CorsAllowHeader          *[]string                                                      // override the default values of Access-Control-Allow-Headers (AllowCors must be true)
	CorsExposeHeader         *[]string                                                      // return Access-Control-Expose-Headers (AllowCors must be true)
	GinDebug                 *bool                                                          // Set gin.debug to true (adds more logs)
	SuppressGinLogs          *bool                                                          // Suppress our custom gin logs (even if GinDebug == true)
	BufferBody               *bool                                                          // Buffers the input body stream, this way the ginext error handler can later include the whole request body
	Timeout                  *time.Duration                                                 // The default handler timeout
	ListenerBeforeRequest    []func(g *gin.Context)                                         // Register listener that are called before the handler method
	ListenerAfterRequest     []func(g *gin.Context, resp HTTPResponse)                      // Register listener that are called after the handler method
	DebugTrimHandlerPrefixes []string                                                       // Trim these prefixes from the handler names in the debug print
	DebugReplaceHandlerNames map[string]string                                              // Replace handler names in debug output
	BuildRequestBindError    func(g *gin.Context, fieldtype string, err error) HTTPResponse // Override function which generates the HTTPResponse errors that are returned by the preContext..Start() methids
}

type PreContext

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

func (*PreContext) Body

func (pctx *PreContext) Body(body any) *PreContext

func (*PreContext) Form

func (pctx *PreContext) Form(form any) *PreContext

func (*PreContext) Header

func (pctx *PreContext) Header(header any) *PreContext

func (*PreContext) IgnoreWrongContentType

func (pctx *PreContext) IgnoreWrongContentType() *PreContext

func (*PreContext) Query

func (pctx *PreContext) Query(query any) *PreContext

func (*PreContext) RawBody

func (pctx *PreContext) RawBody(rawbody *[]byte) *PreContext

func (PreContext) Start

func (pctx PreContext) Start() (*AppContext, *gin.Context, *HTTPResponse)

func (*PreContext) URI

func (pctx *PreContext) URI(uri any) *PreContext

func (*PreContext) WithSession

func (pctx *PreContext) WithSession(sessionObj SessionObject) *PreContext

func (*PreContext) WithTimeout

func (pctx *PreContext) WithTimeout(to time.Duration) *PreContext

type SessionObject

type SessionObject interface {
	Init(g *gin.Context, ctx *AppContext) error
	Finish(ctx context.Context, resp HTTPResponse) error
}

type WHandlerFunc

type WHandlerFunc func(PreContext) HTTPResponse

func RedirectFound

func RedirectFound(newuri string) WHandlerFunc

func RedirectPermanent

func RedirectPermanent(newuri string) WHandlerFunc

func RedirectTemporary

func RedirectTemporary(newuri string) WHandlerFunc

Jump to

Keyboard shortcuts

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