gin

package
v2.0.12 Latest Latest
Warning

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

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

Documentation

Overview

SPDX-License-Identifier: Apache-2.0

Package gin provides some basic implementations for building routers based on gin-gonic/gin

Index

Constants

View Source
const NEGOTIATE = "negotiate"

NEGOTIATE defines the value of the OutputEncoding for the negotiated render

View Source
const Namespace = "github_com/luraproject/lura/router/gin"
View Source
const XML = "xml"
View Source
const YAML = "yaml"

Variables

EndpointHandler implements the HandlerFactory interface using the default ToHTTPError function

View Source
var ErrorResponseWriter = func(c *gin.Context, err error) {
	if te, ok := err.(encodedResponseError); ok && te.Encoding() != "" {
		c.Header("Content-Type", te.Encoding())
	}
	c.Writer.WriteString(err.Error())
}

ErrorResponseWriter writes the string representation of an error into the response body and sets a Content-Type header for errors that implement the encodedResponseError interface.

Functions

func DebugHandler

func DebugHandler(logger logging.Logger) gin.HandlerFunc

DebugHandler creates a dummy handler function, useful for quick integration tests

func DefaultFactory

func DefaultFactory(proxyFactory proxy.Factory, logger logging.Logger) router.Factory

DefaultFactory returns a gin router factory with the injected proxy factory and logger. It also uses a default gin router and the default HandlerFactory

func DefaultVicgFactory

func DefaultVicgFactory(vicgFactory VicgFactory, logger logging.Logger, opts ...Option) router.Factory

DefaultVicgFactory 创建用户代理工厂.

func EchoHandler

func EchoHandler() gin.HandlerFunc

EchoHandler creates a dummy handler function, useful for quick integration tests

func NewEngine

func NewEngine(cfg config.ServiceConfig, opt EngineOptions) *gin.Engine

NewEngine returns an initialized gin engine

func NewFactory

func NewFactory(cfg Config) router.Factory

NewFactory returns a gin router factory with the injected configuration

func NewRequest

func NewRequest(headersToSend []string) func(*gin.Context, []string) *proxy.Request

NewRequest gets a request from the current gin context and the received query string

func RegisterRender

func RegisterRender(name string, r Render)

RegisterRender allows clients to register their custom renders

Types

type BuildInfraFunc added in v2.0.8

type BuildInfraFunc func(ctx context.Context, cfg config.ExtraConfig) (infra interface{}, err error)

BuildInfraFunc 基于额外参数构建用户自定义结构.

type Config

type Config struct {
	Engine         *gin.Engine
	Middlewares    []gin.HandlerFunc
	HandlerFactory HandlerFactory
	ProxyFactory   proxy.Factory
	VicgFactory    VicgFactory
	Logger         logging.Logger
	RunServer      RunServerFunc
}

Config is the struct that collects the parts the router should be builded from

type EngineOptions

type EngineOptions struct {
	Logger    logging.Logger
	Writer    io.Writer
	Formatter gin.LogFormatter
	Health    <-chan string
}

type HandlerFactory

type HandlerFactory func(*config.EndpointConfig, proxy.Proxy) gin.HandlerFunc

HandlerFactory creates a handler function that adapts the gin router with the injected proxy

func CustomErrorEndpointHandler

func CustomErrorEndpointHandler(logger logging.Logger, errF server.ToHTTPError) HandlerFactory

CustomErrorEndpointHandler returns a HandlerFactory using the injected ToHTTPError function and logger

type Option added in v2.0.6

type Option func(*Config)

type Render

type Render func(*gin.Context, *proxy.Response)

Render defines the signature of the functions to be use for the final response encoding and rendering

type RunServerFunc

type RunServerFunc func(context.Context, config.ServiceConfig, http.Handler) error

RunServerFunc is a func that will run the http Server with the given params.

type VicgFactory added in v2.0.8

type VicgFactory interface {
	// New 基于用户自定义结构创建代理.
	New(cfg *config.EndpointConfig, infra interface{}) (proxy.Proxy, error)
	// BuildInfra 基于额外参数构建用户自定义结构.
	BuildInfra(ctx context.Context, cfg config.ExtraConfig) (infra interface{}, err error)
}

VicgFactory 用户自定义的代理工厂.

Jump to

Keyboard shortcuts

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