stdpubprivrpcfx

package
v0.0.173 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New[PUBRO, PUBRW, PRIVRW, PRIVRWC any](deps struct {
	fx.In
	fx.Lifecycle

	Config              Config
	BasePath            BasePath
	Logger              *zap.Logger
	Validator           protovalidate.Validator
	AuthMiddleware      *authn.Middleware
	HealthCheck         HealthCheck
	PublicReadOnly      PUBRO
	PublicReadWrite     PUBRW
	PrivateReadWrite    PRIVRW
	NewPublicReadOnly   func(svc PUBRO, opts ...connect.HandlerOption) (string, http.Handler)
	NewPublicReadWrite  func(svc PUBRW, opts ...connect.HandlerOption) (string, http.Handler)
	NewPrivateReadWrite func(svc PRIVRW, opts ...connect.HandlerOption) (string, http.Handler)

	// dependencies for building lambda relays.
	NewPrivateReadWriteClient func(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) PRIVRWC
	LambdaRelays              []*LambdaRelay[PRIVRWC] `group:"lambda_relays"`
}) (res struct {
	fx.Out

	Public  http.Handler `name:"public"`
	Private http.Handler `name:"private"`
}, err error,
)

func Provide

func Provide[PUBRO, PUBRW, PRIVRW, PRIVRWC any](
	newPubROFunc func(svc PUBRO, opts ...connect.HandlerOption) (string, http.Handler),
	newPubRWFunc func(svc PUBRW, opts ...connect.HandlerOption) (string, http.Handler),
	newprivRWFunc func(svc PRIVRW, opts ...connect.HandlerOption) (string, http.Handler),
	newPrivRWCFunc func(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) PRIVRWC,
) fx.Option

Provide the components as fx dependencies.

func ProvideBasePath added in v0.0.173

func ProvideBasePath(base string) fx.Option

func ProvideLambdaRelay

func ProvideLambdaRelay[C, E any](
	slug string,
	handler LambdaRelayHandler[C, E],
) fx.Option

func TestProvide

func TestProvide[PUBRO, PUBRW, PRIVRW, PUBROC, PUBRWC, PRIVRWC any](
	newPubROFunc func(svc PUBRO, opts ...connect.HandlerOption) (string, http.Handler),
	newPubRWFunc func(svc PUBRW, opts ...connect.HandlerOption) (string, http.Handler),
	newprivRWFunc func(svc PRIVRW, opts ...connect.HandlerOption) (string, http.Handler),
	newPubROCFunc func(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) PUBROC,
	newPubRWCFunc func(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) PUBRWC,
	newPrivRWCFunc func(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) PRIVRWC,
	clientOpts ...connect.ClientOption,
) fx.Option

TestProvide provides API clients for testing. We use the actual web public and private HTTP handler to get as much parity as possible.

Types

type BasePath added in v0.0.173

type BasePath struct{ V string }

type Config

type Config struct {
	// allow health endpoint to panic, for testing purposes.
	AllowForcedPanics bool `env:"ALLOW_FORCED_PANICS"`
	// response validation can be enabled in testing to catch errors early.
	ResponseValidation bool `env:"RESPONSE_VALIDATION"`
	// cache the pre-flight response more readily, it is not dynamic.
	CORSMaxAgeSeconds int `env:"CORS_MAX_AGE_SECONDS" envDefault:"3600"`
	// allow configuration of CORS allowed origins
	CORSAllowedOrigins []string `env:"CORS_ALLOWED_ORIGINS"`
	// contains filtered or unexported fields
}

type HealthCheck

type HealthCheck func(ctx context.Context, r *http.Request, isPrivate bool) error

type LambdaRelay

type LambdaRelay[C any] struct {
	Slug                       string
	CreateHandlerFromSysClient func(C) bhttp.HandlerFunc[context.Context]
}

type LambdaRelayHandler

type LambdaRelayHandler[C, E any] func(ctx context.Context, ev E, sys C) error

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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