http

package
v0.2.19 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const Module = "transport.http"

Variables

This section is empty.

Functions

func DefaultClientMiddlewares

func DefaultClientMiddlewares() []middleware.Middleware

DefaultClientMiddlewares provides a default set of client-side middlewares for HTTP services.

func DefaultServerMiddlewares

func DefaultServerMiddlewares() []middleware.Middleware

DefaultServerMiddlewares provides a default set of server-side middlewares for HTTP services. These are essential for ensuring basic stability and observability.

func NewClient added in v0.2.7

func NewClient(ctx context.Context, httpConfig *httpv1.Client, clientOpts *ClientOptions) (*transhttp.Client, error)

NewClient creates a new concrete HTTP client connection based on the provided configuration. It returns *transhttp.Client, not the generic contracts.Client.

func NewCorsHandler

func NewCorsHandler(config *corsv1.Cors, codeOpts ...CorsOption) (func(http.Handler) http.Handler, error)

NewCorsHandler creates a Kratos filter for CORS by merging framework defaults, the base configuration from proto, and advanced, code-based functional options.

func NewServer added in v0.2.7

func NewServer(httpConfig *httpv1.Server, serverOpts *ServerOptions) (*transhttp.Server, error)

NewServer creates a new concrete HTTP server instance based on the provided configuration. It returns *transhttp.Server, not the generic contracts.Server.

func RegisterPprof added in v0.2.13

func RegisterPprof(srv *transhttp.Server)

RegisterPprof registers the pprof handlers with the HTTP server.

func WithClientMiddlewares added in v0.2.13

func WithClientMiddlewares(mws map[string]middleware.Middleware) options.Option

WithClientMiddlewares adds a map of named client middlewares.

func WithClientOptions added in v0.2.13

func WithClientOptions(opts ...transhttp.ClientOption) options.Option

WithClientOptions appends Kratos HTTP client options.

func WithDiscoveries added in v0.2.13

func WithDiscoveries(discoveries map[string]registry.Discovery) options.Option

WithDiscoveries adds a map of named service discovery clients.

func WithRegistrar added in v0.2.13

func WithRegistrar(registrar transport.HTTPRegistrar) options.Option

WithRegistrar sets the HTTP registrar.

func WithServerOptions added in v0.2.13

func WithServerOptions(opts ...transhttp.ServerOption) options.Option

WithServerOptions appends Kratos HTTP server options.

Types

type ClientOptions

type ClientOptions struct {
	// ClientOptions allows passing native Kratos HTTP client dial options.
	ClientOptions []transhttp.ClientOption

	// ClientMiddlewares holds a map of named client middlewares.
	ClientMiddlewares map[string]middleware.Middleware

	// Discoveries holds a map of named service discovery clients.
	Discoveries map[string]registry.Discovery
}

ClientOptions is a container for HTTP client-specific options.

func FromClientOptions

func FromClientOptions(opts []options.Option) *ClientOptions

FromClientOptions creates a new HTTP ClientOptions struct.

type CorsOption

type CorsOption func(*cors.Options)

CorsOption defines a functional option for configuring advanced CORS settings in code.

func WithAllowOriginFunc

func WithAllowOriginFunc(f func(origin string) bool) CorsOption

WithAllowOriginFunc sets the AllowOriginFunc.

type ServerOptions

type ServerOptions struct {
	// ServerOptions allows passing native Kratos HTTP server options.
	ServerOptions []transhttp.ServerOption

	// CorsOptions allows applying advanced, code-based configurations.
	CorsOptions []CorsOption

	// Registrar is the HTTP registrar to use.
	Registrar transport.HTTPRegistrar

	// ServerMiddlewares holds a map of named server middlewares.
	ServerMiddlewares map[string]middleware.Middleware
	Context           context.Context
}

ServerOptions is a container for HTTP server-specific options.

func FromServerOptions

func FromServerOptions(opts []options.Option) *ServerOptions

FromServerOptions creates a new HTTP ServerOptions struct.

Jump to

Keyboard shortcuts

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