config

package
v0.0.0-...-f9738e6 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	ID             string
	Name           string
	Version        string
	Env            string
	Server         *ServerConfig
	Signature      *Signature
	Log            *Logger
	Pool           *Pool
	Email          *Email
	JWT            *JWT
	Http           *Http
	Logging        *Logging
	Authentication *Authentication
	Tracing        *Tracing
	Client         []*Client
	Database       map[string]*Database
	Redis          map[string]*Redis
	Loader         map[string]string
	Captcha        map[string]*Captcha
	RateLimit      bool
	Metrics        bool
	Prometheus     []*Prometheus
}

type Authentication

type Authentication struct {
	EnableGrpc bool
	DB         string
	Prefix     string
	Redis      string
	RoleKey    string
	Whitelist  map[string]bool
	SkipRole   []string
}

type Backend

type Backend struct {
	Target string
	Weight *int64
}

type Captcha

type Captcha struct {
	Type     string
	Length   int
	Expire   time.Duration
	Redis    string
	Height   int
	Width    int
	Skew     float64
	DotCount int
	Refresh  bool
	IpLimit  int
	Template string
}

type Client

type Client struct {
	Server    string
	Type      string
	Timeout   time.Duration
	Metadata  map[string]string
	Backends  []Backend
	Signature *Signature
	Tls       *Tls
}

type Config

type Config interface {
	SetAppInfo(id, name, version string)
	Load() error
	Scan(v any) error
	Value(key string) Value
	Watch(key string, o WatchHandleFunc)
	ScanWatch(key string, o WatchHandleFunc)
	Close() error
	App() *App
	IsInit() bool
}

func Instance

func Instance() Config

func New

func New(source kratosConfig.Source) Config

type Cors

type Cors struct {
	AllowCredentials    bool
	AllowOrigins        []string
	AllowMethods        []string
	AllowHeaders        []string
	ExposeHeaders       []string
	MaxAge              time.Duration
	AllowPrivateNetwork bool
}

type DBConfig

type DBConfig struct {
	TablePrefix    string
	Connect        DBConnect
	LogLevel       int
	PrepareStmt    bool
	DryRun         bool
	TransformError *DBTransformError
	SlowThreshold  time.Duration
	MaxLifetime    time.Duration
	MaxOpenConn    int
	MaxIdleConn    int
	Initializer    *DBInitializer
}

type DBConnect

type DBConnect struct {
	Username string
	Password string
	Host     string
	Port     int
	Option   string
	DBName   string
}

type DBErrorFormat

type DBErrorFormat struct {
	Duplicated *string
	AddForeign *string
	DelForeign *string
}

type DBInitializer

type DBInitializer struct {
	Enable bool
	Force  bool
	Path   string
}

type DBTransformError

type DBTransformError struct {
	Enable bool
	Format *DBErrorFormat
}

type Database

type Database struct {
	Enable     bool
	Drive      string
	AutoCreate bool
	Connect    DBConnect
	Config     DBConfig
}

type Email

type Email struct {
	User     string
	Name     string
	Password string
	Host     string
	Port     int
	Template map[string]EmailTemplate
}

type EmailTemplate

type EmailTemplate struct {
	Subject string
	Path    string
	Enable  *bool
	From    string
	Type    string
}

type GrpcService

type GrpcService struct {
	Network     string
	Addr        string
	Host        string
	Port        int
	MaxRecvSize int
	Timeout     time.Duration
}

type Http

type Http struct {
	EnableLog        bool
	RetryCount       int
	RetryWaitTime    time.Duration
	MaxRetryWaitTime time.Duration
	Timeout          time.Duration
	Server           string
}

type HttpService

type HttpService struct {
	Network        string
	Addr           string
	Host           string
	Port           int
	Timeout        time.Duration
	FormatResponse bool
	Cors           *Cors
	Marshal        *Marshal
	Pprof          *Pprof
}

type JWT

type JWT struct {
	EnableGrpc bool
	Redis      string
	Header     string
	Secret     string
	Unique     bool
	UniqueKey  string
	Expire     time.Duration
	Renewal    time.Duration
	Whitelist  map[string]bool
}

type Logger

type Logger struct {
	Level      string
	Output     []string
	Encode     string
	Caller     bool
	CallerSkip *int
	File       *LoggerFile
}

type LoggerFile

type LoggerFile struct {
	Name      string
	MaxSize   int
	MaxBackup int
	MaxAge    int
	Compress  bool
	LocalTime bool
}

type Logging

type Logging struct {
	Enable    bool
	Whitelist map[string]bool
}

type Marshal

type Marshal struct {
	ForceUseJson    bool
	EmitUnpopulated bool
	UseProtoNames   bool
}

type Pool

type Pool struct {
	Size             int
	ExpiryDuration   time.Duration
	PreAlloc         bool
	MaxBlockingTasks int
	Nonblocking      bool
}

type Pprof

type Pprof struct {
	Query  string
	Secret string
}

type Prometheus

type Prometheus struct {
	Name       string
	Type       string
	Help       string
	Namespace  string
	Subsystem  string
	Buckets    []float64
	Labels     []string
	Objectives map[float64]float64
	MaxAge     time.Duration
	AgeBuckets uint32
	BufCap     uint32
}

type Redis

type Redis struct {
	Enable   bool
	Name     string
	Host     string
	Username string
	Password string
}

type ServerConfig

type ServerConfig struct {
	Count    int
	Registry *string
	Http     *HttpService
	Grpc     *GrpcService
	Tls      *Tls
}

type Signature

type Signature struct {
	Enable    bool
	Ak        string
	Sk        string
	Whitelist map[string]bool
	Expire    time.Duration
}

type Tls

type Tls struct {
	Name string
	Ca   string
	Pem  string
	Key  string
}

type Tracing

type Tracing struct {
	HttpEndpoint string
	SampleRatio  *float32
	Timeout      time.Duration
	Insecure     *bool
}

type Value

type Value interface {
	kratosConfig.Value
}

type WatchHandleFunc

type WatchHandleFunc func(Value)

type Watcher

type Watcher func(key string, o WatchHandleFunc)

Jump to

Keyboard shortcuts

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