コード例 #1
0
ファイル: tarball.go プロジェクト: GaoJiasheng/agent-updater
func configTarballRoutes() {

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		http.FileServer(http.Dir(g.Config().TarballDir)).ServeHTTP(w, r)
	})

}
コード例 #2
0
func configHeartbeatRoutes() {
	// post
	http.HandleFunc("/heartbeat", func(w http.ResponseWriter, r *http.Request) {
		if r.ContentLength == 0 {
			http.Error(w, "body is blank", http.StatusBadRequest)
			return
		}

		var req model.HeartbeatRequest
		decoder := json.NewDecoder(r.Body)
		err := decoder.Decode(&req)
		if err != nil {
			http.Error(w, "body format error", http.StatusBadRequest)
			return
		}

		if req.Hostname == "" {
			http.Error(w, "hostname is blank", http.StatusBadRequest)
			return
		}

		if g.Config().Debug {
			log.Println("Heartbeat Request=====>>>>")
			log.Println(req)
		}

		store.ParseHeartbeatRequest(&req)

		resp := model.HeartbeatResponse{
			ErrorMessage:  "",
			DesiredAgents: g.DesiredAgents(req.Hostname),
		}

		if g.Config().Debug {
			log.Println("<<<<=====Heartbeat Response")
			log.Println(resp)
		}

		RenderJson(w, resp)

	})

}
コード例 #3
0
ファイル: common.go プロジェクト: GaoJiasheng/agent-updater
func configCommonRoutes() {
	http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("ok"))
	})

	http.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte(g.VERSION))
	})

	http.HandleFunc("/workdir", func(w http.ResponseWriter, r *http.Request) {
		RenderDataJson(w, file.SelfDir())
	})

	http.HandleFunc("/config/reload", func(w http.ResponseWriter, r *http.Request) {
		if strings.HasPrefix(r.RemoteAddr, "127.0.0.1") {
			err := g.ParseConfig(g.ConfigFile)
			AutoRender(w, g.Config(), err)
		} else {
			w.Write([]byte("no privilege"))
		}
	})
}