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