mirror of
https://github.com/by-jp/www.byjp.me.git
synced 2025-08-09 22:16:07 +01:00
Syndicate is working! Instagra & Pixelfed demonstrated with the new post attached. Lots of TODOs, but functional enough :)
37 lines
724 B
Go
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
|
|
}
|