Пример #1
0
func configCommonRoutes(router *gorest.Router) {
	router.GetFunc("/health", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("ok\n"))
	})

	router.GetFunc("/version", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte(fmt.Sprintf("%s\n", g.VERSION)))
	})
}
Пример #2
0
func ConfigGetAwsInfoApiRoutes(router *gorest.Router) {

	router.GetFunc("/v1/aws/ip/{ip}", func(w http.ResponseWriter, req *http.Request) {
		ip := gorest.Var(req, "ip")
		if len(ip) < 1 {
			gorest.InternalServerErrorText(w, "invalid ip")
			return
		}
		m := funcs.GetInfos("ip", ip)

		gorest.WriteJson(w, m)
	})

	router.GetFunc("/v1/aws/id/{id}", func(w http.ResponseWriter, req *http.Request) {
		id := gorest.Var(req, "id")
		if len(id) < 1 {
			gorest.InternalServerErrorText(w, "invalid id")
			return
		}
		log.Println("id", id)
		m := funcs.GetInfos("id", id)

		gorest.WriteJson(w, m)
	})

	router.PostFunc("/v1/aws/ids", func(w http.ResponseWriter, req *http.Request) {
		if req.Body == nil {
			gorest.InternalServerErrorText(w, "wrong body")
			return
		}

		var ids []string
		decoder := json.NewDecoder(req.Body)
		err := decoder.Decode(&ids)
		// log.Println(ids[0])
		if err != nil {
			http.Error(w, "connot decode body", http.StatusBadRequest)
			return
		}
		ret := make(map[string]*myredis.TagsInfo)

		for _, id := range ids {
			m := funcs.GetInfos("id", id)
			ret[id] = m
		}
		gorest.WriteJson(w, ret)
	})
}