gateway

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GatewayRequest       = "x-gateway-request"
	GatewayURL           = "x-gateway-url"
	GatewaySessionCookie = "ory_kratos_session"
	GatewayAPIKey        = "X-Session-Token"
	APIKey               = "X-API-KEYID"
	APIKeyToken          = "X-API-TOKEN"
	GatewayMethod        = "x-gateway-method"
	UserAgent            = "x-gateway-user-agent"
	Host                 = "x-gateway-host"
	RemoteAddr           = "x-gateway-remote-addr"
)

Paralus Gateway annotations

Variables

View Source
var ParalusGatewayAnnotator = func(ctx context.Context, r *http.Request) metadata.MD {
	return metadata.New(map[string]string{
		GatewayRequest: "true",
		GatewayURL:     r.URL.EscapedPath(),
		GatewayAPIKey:  r.Header.Get(GatewayAPIKey),
		APIKey:         r.Header.Get(APIKey),
		APIKeyToken:    r.Header.Get(APIKeyToken),
		GatewayMethod:  r.Method,
		UserAgent:      r.UserAgent(),
		Host:           r.Host,
		RemoteAddr:     r.RemoteAddr,
	})
}

ParalusGatewayAnnotator adds paralus gateway specific annotations

Functions

func CreateGateway

func CreateGateway(
	ctx context.Context,
	conn *grpc.ClientConn,
	serveMuxOptions []gwRuntime.ServeMuxOption,
	annotators []AnnotatorFunc,
	handlers ...HandlerFunc,
) (*gwRuntime.ServeMux, error)

CreateGateway returns new grpc gateway

func CreateGatewayEndpoint

func CreateGatewayEndpoint(
	ctx context.Context,
	endpoint string,
	serveMuxOptions []gwRuntime.ServeMuxOption,
	dialOptions []grpc.DialOption,
	annotators []AnnotatorFunc,
	handlers ...HandlerFromEndpoint,
) (*gwRuntime.ServeMux, error)

CreateGatewayEndpoint returns new grpc gateway

func NewParalusJSON

func NewParalusJSON() runtime.Marshaler

NewParalusJSON returns new grpc gateway paralus json marshaller

func Run

func Run(ctx context.Context, opts ...GatewayOption) error

Types

type AnnotatorFunc

type AnnotatorFunc func(context.Context, *http.Request) metadata.MD

AnnotatorFunc is the annotator function is for injecting metadata from http request into gRPC context

type Gateway

type Gateway struct {
	*http.Server // if you need gRPC gw,please use it
	// contains filtered or unexported fields
}

func ApplyGateway

func ApplyGateway(opts ...GatewayOption) *Gateway

func NewGateway

func NewGateway(ctx context.Context, opts ...GatewayOption) *Gateway

func (*Gateway) Endpoint

func (g *Gateway) Endpoint() (*url.URL, error)

func (*Gateway) Start

func (g *Gateway) Start(ctx context.Context) error

Start start the HTTP server.

func (*Gateway) Stop

func (g *Gateway) Stop(ctx context.Context) error

Stop stop the HTTP server.

type GatewayOption

type GatewayOption func(o *Gateway)

GatewayOption is gRPC Gateway option.

func WithAddress

func WithAddress(addr string) GatewayOption

func WithAnnotator

func WithAnnotator(annotator ...AnnotatorFunc) GatewayOption

WithAnnotator returns an Option to append some annotator

func WithConn

func WithConn(conn *grpc.ClientConn) GatewayOption

func WithEndpoint

func WithEndpoint(endpoint *url.URL) GatewayOption

func WithHandlers

func WithHandlers(handlers ...HandlerFunc) GatewayOption

func WithListener

func WithListener(lis net.Listener) GatewayOption

func WithNetwork

func WithNetwork(network string) GatewayOption

func WithServeMuxOptions

func WithServeMuxOptions(serveMuxOptions ...gwRuntime.ServeMuxOption) GatewayOption

func WithShutdownFunc

func WithShutdownFunc(f func()) GatewayOption

WithShutdownFunc returns an Option to register a function which will be called when server shutdown

func WithTLSConfig

func WithTLSConfig(c *tls.Config) GatewayOption

func WithTimeout

func WithTimeout(timeout time.Duration) GatewayOption

type HandlerFromEndpoint

type HandlerFromEndpoint func(ctx context.Context, mux *gwRuntime.ServeMux,
	endpoint string, opts []grpc.DialOption) error

HandlerFromEndpoint is the callback that the caller should implement to steps to reverse-proxy the HTTP/1 requests to gRPC handlerFromEndpoint http gw endPoint automatically dials to "endpoint" and closes the connection when "ctx" gets done.

type HandlerFunc

type HandlerFunc func(ctx context.Context, mux *gwRuntime.ServeMux, conn *grpc.ClientConn) error

Jump to

Keyboard shortcuts

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