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

Implemented #1 for Lemmy

This commit is contained in:
マリウス 2023-01-10 19:00:58 -05:00
parent 71c86c4a56
commit 60a5162b5c
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F

View File

@ -3,8 +3,10 @@ package lemmy
import ( import (
"context" "context"
"fmt" "fmt"
"net/http"
"net/url" "net/url"
"strconv" "strconv"
"time"
"github.com/mrusme/neonmodem/models/author" "github.com/mrusme/neonmodem/models/author"
"github.com/mrusme/neonmodem/models/forum" "github.com/mrusme/neonmodem/models/forum"
@ -100,14 +102,38 @@ func (sys *System) Description() string {
} }
func (sys *System) Load() error { func (sys *System) Load() error {
var httpClient *http.Client = nil
var httpTransport *http.Transport = nil
var err error var err error
url := sys.config["url"] u := sys.config["url"]
if url == nil { if u == nil {
return nil return nil
} }
sys.client, err = lemmy.New(url.(string)) proxy := sys.config["proxy"].(string)
if proxy != "" {
proxyURL, err := url.Parse(proxy)
if err != nil {
sys.logger.Error(err)
} else {
sys.logger.Debugf("setting up http proxy transport: %s\n", proxyURL.String())
httpTransport = &http.Transport{
Proxy: http.ProxyURL(proxyURL),
}
}
}
httpClient = &http.Client{
Transport: httpTransport,
Timeout: time.Second * 10,
}
sys.client, err = lemmy.NewWithClient(
u.(string),
httpClient,
)
if err != nil { if err != nil {
return err return err
} }