config

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2025 License: Apache-2.0 Imports: 16 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindConfigToContext

func BindConfigToContext(ctx context.Context) context.Context

BindConfigToContext binds the configuration to the context.

func Reload

func Reload() error

Reload reloads the configuration from the file.

func Watch

func Watch(callback func(*Config))

Watch watches the configuration file and reloads it when it changes.

Types

type Auth

type Auth struct {
	JWT                    *JWT     `json:"jwt" yaml:"jwt"`
	Casbin                 *Casbin  `json:"casbin" yaml:"casbin"`
	Whitelist              []string `json:"whitelist" yaml:"whitelist"`
	MaxSessions            int      `json:"max_sessions" yaml:"max_sessions"`
	SessionCleanupInterval int      `json:"session_cleanup_interval" yaml:"session_cleanup_interval"`
}

Auth auth config struct

type Casbin

type Casbin struct {
	Path  string
	Model string
}

Casbin casbin config struct

type Config

type Config struct {
	AppName     string       `yaml:"app_name" json:"app_name"`
	Environment string       `yaml:"environment" json:"environment"`
	Protocol    string       `yaml:"protocol" json:"protocol"`
	Domain      string       `yaml:"domain" json:"domain"`
	Host        string       `yaml:"host" json:"host"`
	Port        int          `yaml:"port" json:"port"`
	GRPC        *GRPC        `yaml:"grpc" json:"grpc"`
	Consul      *Consul      `yaml:"consul" json:"consul"`
	Observes    *Observes    `yaml:"observes" json:"observes"`
	Extension   *Extension   `yaml:"extension" json:"extension"`
	Frontend    *Frontend    `yaml:"frontend" json:"frontend"`
	Logger      *Logger      `yaml:"logger" json:"logger"`
	Data        *Data        `yaml:"data" json:"data"`
	Auth        *Auth        `yaml:"auth" json:"auth"`
	Storage     *Storage     `yaml:"storage" json:"storage"`
	OAuth       *OAuth       `yaml:"oauth" json:"oauth"`
	Email       *Email       `yaml:"email" json:"email"`
	Viper       *viper.Viper `yaml:"-" json:"-"`
}

Config represents the configuration implementation.

func GetConfig

func GetConfig() (*Config, error)

GetConfig returns the configuration. It does not handle errors internally; instead, it returns the error for the caller to handle.

func Init

func Init() (cfg *Config, err error)

Init initializes and loads the configuration.

func LoadConfig

func LoadConfig(configPath string) (*Config, error)

LoadConfig loads the configuration from the file.

func (*Config) IsProd added in v0.1.6

func (c *Config) IsProd(envs ...string) bool

IsProd returns current environment is production

type Consul

type Consul struct {
	Address   string `yaml:"address" json:"address"`
	Scheme    string `yaml:"scheme" json:"scheme"`
	Discovery struct {
		DefaultTags   []string          `yaml:"default_tags" json:"default_tags"`
		DefaultMeta   map[string]string `yaml:"default_meta" json:"default_meta"`
		HealthCheck   bool              `yaml:"health_check" json:"health_check"`
		CheckInterval string            `yaml:"check_interval" json:"check_interval"`
		Timeout       string            `yaml:"timeout" json:"timeout"`
	} `yaml:"discovery" json:"discovery"`
}

Consul config struct

type DBNode

type DBNode = dc.DBNode

DBNode represents a database node

type Data

type Data = dc.Config

Data represents the data configuration

type Email

type Email = email.Email

Email represents the email configuration

type Extension

type Extension = ec.Config

Extension represents the extension configuration

type Frontend

type Frontend struct {
	SignInURL string `json:"sign_in_url" yaml:"sign_in_url"`
	SignUpURL string `json:"sign_up_url" yaml:"sign_up_url"`
}

Frontend frontend config struct

type GRPC added in v0.1.4

type GRPC struct {
	Enabled bool   `yaml:"enabled" json:"enabled"`
	Host    string `yaml:"host" json:"host"`
	Port    int    `yaml:"port" json:"port"`
}

type JWT

type JWT struct {
	Secret string
	Expiry time.Duration
}

JWT jwt config struct

type Logger

type Logger = lc.Config

Logger represents the logger configuration

type OAuth

type OAuth = oc.Config

OAuth represents the OAuth configuration

type Observes

type Observes struct {
	Sentry *Sentry
	Tracer *Tracer
}

Observes config struct

type Sentry

type Sentry struct {
	Endpoint string `json:"endpoint" yaml:"endpoint"`
}

Sentry config struct

type Storage

type Storage = storage.Config

Storage represents the storage configuration

type Tracer

type Tracer struct {
	Endpoint string
}

Tracer config struct

Jump to

Keyboard shortcuts

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