Files
workspace/code/go-project/base-farmework/configs/app/config.go
T
2025-08-11 21:32:08 +08:00

42 lines
579 B
Go

package app
import (
"time"
"github.com/spf13/viper"
)
type ServerConfig struct {
Port int
}
type JWTConfig struct {
Secret string
Expiry time.Duration
}
var (
Server ServerConfig
JWT JWTConfig
)
func InitAppConfig(configPath string) (error, error) {
v := viper.New()
v.SetConfigFile(configPath)
v.SetConfigType("yaml")
if err := v.ReadInConfig(); err != nil {
return err, nil
}
if err := v.UnmarshalKey("server", &Server); err != nil {
return err, nil
}
if err := v.UnmarshalKey("jwt", &JWT); err != nil {
return err, nil
}
return nil, nil
}