www.byjp.me/tools/syndicate/services/tracker.go
2023-11-12 09:47:58 +00:00

35 lines
698 B
Go

package services
import (
"fmt"
"github.com/by-jp/www.byjp.me/tools/syndicate/shared"
)
type List struct {
available map[string]shared.Service
}
func New() *List {
return &List{}
}
func (l *List) Load(name string, siteConfig any) (shared.Service, error) {
svc, err := shared.Load(name, siteConfig)
if err != nil {
return nil, fmt.Errorf("couldn't load service %s: %w", name, err)
}
l.available[name] = svc
return svc, nil
}
func (l *List) Init(service string) error {
if svc, ok := l.available[service]; ok {
return svc.Connect(false)
}
return fmt.Errorf("service %s not available", service)
}
func (l *List) Service(name string) shared.Service {
return l.available[name]
}