From cb112d9961678a125aaa990caa0959bd7b950296 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 18 Jun 2019 04:30:01 +0100 Subject: [PATCH] moved headers to json file + cleanup of topics --- api.go | 18 ++++++++---------- data.go | 7 +++++++ file.go | 5 +++++ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/api.go b/api.go index 38dbca8..5709307 100755 --- a/api.go +++ b/api.go @@ -22,10 +22,9 @@ func Request(path string) []byte { log.Fatal("Error reading request. ", err) } - req.Header.Set("Accept", "application/json") - req.Header.Set("Content-Type", "application/json") - req.Header.Set("Api-Key", "57dc92f574f7f400e1d12670940c19930a1f85b78485ca25ac96d96590dc7f99") - req.Header.Set("Api-Username", "Michael") + for _, headers := range Header().Headers { + req.Header.Set(headers.Name, headers.Value) + } client := &http.Client{Timeout: time.Second * 10} @@ -88,14 +87,13 @@ func GetTopics(path string) (topics TagTopics) { // Topics n/a func Topics(path string) map[string]interface{} { - topics := GetTopics(path) var topic TopicsList - for i := 0; i < len(topics.TopicList.Topics); i++ { + for _, topics := range GetTopics(path).TopicList.Topics { var t Topic - json.Unmarshal(Request("/t/"+topics.TopicList.Topics[i].Slug), &t) - for j := 0; j < len(t.PostStream.Posts); j++ { - if t.PostStream.Posts[j].PostNumber != 1 { - t.PostStream.Posts[j].Cooked = "" + json.Unmarshal(Request("/t/"+topics.Slug), &t) + for i := 0; i < len(t.PostStream.Posts); i++ { + if t.PostStream.Posts[i].PostNumber != 1 { + t.PostStream.Posts[i].Cooked = "" } } t.Details.CreatedBy.AvatarTemplate = strings.ReplaceAll(t.Details.CreatedBy.AvatarTemplate, "{size}", "120") diff --git a/data.go b/data.go index ba4acb9..cf40e09 100644 --- a/data.go +++ b/data.go @@ -4,6 +4,13 @@ import ( "time" ) +type Headers struct { + Headers []struct { + Name string `json:"name"` + Value string `json:"value"` + } `json:"headers"` +} + // Contacts list type Contacts struct { Contacts []struct { diff --git a/file.go b/file.go index 1afcfee..bf2dbe9 100644 --- a/file.go +++ b/file.go @@ -26,3 +26,8 @@ func Contact() map[string]interface{} { m := structs.Map(contact) return m } + +func Header() (headers Headers) { + json.Unmarshal(File("./json/headers.json"), &headers) + return +}