feat: 实现网关服务的长连接功能

This commit is contained in:
fish
2026-03-28 19:57:20 +08:00
parent 03728d743e
commit be24b465b1
7 changed files with 379 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
package config
import (
"github.com/spf13/viper"
)
type Config struct {
Server ServerConfig
Redis RedisConfig
Services ServicesConfig
}
type ServerConfig struct {
Port int
}
type RedisConfig struct {
Addr string
Password string
DB int
}
type ServicesConfig struct {
UserService UserServiceConfig
}
type UserServiceConfig struct {
Addr string
}
func Load() (*Config, error) {
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath("./config")
viper.AddConfigPath("../config")
viper.AddConfigPath("../../config")
viper.SetDefault("server.port", 8000)
viper.SetDefault("redis.addr", "redis:6379")
viper.SetDefault("redis.password", "")
viper.SetDefault("redis.db", 0)
viper.SetDefault("services.userService.addr", "user-svc:9000")
if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
return nil, err
}
}
var config Config
if err := viper.Unmarshal(&config); err != nil {
return nil, err
}
return &config, nil
}