1
0
mirror of https://github.com/mrusme/neonmodem.git synced 2024-12-04 14:46:37 -05:00
neonmodem/system/system.go

54 lines
1.0 KiB
Go
Raw Normal View History

2022-12-28 22:22:36 -05:00
package system
import (
"errors"
"github.com/mrusme/gobbs/models/post"
"github.com/mrusme/gobbs/system/adapter"
"github.com/mrusme/gobbs/system/discourse"
2022-12-31 12:30:26 -05:00
"github.com/mrusme/gobbs/system/hackernews"
2022-12-28 22:22:36 -05:00
"github.com/mrusme/gobbs/system/lemmy"
2022-12-29 22:03:38 -05:00
"go.uber.org/zap"
2022-12-28 22:22:36 -05:00
)
type System interface {
GetConfig() map[string]interface{}
SetConfig(cfg *map[string]interface{})
2022-12-29 22:03:38 -05:00
SetLogger(logger *zap.SugaredLogger)
2022-12-28 22:22:36 -05:00
GetCapabilities() []adapter.Capability
2022-12-29 17:46:59 -05:00
Connect(sysURL string) error
2022-12-28 22:22:36 -05:00
Load() error
2022-12-30 03:22:54 -05:00
ListPosts(sysIdx int) ([]post.Post, error)
LoadPost(p *post.Post) error
2022-12-28 22:22:36 -05:00
}
2022-12-29 22:03:38 -05:00
func New(
sysType string,
sysConfig *map[string]interface{},
logger *zap.SugaredLogger,
) (System, error) {
2022-12-28 22:22:36 -05:00
var sys System
switch sysType {
case "discourse":
sys = new(discourse.System)
case "lemmy":
sys = new(lemmy.System)
2022-12-31 12:30:26 -05:00
case "hackernews":
sys = new(hackernews.System)
2022-12-28 22:22:36 -05:00
default:
return nil, errors.New("No such system")
}
sys.SetConfig(sysConfig)
2022-12-29 22:03:38 -05:00
sys.SetLogger(logger)
2022-12-28 22:22:36 -05:00
err := sys.Load()
if err != nil {
return nil, err
}
return sys, nil
}