Added Mock response

This commit is contained in:
2018-04-24 16:56:59 +02:00
parent 926175fd85
commit 17b437bb67
2 changed files with 65 additions and 0 deletions

2
.gitignore vendored
View File

@@ -4,6 +4,8 @@
*.so
*.dylib
*.idea
# Test binary, build with `go test -c`
*.test

63
main.go Normal file
View File

@@ -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) {}