www.byjp.me/tools/syndicate/shared/services.go
JP Hastings-Spital c135910850 Working pixelfed & insta posting
Syndicate is working! Instagra & Pixelfed demonstrated with the new post attached.

Lots of TODOs, but functional enough :)
2023-11-12 07:43:08 +00:00

37 lines
724 B
Go

package shared
import (
"fmt"
)
var serviceTypes = make(map[string]ServiceCreator)
func Register(name string, svc ServiceCreator) {
serviceTypes[name] = svc
}
func Load(name string, config any) (Service, error) {
cfgMap, ok := config.(map[string]any)
if !ok {
return nil, fmt.Errorf("invalid config for '%s' service", name)
}
var serviceType string
if t, ok := cfgMap["type"].(string); ok {
serviceType = t
} else {
serviceType = name
}
svc, ok := serviceTypes[serviceType]
if !ok {
return nil, fmt.Errorf("unknown service type: %s", serviceType)
}
instance, err := svc(cfgMap)
if err != nil {
return nil, fmt.Errorf("unable to create '%s' service: %w", name, err)
}
return instance, nil
}