GoDoxy/internal/homepage/widgets/widgets.go
Yuzerion 4a8bd48ad5
Some checks are pending
Docker Image CI (socket-proxy) / build (push) Waiting to run
fix: optimize memory usage, fix agent and code refactor (#118)
* 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>
2025-05-25 09:45:57 +08:00

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)
}