From 17b437bb67c1370f5a528e330cc527618ab6f33c Mon Sep 17 00:00:00 2001 From: Nedim Uka Date: Tue, 24 Apr 2018 16:56:59 +0200 Subject: [PATCH] Added Mock response --- .gitignore | 2 ++ main.go | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 main.go diff --git a/.gitignore b/.gitignore index a1338d6..ffaadc1 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ *.so *.dylib +*.idea + # Test binary, build with `go test -c` *.test diff --git a/main.go b/main.go new file mode 100644 index 0000000..de9541b --- /dev/null +++ b/main.go @@ -0,0 +1,63 @@ +package main + +import ( + "github.com/gorilla/mux" + "log" + "net/http" + "encoding/json" + "io/ioutil" +) + +//"name": "#ChainedToTheRhythm", +//"url": "http://twitter.com/search?q=%23ChainedToTheRhythm", +//"promoted_content": null, +//"query": "%23ChainedToTheRhythm", +//"tweet_volume": 48857 + +type Tweet struct { + Name string `json:"name,omitempty"` + Url string `json:"url,omitempty"` + PromotedContent string `promoted_content:"lastname,omitempty"` + Query string `json:"query,omitempty"` + TweetVolume string `json:"tweet_volume,omitempty"` +} +type Address struct { + City string `json:"city,omitempty"` + State string `json:"state,omitempty"` +} + +var tweets []Tweet + +func main() { + + tweets = append(tweets, Tweet{Name: "#ChainedToTheRhythm", Url: "http://twitter.com/search?q=%23ChainedToTheRhythm", PromotedContent: "null", Query: "%23ChainedToTheRhythm" , TweetVolume: "48857"}) + //people = append(people, Person{ID: "2", Firstname: "Koko", Lastname: "Doe", Address: &Address{City: "City Z", State: "State Y"}}) + //people = append(people, Person{ID: "3", Firstname: "Francis", Lastname: "Sunday"}) + router := mux.NewRouter() + router.HandleFunc("/hashtags", GetHastags).Methods("GET") + //router.HandleFunc("/people", GetPeople).Methods("GET") + ////router.HandleFunc("/people/{id}", GetPerson).Methods("GET") + //router.HandleFunc("/people/{id}", CreatePerson).Methods("POST") + //router.HandleFunc("/people/{id}", DeletePerson).Methods("DELETE") + log.Fatal(http.ListenAndServe(":8000", router)) +} + +func GetHastags(w http.ResponseWriter, r *http.Request) { + + resp, err := http.Get("https://api.twitter.com/1.1/trends/place.json?id=1") + if err != nil { + println("There was an error") + println(err) + // handle error + } + defer resp.Body.Close() + body, err := ioutil.ReadAll(resp.Body) + println(body) + json.NewEncoder(w).Encode(body) +} + +func GetPeople(w http.ResponseWriter, r *http.Request) { + //json.NewEncoder(w).Encode(people) +} +func CreatePerson(w http.ResponseWriter, r *http.Request) {} +func DeletePerson(w http.ResponseWriter, r *http.Request) {} \ No newline at end of file