gateway

package
v0.0.0-...-4be293a Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: MIT Imports: 23 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorHandler

func ErrorHandler(ctx context.Context, mux *runtime.ServeMux, marshaler runtime.Marshaler, w http.ResponseWriter, r *http.Request, err error)

func IncomingHeaderMatcher

func IncomingHeaderMatcher(key string) (string, bool)

IncomingHeaderMatcher is the default incoming header matcher for the gateway.

It matches all Foundation headers and uses the default matcher for all other headers.

func OutgoingHeaderMatcher

func OutgoingHeaderMatcher(key string) (string, bool)

OutgoingHeaderMatcher is the default outgoing header matcher for the gateway.

It matches all Foundation headers and uses the default matcher for all other headers.

func RegisterServices

func RegisterServices(services []*Service, opts *RegisterServicesOptions) (http.Handler, error)

func WithAuthentication

func WithAuthentication(except []string) func(http.Handler) http.Handler

WithAuthentication is a middleware that forces the request to be authenticated

func WithAuthenticationDetails

func WithAuthenticationDetails(handler http.Handler, authenticate AuthenticationHandler) http.Handler

WithAuthenticationDetails is a middleware that fetches the authentication details using the given authentication function

func WithCORSEnabled

func WithCORSEnabled(options *CORSOptions) func(http.Handler) http.Handler

WithCORSEnabled is a middleware that enables CORS for the given handler.

func WithHydraAuthenticationDetails

func WithHydraAuthenticationDetails(handler http.Handler) http.Handler

WithHydraAuthenticationDetails is a middleware that fetches the authentication details using ORY Hydra

func WithRequestLogger

func WithRequestLogger(l *log.Entry) func(http.Handler) http.Handler

Types

type AuthenticationHandler

type AuthenticationHandler func(token string) (*AuthenticationResult, error)

AuthenticationHandler is a function that authenticates the request

type AuthenticationResult

type AuthenticationResult struct {
	// IsAuthenticated is true if the request is authenticated
	IsAuthenticated bool
	// ClientID is the OAuth2 client ID of the authenticated user (if any)
	ClientID string
	// UserID is the user ID of the authenticated user
	UserID string
	// Scope is the OAuth2 scope of the authenticated user
	Scope string
	// Metadata is the additional metadata for the authenticated user
	Metadata map[string]string
}

AuthenticationResult is the result of an authentication

type CORSOptions

type CORSOptions struct {
	// AllowedOrigin is the allowed origin for CORS.
	AllowedOrigin string
	// MaxAge is the max age for CORS.
	MaxAge *time.Duration
	// AllowedHeaders are the allowed headers for CORS.
	AllowedHeaders []string
	// ExposedHeaders are the exposed headers for CORS.
	ExposedHeaders []string
	// AllowedMethods are the allowed methods for CORS.
	AllowedMethods []string
}

CORSOptions represents the options for CORS.

func NewCORSOptions

func NewCORSOptions() *CORSOptions

type LoggingResponseWriter

type LoggingResponseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

LoggingResponseWriter is an http.ResponseWriter that tracks the status code of the response.

func NewLoggingResponseWriter

func NewLoggingResponseWriter(w http.ResponseWriter) *LoggingResponseWriter

NewLoggingResponseWriter creates a new loggingResponseWriter that wraps the provided http.ResponseWriter. If WriteHeader is not called, the response will implicitly return a status code of 200 OK.

func (*LoggingResponseWriter) WriteHeader

func (lrw *LoggingResponseWriter) WriteHeader(code int)

WriteHeader sets the status code of the response and calls the underlying ResponseWriter's WriteHeader method.

type RegisterServicesOptions

type RegisterServicesOptions struct {
	// Mux options
	MuxOpts []runtime.ServeMuxOption

	// TLS directory
	TLSDir string
}

type Service

type Service struct {
	// Name of the service, used for environment variable lookup in the form of `GRPC_<NAME>_ENDPOINT`
	Name string

	// Function to register the gRPC server endpoint
	Register func(context.Context, *runtime.ServeMux, string, []grpc.DialOption) error
}

Service represents a gRPC service that can be registered with the gateway.

Jump to

Keyboard shortcuts

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