mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-23 17:28:53 +02:00
initial gotify support
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/yusing/go-proxy/internal/common"
|
||||
"github.com/yusing/go-proxy/internal/config/types"
|
||||
E "github.com/yusing/go-proxy/internal/error"
|
||||
"github.com/yusing/go-proxy/internal/notif"
|
||||
"github.com/yusing/go-proxy/internal/route"
|
||||
proxy "github.com/yusing/go-proxy/internal/route/provider"
|
||||
"github.com/yusing/go-proxy/internal/task"
|
||||
@@ -148,48 +149,59 @@ func (cfg *Config) StartProxyProviders() {
|
||||
}
|
||||
|
||||
func (cfg *Config) load() (res E.Error) {
|
||||
b := E.NewBuilder("errors loading config")
|
||||
defer b.To(&res)
|
||||
errs := E.NewBuilder("errors loading config")
|
||||
defer errs.To(&res)
|
||||
|
||||
logger.Debug("loading config")
|
||||
defer logger.Debug("loaded config")
|
||||
|
||||
data, err := E.Check(os.ReadFile(common.ConfigPath))
|
||||
if err != nil {
|
||||
b.Add(E.FailWith("read config", err))
|
||||
logrus.Fatal(b.Build())
|
||||
errs.Add(E.FailWith("read config", err))
|
||||
logrus.Fatal(errs.Build())
|
||||
}
|
||||
|
||||
if !common.NoSchemaValidation {
|
||||
if err = Validate(data); err != nil {
|
||||
b.Add(E.FailWith("schema validation", err))
|
||||
logrus.Fatal(b.Build())
|
||||
errs.Add(E.FailWith("schema validation", err))
|
||||
logrus.Fatal(errs.Build())
|
||||
}
|
||||
}
|
||||
|
||||
model := types.DefaultConfig()
|
||||
if err := E.From(yaml.Unmarshal(data, model)); err != nil {
|
||||
b.Add(E.FailWith("parse config", err))
|
||||
logrus.Fatal(b.Build())
|
||||
errs.Add(E.FailWith("parse config", err))
|
||||
logrus.Fatal(errs.Build())
|
||||
}
|
||||
|
||||
// errors are non fatal below
|
||||
b.Add(cfg.initAutoCert(&model.AutoCert))
|
||||
b.Add(cfg.loadProviders(&model.Providers))
|
||||
errs.Add(cfg.initNotification(model.Providers.Notification))
|
||||
errs.Add(cfg.initAutoCert(&model.AutoCert))
|
||||
errs.Add(cfg.loadRouteProviders(&model.Providers))
|
||||
|
||||
cfg.value = model
|
||||
route.SetFindMuxDomains(model.MatchDomains)
|
||||
return
|
||||
}
|
||||
|
||||
func (cfg *Config) initNotification(notifCfgMap types.NotificationConfigMap) (err E.Error) {
|
||||
if len(notifCfgMap) == 0 {
|
||||
return
|
||||
}
|
||||
errs := E.NewBuilder("errors initializing notification providers")
|
||||
|
||||
for name, notifCfg := range notifCfgMap {
|
||||
_, err := notif.RegisterProvider(cfg.task.Subtask(name), notifCfg)
|
||||
errs.Add(err)
|
||||
}
|
||||
return errs.Build()
|
||||
}
|
||||
|
||||
func (cfg *Config) initAutoCert(autocertCfg *types.AutoCertConfig) (err E.Error) {
|
||||
if cfg.autocertProvider != nil {
|
||||
return
|
||||
}
|
||||
|
||||
logger.Debug("initializing autocert")
|
||||
defer logger.Debug("initialized autocert")
|
||||
|
||||
cfg.autocertProvider, err = autocert.NewConfig(autocertCfg).GetProvider()
|
||||
if err != nil {
|
||||
err = E.FailWith("autocert provider", err)
|
||||
@@ -197,11 +209,11 @@ func (cfg *Config) initAutoCert(autocertCfg *types.AutoCertConfig) (err E.Error)
|
||||
return
|
||||
}
|
||||
|
||||
func (cfg *Config) loadProviders(providers *types.ProxyProviders) (outErr E.Error) {
|
||||
subtask := cfg.task.Subtask("load providers")
|
||||
func (cfg *Config) loadRouteProviders(providers *types.Providers) (outErr E.Error) {
|
||||
subtask := cfg.task.Subtask("load route providers")
|
||||
defer subtask.Finish("done")
|
||||
|
||||
errs := E.NewBuilder("errors loading providers")
|
||||
errs := E.NewBuilder("errors loading route providers")
|
||||
results := E.NewBuilder("loaded providers")
|
||||
defer errs.To(&outErr)
|
||||
|
||||
|
||||
@@ -2,22 +2,23 @@ package types
|
||||
|
||||
type (
|
||||
Config struct {
|
||||
Providers ProxyProviders `json:"providers" yaml:",flow"`
|
||||
Providers Providers `json:"providers" yaml:",flow"`
|
||||
AutoCert AutoCertConfig `json:"autocert" yaml:",flow"`
|
||||
ExplicitOnly bool `json:"explicit_only" yaml:"explicit_only"`
|
||||
MatchDomains []string `json:"match_domains" yaml:"match_domains"`
|
||||
TimeoutShutdown int `json:"timeout_shutdown" yaml:"timeout_shutdown"`
|
||||
RedirectToHTTPS bool `json:"redirect_to_https" yaml:"redirect_to_https"`
|
||||
}
|
||||
ProxyProviders struct {
|
||||
Files []string `json:"include" yaml:"include"` // docker, file
|
||||
Docker map[string]string `json:"docker" yaml:"docker"`
|
||||
Providers struct {
|
||||
Files []string `json:"include" yaml:"include"`
|
||||
Docker map[string]string `json:"docker" yaml:"docker"`
|
||||
Notification NotificationConfigMap `json:"notification" yaml:"notification"`
|
||||
}
|
||||
)
|
||||
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
Providers: ProxyProviders{},
|
||||
Providers: Providers{},
|
||||
TimeoutShutdown: 3,
|
||||
RedirectToHTTPS: false,
|
||||
}
|
||||
|
||||
5
internal/config/types/notif_config.go
Normal file
5
internal/config/types/notif_config.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package types
|
||||
|
||||
import "github.com/yusing/go-proxy/internal/notif"
|
||||
|
||||
type NotificationConfigMap map[string]notif.ProviderConfig
|
||||
Reference in New Issue
Block a user