63 lines
2.0 KiB
Go
63 lines
2.0 KiB
Go
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) {} |