예제 #1
0
func RemoveBracket(slug string) error {
	res, _ := FindBracket(slug)
	result, err := brackets.Parse(res)
	if err != nil {
		return err
	}
	client := new(http.Client)
	for _, match := range result.Matches {
		if match.Event.Id != nil {
			deleteRequest, err := http.NewRequest("DELETE", "http://esports.ign.com/content/v2/events/"+string(*match.Event.Id), nil)
			if err != nil {
				log.Println(err)
			}
			resp, err := client.Do(deleteRequest)
			if err != nil {
				log.Println(err)
			}
			defer resp.Body.Close()
			log.Printf("deleted %s", *match.Event.Id)
		}
	}

	c, session := ConnectToCollection("brackets")
	defer session.Close()

	err = c.Remove(bson.M{"slug": slug})
	if err != nil {
		log.Println(err)
	}
	return nil
}
예제 #2
0
func RequestHandler(w http.ResponseWriter, r *http.Request) {
	switch r.Method {
	// case "GET":
	// 	result, err = getBracket(w, r, c)
	// case "PUT":
	// 	result, err = updateBracket(w, r, c)
	case "POST":
		body, err := ioutil.ReadAll(r.Body)
		if err != nil {
			log.Println(err)
		}

		result, err := brackets.Parse(body)
		// gOut, _ := json.Marshal(result)
		// fmt.Println(string(gOut))
		if err != nil {
			log.Println(err)
		}
		// log.Println(result)
		CreateBracket(result)
		// FindBracket()
		SetCORHeaders(w)
		w.WriteHeader(200)
	case "OPTIONS":
		SetCORHeaders(w)
		w.WriteHeader(200)
	}
}
예제 #3
0
func ReadBody(r *http.Request) (*brackets.Bracket, error) {
	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	result, err := brackets.Parse(body)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	return result, nil
}