httpsvc

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Configs = configset.Set[Config]{
	Default: &Config{
		Addr:                 "0.0.0.0:" + sdkclient.DefaultPort,
		ServiceUrl:           sdkclient.DefaultLocalURL,
		H2C:                  httpH2CConfig{Enable: true},
		EnableGRPCReflection: true,
		CORS: CORSConfig{
			AllowedOrigins:   []string{"*"},
			AllowedMethods:   []string{"GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH", "HEAD"},
			AllowedHeaders:   []string{"*"},
			AllowCredentials: true,
		},
		Logger: LoggerConfig{
			NonimportantLevel: zap.NewAtomicLevelAt(zap.DebugLevel),
			ImportantLevel:    zap.NewAtomicLevelAt(zap.InfoLevel),
			ErrorsLevel:       zap.NewAtomicLevelAt(zap.WarnLevel),
			NonimportantRegexes: []string{
				`.*/List.*`,
				`.*/Get.*`,
				`/healthz`,
				`/readyz`,
				`/`,
			},
		},
	},
}

Functions

func GetT0 added in v0.6.3

func GetT0(ctx context.Context) time.Time

Types

type CORSConfig

type CORSConfig struct {
	AllowedOrigins   []string `koanf:"allowed_origins"`
	AllowedMethods   []string `koanf:"allowed_methods"`
	AllowedHeaders   []string `koanf:"allowed_headers"`
	AllowCredentials bool     `koanf:"allow_credentials"`
}

type Config

type Config struct {
	// local server address, set to run server on different port
	Addr string `koanf:"addr"`

	// ak service url, used in client to connect to connect to specific ak server
	ServiceUrl string `koanf:"service_url"`

	H2C httpH2CConfig `koanf:"h2c"`

	// If not empty, write HTTP port to this file.
	// This is useful when starting with port 0, which means to get
	// the next port. This is done in testing to start on an unused
	// port to avoid conflict with an already running service.
	AddrFilename         string `koanf:"addr_filename"`
	EnableGRPCReflection bool   `koanf:"reflection"`

	Ngrok ngrokConfig `koanf:"ngrok"`

	Logger LoggerConfig `koanf:"logger"`

	CORS CORSConfig `koanf:"cors"`
}

type LoggerConfig

type LoggerConfig struct {
	ImportantLevel    zap.AtomicLevel `koanf:"important_log_level"`
	NonimportantLevel zap.AtomicLevel `koanf:"nonimportant_log_level"`
	ErrorsLevel       zap.AtomicLevel `koanf:"trace_errors_log_level"`

	// Requests that their paths matches any one of these regexes will be
	// logged in the nonimportant log level.
	NonimportantRegexes []string `koanf:"nonimportant_regexes"`
}

type RequestLogExtractor

type RequestLogExtractor func(*http.Request) []zap.Field

type Svc

type Svc interface {
	Mux() *http.ServeMux
	Addr() string // available only after start.
}

func New

func New(lc fx.Lifecycle, z *zap.Logger, cfg *Config, reflectors []string, extractors []RequestLogExtractor) (Svc, error)

Jump to

Keyboard shortcuts

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