mirror of
https://github.com/yusing/godoxy.git
synced 2026-01-11 22:30:47 +01:00
refactor(config): correct logic in InitFromFile
This commit is contained in:
@@ -3,12 +3,10 @@ package config
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/yusing/godoxy/internal/common"
|
||||
config "github.com/yusing/godoxy/internal/config/types"
|
||||
"github.com/yusing/godoxy/internal/notif"
|
||||
@@ -62,11 +60,6 @@ func Load() error {
|
||||
cfgWatcher = watcher.NewConfigFileWatcher(common.ConfigFileName)
|
||||
|
||||
initErr := state.InitFromFile(common.ConfigPath)
|
||||
if errors.Is(initErr, fs.ErrNotExist) {
|
||||
// log only
|
||||
log.Warn().Msg("config file not found, using default config")
|
||||
initErr = nil
|
||||
}
|
||||
err := errors.Join(initErr, state.StartProviders())
|
||||
if err != nil {
|
||||
logNotifyError("init", err)
|
||||
|
||||
@@ -5,7 +5,9 @@ import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"iter"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -19,7 +21,6 @@ import (
|
||||
"github.com/yusing/godoxy/agent/pkg/agent"
|
||||
"github.com/yusing/godoxy/internal/acl"
|
||||
"github.com/yusing/godoxy/internal/autocert"
|
||||
"github.com/yusing/godoxy/internal/common"
|
||||
config "github.com/yusing/godoxy/internal/config/types"
|
||||
"github.com/yusing/godoxy/internal/entrypoint"
|
||||
homepage "github.com/yusing/godoxy/internal/homepage/types"
|
||||
@@ -92,10 +93,13 @@ func Value() *config.Config {
|
||||
}
|
||||
|
||||
func (state *state) InitFromFile(filename string) error {
|
||||
data, err := os.ReadFile(common.ConfigPath)
|
||||
data, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
state.Config = config.DefaultConfig()
|
||||
return err
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
state.Config = config.DefaultConfig()
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return state.Init(data)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user