httpsvc

package
v0.8.7 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 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{
			UnimportantLevel: zap.NewAtomicLevelAt(zap.DebugLevel),
			ImportantLevel:   zap.NewAtomicLevelAt(zap.InfoLevel),
			ErrorsLevel:      zap.NewAtomicLevelAt(zap.WarnLevel),
			UnimportantRegexes: []string{
				`^/autokitteh.+/(Get|List)$`,
				`^/oauth/|/oauth$|/save$`,
			},
			UnloggedRegexes: []string{
				`/(healthz|readyz)$`,
				`\.(css|html|ico|js|png|svg|txt|webmanifest)$`,
			},
		},
	},
}

Functions

func GetStartTime added in v0.8.6

func GetStartTime(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"`
	UnimportantLevel zap.AtomicLevel `koanf:"unimportant_log_level"`
	ErrorsLevel      zap.AtomicLevel `koanf:"trace_errors_log_level"`

	// URL requests with paths that match any one of these regular
	// expressions will be logged in the nonimportant log level.
	UnimportantRegexes []string `koanf:"nonimportant_regexes"`

	// URL requests with paths that match any one of these
	// regular expressions will not be logged at all.
	UnloggedRegexes []string `koanf:"unlogged_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