mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-06 19:52:33 +02:00

Some checks are pending
Docker Image CI (socket-proxy) / build (push) Waiting to run
* refactor: simplify io code and make utils module independent * fix(docker): agent and socket-proxy docker event flushing with modified reverse proxy handler * refactor: remove unused code * refactor: remove the use of logging module in most code * refactor: streamline domain mismatch check in certState function * tweak: use ecdsa p-256 for autocert * fix(tests): update health check tests for invalid host and add case for port in host * feat(acme): custom acme directory * refactor: code refactor and improved context and error handling * tweak: optimize memory usage under load * fix(oidc): restore old user matching behavior * docs: add ChatGPT assistant to README --------- Co-authored-by: yusing <yusing@6uo.me>
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package widgets
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/yusing/go-proxy/internal/gperr"
|
|
"github.com/yusing/go-proxy/internal/serialization"
|
|
)
|
|
|
|
type (
|
|
Config struct {
|
|
Provider string `json:"provider"`
|
|
Config Widget `json:"config"`
|
|
}
|
|
Widget interface {
|
|
Initialize(ctx context.Context, url string, cfg map[string]any) error
|
|
Data(ctx context.Context) ([]NameValue, error)
|
|
}
|
|
NameValue struct {
|
|
Name string `json:"name"`
|
|
Value string `json:"value"`
|
|
}
|
|
)
|
|
|
|
const (
|
|
WidgetProviderQbittorrent = "qbittorrent"
|
|
)
|
|
|
|
var widgetProviders = map[string]struct{}{
|
|
WidgetProviderQbittorrent: {},
|
|
}
|
|
|
|
var ErrInvalidProvider = gperr.New("invalid provider")
|
|
|
|
func (cfg *Config) UnmarshalMap(m map[string]any) error {
|
|
var ok bool
|
|
cfg.Provider, ok = m["provider"].(string)
|
|
if !ok {
|
|
return ErrInvalidProvider.Withf("non string")
|
|
}
|
|
if _, ok := widgetProviders[cfg.Provider]; !ok {
|
|
return ErrInvalidProvider.Subject(cfg.Provider)
|
|
}
|
|
delete(m, "provider")
|
|
m, ok = m["config"].(map[string]any)
|
|
if !ok {
|
|
return gperr.New("invalid config")
|
|
}
|
|
return serialization.MapUnmarshalValidate(m, &cfg.Config)
|
|
}
|