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

Refactored disourse client, fixed url

This commit is contained in:
マリウス 2022-12-30 00:43:32 -05:00
parent 1399653532
commit 3e83345758
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F
2 changed files with 19 additions and 13 deletions

View File

@ -12,6 +12,7 @@ import (
type System struct {
config map[string]interface{}
logger *zap.SugaredLogger
client *Client
}
func (sys *System) GetConfig() map[string]interface{} {
@ -27,6 +28,22 @@ func (sys *System) SetLogger(logger *zap.SugaredLogger) {
}
func (sys *System) Load() error {
url := sys.config["url"]
if url == nil {
return nil
}
credentials := make(map[string]string)
for k, v := range (sys.config["credentials"]).(map[string]interface{}) {
credentials[k] = v.(string)
}
sys.client = NewClient(&ClientConfig{
Endpoint: url.(string),
Credentials: credentials,
HTTPClient: http.DefaultClient,
Logger: sys.logger,
})
return nil
}
@ -51,18 +68,7 @@ func (sys *System) GetCapabilities() []adapter.Capability {
}
func (sys *System) ListPosts() ([]post.Post, error) {
credentials := make(map[string]string)
for k, v := range (sys.config["credentials"]).(map[string]interface{}) {
credentials[k] = v.(string)
}
c := NewClient(&ClientConfig{
Endpoint: sys.config["url"].(string),
Credentials: credentials,
HTTPClient: http.DefaultClient,
Logger: sys.logger,
})
items, err := c.Topics.ListLatest(context.Background())
items, err := sys.client.Topics.ListLatest(context.Background())
if err != nil {
return []post.Post{}, err
}

View File

@ -36,7 +36,7 @@ func (sys *System) Load() error {
return nil
}
sys.client, err = lemmy.New(sys.config["url"].(string))
sys.client, err = lemmy.New(url.(string))
if err != nil {
return err
}