add swagger

This commit is contained in:
yanghao05
2023-06-09 14:32:21 +08:00
parent 37bf456102
commit 3f27dee0b2
23 changed files with 245 additions and 89 deletions

View File

@@ -1,9 +1,11 @@
package config
import (
"log"
"os"
"path/filepath"
"github.com/pkg/errors"
"github.com/rogeecn/atom/container"
"github.com/spf13/viper"
)
@@ -14,15 +16,15 @@ func Load(file, app string) (*viper.Viper, error) {
if file == "" {
v.SetConfigType("toml")
v.SetConfigName(app)
v.SetConfigName(app + ".toml")
//execute path
// execute path
execPath, err := os.Executable()
if err == nil {
v.AddConfigPath(filepath.Dir(execPath))
}
//home path
// home path
homePath, err := os.UserHomeDir()
if err == nil {
v.AddConfigPath(homePath)
@@ -39,10 +41,13 @@ func Load(file, app string) (*viper.Viper, error) {
v.SetConfigFile(file)
}
if err := v.ReadInConfig(); err != nil {
return nil, err
err := v.ReadInConfig()
log.Println("config file:", v.ConfigFileUsed())
if err != nil {
return nil, errors.Wrap(err, "config file read error")
}
err := container.Container.Provide(func() (*viper.Viper, error) {
err = container.Container.Provide(func() (*viper.Viper, error) {
return v, nil
})
if err != nil {