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"
|
||||
)
|
||||
|
||||
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)
|
||||
}
|
||||
|
|
3
main.go
3
main.go
|
@ -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 {
|
||||
|
|
5
util.go
5
util.go
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue