mirror of
https://github.com/mrusme/neonmodem.git
synced 2025-01-03 14:56:41 -05:00
Implemented #1 for Discourse, Lobsters
This commit is contained in:
parent
dbcf566574
commit
71c86c4a56
@ -78,6 +78,11 @@ func load() {
|
||||
}
|
||||
defer logger.Sync()
|
||||
LOG = logger.Sugar()
|
||||
|
||||
if CFG.Proxy != "" {
|
||||
LOG.Debugf("set proxy: %s", CFG.Proxy)
|
||||
os.Setenv("HTTP_PROXY", CFG.Proxy)
|
||||
}
|
||||
}
|
||||
|
||||
func loadSystems(c *ctx.Ctx) []error {
|
||||
@ -85,6 +90,7 @@ func loadSystems(c *ctx.Ctx) []error {
|
||||
|
||||
for _, sysCfg := range c.Config.Systems {
|
||||
c.Logger.Debugf("loading system of type %s ...", sysCfg.Type)
|
||||
sysCfg.Config["proxy"] = CFG.Proxy
|
||||
sys, err := system.New(sysCfg.Type, &sysCfg.Config, LOG)
|
||||
if err != nil {
|
||||
c.Logger.Errorf("error loading system: %s", err)
|
||||
|
@ -41,6 +41,7 @@ type ThemeItemConfig struct {
|
||||
type Config struct {
|
||||
Debug bool
|
||||
Log string
|
||||
Proxy string
|
||||
|
||||
RenderImages bool
|
||||
|
||||
@ -185,6 +186,7 @@ func (cfg *Config) Save() error {
|
||||
func SetDefaults(cacheDir string) {
|
||||
viper.SetDefault("Debug", "false")
|
||||
viper.SetDefault("Log", path.Join(cacheDir, "neonmodem.log"))
|
||||
viper.SetDefault("Proxy", "")
|
||||
|
||||
viper.SetDefault("RenderImages", "true")
|
||||
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/go-retryablehttp"
|
||||
)
|
||||
@ -74,13 +75,34 @@ type Client struct {
|
||||
|
||||
func NewDefaultClientConfig(
|
||||
endpoint string,
|
||||
proxy string,
|
||||
credentials map[string]string,
|
||||
logger Logger,
|
||||
) ClientConfig {
|
||||
var httpClient *http.Client = nil
|
||||
var httpTransport *http.Transport = nil
|
||||
|
||||
if proxy != "" {
|
||||
proxyURL, err := url.Parse(proxy)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
} else {
|
||||
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,
|
||||
}
|
||||
|
||||
return ClientConfig{
|
||||
Endpoint: endpoint,
|
||||
Credentials: credentials,
|
||||
HTTPClient: http.DefaultClient,
|
||||
HTTPClient: httpClient,
|
||||
Logger: logger,
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package discourse
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
@ -20,10 +19,11 @@ import (
|
||||
)
|
||||
|
||||
type System struct {
|
||||
ID int
|
||||
config map[string]interface{}
|
||||
logger *zap.SugaredLogger
|
||||
client *api.Client
|
||||
ID int
|
||||
config map[string]interface{}
|
||||
logger *zap.SugaredLogger
|
||||
client *api.Client
|
||||
clientCfg api.ClientConfig
|
||||
}
|
||||
|
||||
func (sys *System) GetID() int {
|
||||
@ -113,12 +113,13 @@ func (sys *System) Load() error {
|
||||
credentials[k] = v.(string)
|
||||
}
|
||||
|
||||
sys.client = api.NewClient(&api.ClientConfig{
|
||||
Endpoint: url.(string),
|
||||
Credentials: credentials,
|
||||
HTTPClient: http.DefaultClient,
|
||||
Logger: sys.logger,
|
||||
})
|
||||
sys.clientCfg = api.NewDefaultClientConfig(
|
||||
url.(string),
|
||||
sys.config["proxy"].(string),
|
||||
credentials,
|
||||
sys.logger,
|
||||
)
|
||||
sys.client = api.NewClient(&sys.clientCfg)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/go-retryablehttp"
|
||||
)
|
||||
@ -70,13 +71,34 @@ type Client struct {
|
||||
|
||||
func NewDefaultClientConfig(
|
||||
endpoint string,
|
||||
proxy string,
|
||||
credentials map[string]string,
|
||||
logger Logger,
|
||||
) ClientConfig {
|
||||
var httpClient *http.Client = nil
|
||||
var httpTransport *http.Transport = nil
|
||||
|
||||
if proxy != "" {
|
||||
proxyURL, err := url.Parse(proxy)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
} else {
|
||||
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,
|
||||
}
|
||||
|
||||
return ClientConfig{
|
||||
Endpoint: endpoint,
|
||||
Credentials: credentials,
|
||||
HTTPClient: http.DefaultClient,
|
||||
HTTPClient: httpClient,
|
||||
Logger: logger,
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package lobsters
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
@ -19,10 +18,11 @@ import (
|
||||
)
|
||||
|
||||
type System struct {
|
||||
ID int
|
||||
config map[string]interface{}
|
||||
logger *zap.SugaredLogger
|
||||
client *api.Client
|
||||
ID int
|
||||
config map[string]interface{}
|
||||
logger *zap.SugaredLogger
|
||||
client *api.Client
|
||||
clientCfg api.ClientConfig
|
||||
}
|
||||
|
||||
func (sys *System) GetID() int {
|
||||
@ -110,12 +110,13 @@ func (sys *System) Load() error {
|
||||
|
||||
credentials := make(map[string]string)
|
||||
|
||||
sys.client = api.NewClient(&api.ClientConfig{
|
||||
Endpoint: url.(string),
|
||||
Credentials: credentials,
|
||||
HTTPClient: http.DefaultClient,
|
||||
Logger: sys.logger,
|
||||
})
|
||||
sys.clientCfg = api.NewDefaultClientConfig(
|
||||
url.(string),
|
||||
sys.config["proxy"].(string),
|
||||
credentials,
|
||||
sys.logger,
|
||||
)
|
||||
sys.client = api.NewClient(&sys.clientCfg)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user