For parameter is now in request header with env var config
This commit is contained in:
parent
f6b448c162
commit
464b20f0d4
12
assos.go
12
assos.go
|
@ -25,8 +25,16 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getArticles(endpoint string) []Article {
|
func getArticles(endpoint, forB64 string) []Article {
|
||||||
resp, err := http.Get(endpoint)
|
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 {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
3
main.go
3
main.go
|
@ -57,11 +57,12 @@ type Config struct {
|
||||||
ApiEndpointMM string
|
ApiEndpointMM string
|
||||||
ApiEndpointAssos string
|
ApiEndpointAssos string
|
||||||
DbPath string
|
DbPath string
|
||||||
|
ForB64 string
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
config := getConfig()
|
config := getConfig()
|
||||||
articles := getArticles(config.ApiEndpointAssos)
|
articles := getArticles(config.ApiEndpointAssos, config.ForB64)
|
||||||
entries := openDb(config.DbPath)
|
entries := openDb(config.DbPath)
|
||||||
|
|
||||||
for _, article := range articles {
|
for _, article := range articles {
|
||||||
|
|
5
util.go
5
util.go
|
@ -31,9 +31,10 @@ func getConfig() Config {
|
||||||
config.ApiEndpointMM = os.Getenv("MM_ASSOS_ENDPOINTMM")
|
config.ApiEndpointMM = os.Getenv("MM_ASSOS_ENDPOINTMM")
|
||||||
config.ApiEndpointAssos = os.Getenv("MM_ASSOS_ENDPOINTASSOS")
|
config.ApiEndpointAssos = os.Getenv("MM_ASSOS_ENDPOINTASSOS")
|
||||||
config.DbPath = os.Getenv("MM_ASSOS_DBPATH")
|
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 == "" {
|
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 or MM_ASSOS_TOKEN not defined")
|
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
|
return config
|
||||||
|
|
Loading…
Reference in New Issue