yrun

package
v0.0.0-...-56f6100 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2024 License: MIT Imports: 65 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chain

func Chain(base http.Handler, interceptors ...HTTPInterceptor) http.Handler

Chain chains together interceptors (middleware), the first interceptor will be the outermost.

func ChainF

func ChainF(base func(http.ResponseWriter, *http.Request), interceptors ...HTTPInterceptor) http.Handler

func FromBytes

func FromBytes[T any](baseSchema, appSchema string, config []byte) (conf T, err error)

func ManageK8s

func ManageK8s(ctx context.Context, lg *slog.Logger, c HTTPConfig, cd HTTPConfig, mx *muxRegister) error

func NewMetric

func NewMetric(ctx context.Context, c MetricConfig) error

func NewO11y

func NewO11y(c O11yConfig) (O11y, O11yReg)

func NewTrace

func NewTrace(ctx context.Context, c TraceConfig) (http.Handler, error)

func Run

func Run[C, A any](r RunConfig[C, A]) (exitCode int)

Run is intended to be called as the sole function in main.

Types

type Config

type Config[AppConfig any] struct {
	O11y  O11yConfig
	HTTP  HTTPConfig
	Debug HTTPConfig
	GRPC  gRPCConfig
	App   AppConfig
}

Config is the base config type for all applications. It carries common config, and embeds application specific config

type HTTPConfig

type HTTPConfig struct {
	// host:port listening address
	Address string

	K8s struct {
		Enable bool

		GatewayNamespace string
		GatewayName      string
	}
}

HTTPConfig is the config for an http server

type HTTPInterceptor

type HTTPInterceptor = func(next http.Handler) http.Handler

type HTTPRegistrar

type HTTPRegistrar interface {
	Handle(string, http.Handler)
	Pattern(method, host, pattern string, handler func(http.ResponseWriter, *http.Request), interceptors ...HTTPInterceptor)
}

type LogConfig

type LogConfig struct {
	Format string
	Level  slog.Level
}

type MetricConfig

type MetricConfig struct{}

type O11y

type O11y struct {
	T trace.Tracer
	M metric.Meter
	L *slog.Logger
	H slog.Handler
}

func (O11y) Err

func (o O11y) Err(ctx context.Context, msg string, err error, attrs ...slog.Attr) error

func (O11y) HTTPErr

func (o O11y) HTTPErr(ctx context.Context, msg string, err error, rw http.ResponseWriter, code int, attrs ...slog.Attr)

func (O11y) Region

func (o O11y) Region(ctx context.Context, name string, do func(ctx context.Context, span trace.Span) error) error

func (O11y) Sub

func (o O11y) Sub(name string) O11y

type O11yConfig

type O11yConfig struct {
	Log    LogConfig
	Metric MetricConfig
	Trace  TraceConfig
}

type O11yReg

type O11yReg struct {
	LogZpage   http.Handler
	TraceZpage http.Handler
}

type RunConfig

type RunConfig[C, A any] struct {

	// A cue schema, all config should be under the "App" key.
	AppConfigSchema string
	// New creates an application struct from the application config struct.
	New func(context.Context, C, *blob.Bucket, O11y) (*A, error)
	// HTTP is for registering http handlers to the main listener
	HTTP func(*A, HTTPRegistrar)
	// Debug is for registering http handlers to the debug handler
	Debug func(*A, HTTPRegistrar)
	// StartTasks should use the given function to start any background tasks.
	// Tasks should exit when the given context is canceled.
	StartTasks func(*A, context.Context, func(func() error))
	// RegisterShutdown should use the given function to start any tasks
	// that should run on shutdown.
	// shutdown tasks are given a context with a 5 second timeout.
	RegisterShutdown func(*A, context.Context, func(func(context.Context) error))
}

RunConfig are the args passed to Run. It takes 2 type parameters: C is the application config type, A is the application type.

type Store

type Store[T proto.Message] struct {
	// contains filtered or unexported fields
}

func NewStore

func NewStore[T any, P storer[T]](ctx context.Context, bkt *blob.Bucket, key string, init func() P) (*Store[P], error)

func (*Store[T]) Do

func (s *Store[T]) Do(ctx context.Context, f func(T))

func (*Store[T]) RDo

func (s *Store[T]) RDo(ctx context.Context, f func(T))

func (*Store[T]) Sync

func (s *Store[T]) Sync(ctx context.Context)

type TraceConfig

type TraceConfig struct{}

Jump to

Keyboard shortcuts

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