For parameter is now in request header with env var config

This commit is contained in:
Romain de Laage 2021-03-22 09:09:21 +01:00
parent f6b448c162
commit 464b20f0d4
Signed by: rdelaage
GPG Key ID: 534845FADDF0C329
3 changed files with 15 additions and 5 deletions

View File

@ -25,8 +25,16 @@ import (
"encoding/json"
)
func getArticles(endpoint string) []Article {
resp, err := http.Get(endpoint)
func getArticles(endpoint, forB64 string) []Article {
req, err := http.NewRequest("GET", endpoint, nil)
if err != nil {
log.Fatalln(err)
}
req.Header.Set("For", forB64)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Fatalln(err)
}

View File

@ -57,11 +57,12 @@ type Config struct {
ApiEndpointMM string
ApiEndpointAssos string
DbPath string
ForB64 string
}
func main() {
config := getConfig()
articles := getArticles(config.ApiEndpointAssos)
articles := getArticles(config.ApiEndpointAssos, config.ForB64)
entries := openDb(config.DbPath)
for _, article := range articles {

View File

@ -31,9 +31,10 @@ func getConfig() Config {
config.ApiEndpointMM = os.Getenv("MM_ASSOS_ENDPOINTMM")
config.ApiEndpointAssos = os.Getenv("MM_ASSOS_ENDPOINTASSOS")
config.DbPath = os.Getenv("MM_ASSOS_DBPATH")
config.ForB64 = os.Getenv("MM_ASSOS_FORB64")
if config.ChannelId == "" || config.ApiToken == "" || config.ApiEndpointMM == "" || config.ApiEndpointAssos == "" || config.DbPath == "" {
log.Fatalln("MM_ASSOS_CHANNEL, MM_ASSOS_ENDPOINTMM, MM_ASSOS_ENDPOINTASSOS, MM_ASSOS_DBPATH or MM_ASSOS_TOKEN not defined")
if config.ChannelId == "" || config.ApiToken == "" || config.ApiEndpointMM == "" || config.ApiEndpointAssos == "" || config.DbPath == "" || config.ForB64 == "" {
log.Fatalln("MM_ASSOS_CHANNEL, MM_ASSOS_ENDPOINTMM, MM_ASSOS_ENDPOINTASSOS, MM_ASSOS_DBPATH, MM_ASSOS_TOKEN or MM_ASSOS_FORB64 not defined or empty string")
}
return config