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"
|
|
|
|
"github.com/mrusme/gobbs/system/lemmy"
|
|
|
|
)
|
|
|
|
|
|
|
|
type System interface {
|
2022-12-29 14:34:05 -05:00
|
|
|
GetConfig() map[string]interface{}
|
|
|
|
SetConfig(cfg *map[string]interface{})
|
2022-12-28 22:22:36 -05:00
|
|
|
GetCapabilities() []adapter.Capability
|
|
|
|
|
|
|
|
Load() error
|
|
|
|
|
|
|
|
ListPosts() ([]post.Post, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
func New(sysType string, sysConfig *map[string]interface{}) (System, error) {
|
|
|
|
var sys System
|
|
|
|
|
|
|
|
switch sysType {
|
|
|
|
case "discourse":
|
|
|
|
sys = new(discourse.System)
|
|
|
|
case "lemmy":
|
|
|
|
sys = new(lemmy.System)
|
|
|
|
default:
|
|
|
|
return nil, errors.New("No such system")
|
|
|
|
}
|
|
|
|
|
2022-12-29 14:34:05 -05:00
|
|
|
sys.SetConfig(sysConfig)
|
2022-12-28 22:22:36 -05:00
|
|
|
err := sys.Load()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return sys, nil
|
|
|
|
}
|