Exemple #1
0
func getterHandler(w http.ResponseWriter, r *http.Request, params map[string]string) {
	response := Resp{}
	response.Code = 200
	response.Message = "OK"

	// PUT VISIT DATA
	go func() {
		var client_type string = "2"
		if params["client_type"] != "" {
			client_type = params["client_type"]
		}
		visitParams := map[string]string{"client_id": params["key"], "client_type": client_type}
		err := db.Put(visitParams)
		if err != nil {
			log.Print(err)
		}
	}()
	// END

	resp, err := http.Get(fmt.Sprintf("%s/service/get/findinformer?key=%s", CoobUrl, params["key"]))
	if err != nil {
		response.Code = http.StatusInternalServerError
		response.Message = err.Error()
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)

	w.Header().Set("Access-Control-Allow-Origin", "*")
	w.Header().Set("Access-Control-Allow-Credentials", "true")
	w.Header().Set("Access-Control-Allow-Headers", "authorization")
	w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS")
	w.Write(body)
}
Exemple #2
0
func putHandler(w http.ResponseWriter, r *http.Request, params map[string]string) {
	response := Resp{}
	response.Code = 200
	response.Message = "OK"

	go func() {
		err := db.Put(params)
		if err != nil {
			response.Code = http.StatusInternalServerError
			response.Message = err.Error()
		}
	}()

	makeResp(w, r, response)
}