config

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Dev     = "dev"
	Prod    = "prod"
	Test    = "test"
	Staging = "staging"
)

应用环境

View Source
const (
	VarPath  string = "var"
	LogPath         = VarPath + "/logs"
	TempPath        = VarPath + "/tmp"
)

Variables

View Source
var AmsFileAllow = struct {
	Image      FileAllow
	Audio      FileAllow
	Video      FileAllow
	Document   FileAllow
	Compressed FileAllow
}{
	Image:      FileAllow{AllowMimeType: []string{"png", "jpg", "jpeg", "gif", "bmp"}, AllowCapacitySize: 5 * MB},
	Audio:      FileAllow{AllowMimeType: []string{"mp3", "wav", "flac", "mid", "mov", "m4a"}, AllowCapacitySize: 20 * MB},
	Video:      FileAllow{AllowMimeType: []string{"mp4", "mpg", "avi", "wmv", "mov", "flv", "rmvb", "3gp", "m4v", "mkv"}, AllowCapacitySize: 2 * GB},
	Document:   FileAllow{AllowMimeType: []string{"pdf", "docx", "doc", "xlsx", "xls", "pptx", "ppt", "cvs", "txt", "markdown", "html"}, AllowCapacitySize: 50 * MB},
	Compressed: FileAllow{AllowMimeType: []string{"zip", "rar", "tar", "tar.gz", "gz", "tgz", "tbz2", "tbz"}, AllowCapacitySize: 500 * MB},
}

AmsFileAllow 管理端上传限制

View Source
var AnonymousFileAllow = struct {
	File FileAllow
}{
	File: FileAllow{AllowMimeType: []string{"pdf", "doc", "docx", "ppt", "pptx", "xls", "xlsx"}, AllowCapacitySize: 20 * MB},
}

AnonymousFileAllow 匿名用户上传限制

View Source
var UserFileAllow = struct {
	Image FileAllow
	Audio FileAllow
	Video FileAllow
}{
	Image: FileAllow{AllowMimeType: []string{"png", "jpg", "jpeg", "gif"}, AllowCapacitySize: 5 * MB},
	Audio: FileAllow{AllowMimeType: []string{"mp3", "wav", "flac", "mid", "mov", "m4a"}, AllowCapacitySize: 20 * MB},
	Video: FileAllow{AllowMimeType: []string{"mp4", "mpg", "avi", "wmv", "mov", "flv", "rmvb", "3gp", "m4v", "mkv"}, AllowCapacitySize: 100 * MB},
}

UserFileAllow 终端用户上传限制

Functions

This section is empty.

Types

type AppConfig

type AppConfig struct {
	Name        string `mapstructure:"name"`
	Environment string `mapstructure:"environment"`
	Debug       bool   `mapstructure:"debug"`
	Domain      string `mapstructure:"domain"`
}

AppConfig 应用基本配置

type ByteSize

type ByteSize int64
const (
	B ByteSize = 1 << (10 * iota)
	KB
	MB
	GB
	TB
)

func (ByteSize) String

func (b ByteSize) String() string

func (ByteSize) ToInt

func (b ByteSize) ToInt() int64

type Cache

type Cache struct {
	Driver     string `mapstructure:"driver"`
	Serializer string `mapstructure:"serializer"`
}

Cache 应用缓存

type ClusterConfig

type ClusterConfig struct {
	Addrs    []string `mapstructure:"addrs"`
	Password string   `mapstructure:"password"`
}

type Config

type Config struct {
	App          AppConfig      `mapstructure:"app"`
	Server       Server         `mapstructure:"server"`
	Security     Security       `mapstructure:"security"`
	Database     DatabaseConfig `mapstructure:"database"`
	Redis        Redis          `mapstructure:"redis"`
	Cache        Cache          `mapstructure:"cache"`
	MessageQueue MessageQueue   `mapstructure:"message_queue"`
	Etcd         Etcd           `mapstructure:"etcd"`
	Storage      Storage        `mapstructure:"storage"`
	Monitor      Monitor        `mapstructure:"monitor"`
	ThirdParty   ThirdParty     `mapstructure:"third_party"`
}

Config 应用配置

var GlobalConfig *Config

func LoadConfig

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

LoadConfig 加载配置

type DatabaseConfig

type DatabaseConfig struct {
	Migration       Migration     `mapstructure:"migration"`
	Driver          string        `mapstructure:"driver"`
	Host            string        `mapstructure:"host"`
	Port            int           `mapstructure:"port"`
	Username        string        `mapstructure:"username"`
	Password        string        `mapstructure:"password"`
	Database        string        `mapstructure:"database"`
	MaxOpenConns    int           `mapstructure:"max_open_conns"`
	MaxIdleConns    int           `mapstructure:"max_idle_conns"`
	ConnMaxLifetime time.Duration `mapstructure:"conn_max_lifetime"`
}

DatabaseConfig 数据库配置

type Etcd

type Etcd struct {
	GRPC etcdItem `mapstructure:"grpc"`
}

type EventConfig

type EventConfig struct {
	Enabled bool   `mapstructure:"enabled"`
	Driver  string `mapstructure:"driver"`
}

EventConfig 事件消费者服务配置

type FileAllow

type FileAllow struct {
	// 允许上传的文件类型
	AllowMimeType []string
	// 允许上传的文件容量大小(单位:字节)
	AllowCapacitySize ByteSize
}

type GRPCConfig

type GRPCConfig struct {
	Enabled   bool   `mapstructure:"enabled"`
	Host      string `mapstructure:"host"`
	Port      int    `mapstructure:"port"`
	Namespace string `mapstructure:"namespace"`
}

GRPCConfig gRPC配置

type HTTPConfig

type HTTPConfig struct {
	Enabled bool   `mapstructure:"enabled"`
	Host    string `mapstructure:"host"`
	Port    int    `mapstructure:"port"`
}

HTTPConfig HTTP服务配置

type HealthConfig

type HealthConfig struct {
	Enabled bool `mapstructure:"enabled"`
	Port    int  `mapstructure:"port"`
}

type MessageQueue

type MessageQueue struct {
	Enabled bool   `mapstructure:"enabled"`
	Driver  string `mapstructure:"driver"`
	Amqp    amqp   `mapstructure:"amqp"`
}

MessageQueue 消息队列配置

type Migration

type Migration struct {
	Enabled bool `mapstructure:"enabled"`
}

type Monitor

type Monitor struct {
	ServiceName    string `mapstructure:"service_name"`
	ServiceVersion string `mapstructure:"service_version"`
	Tracer         otlp   `mapstructure:"tracer"`
	Metrics        otlp   `mapstructure:"metrics"`
	Log            otlp   `mapstructure:"log"`
}

Monitor 平台监控配置

type PoolConfig

type PoolConfig struct {
	MinIdleConns int `mapstructure:"min_idle_conns"`
	MaxRetries   int `mapstructure:"max_retries"`
	PoolSize     int `mapstructure:"pool_size"`
}

type Redis

type Redis struct {
	Main  RedisItem `mapstructure:"main"`
	Cache RedisItem `mapstructure:"cache"`
	MQ    RedisItem `mapstructure:"mq"`
}

Redis redis配置

type RedisItem

type RedisItem struct {
	// 单机模式配置
	Host      string `mapstructure:"host"`
	Port      string `mapstructure:"port"`
	Password  string `mapstructure:"password"`
	DB        int    `mapstructure:"db"`
	KeyPrefix string `mapstructure:"key_prefix"`

	// 模式选择: standalone, cluster, sentinel
	Mode string `mapstructure:"mode"`

	// 集群模式配置
	Cluster ClusterConfig `mapstructure:"cluster"`

	// 哨兵模式配置
	Sentinel SentinelConfig `mapstructure:"sentinel"`

	// 连接池配置
	Pool PoolConfig `mapstructure:"pool"`
}

type Security

type Security struct {
	JWT struct {
		Secret string `mapstructure:"secret"`
	} `mapstructure:"jwt"`
}

Security 安全配置

type SentinelConfig

type SentinelConfig struct {
	MasterName       string   `mapstructure:"master_name"`
	SentinelAddrs    []string `mapstructure:"sentinel_addrs"`
	Password         string   `mapstructure:"password"`
	SentinelPassword string   `mapstructure:"sentinel_password"`
	DB               int      `mapstructure:"db"`
}

type Server

type Server struct {
	HTTP      HTTPConfig      `mapstructure:"http"`
	GRPC      GRPCConfig      `mapstructure:"grpc"`
	WebSocket WebSocketConfig `mapstructure:"websocket"`
	Event     EventConfig     `mapstructure:"event"`
	Health    HealthConfig    `mapstructure:"health"`
}

Server 服务配置

type Storage

type Storage struct {
	Driver    string       `mapstructure:"driver"`
	CdnDomain string       `mapstructure:"cdn_domain"`
	Local     local        `mapstructure:"local"`
	MinIO     cloudStorage `mapstructure:"minio"`
	AliOss    cloudStorage `mapstructure:"ali_oss"`
	HwObs     cloudStorage `mapstructure:"hw_obs"`
	TxCos     cloudStorage `mapstructure:"tx_cos"`
	S3        cloudStorage `mapstructure:"s3"`
}

type ThirdParty

type ThirdParty struct {
	Wx  wx  `mapstructure:"wx"`
	TTS tts `mapstructure:"tts"`
}

ThirdParty 第三方服务

type WebSocketConfig

type WebSocketConfig struct {
	Enabled bool   `mapstructure:"enabled"`
	Host    string `mapstructure:"host"`
	Port    int    `mapstructure:"port"`
}

WebSocketConfig WebSocket配置

Jump to

Keyboard shortcuts

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