Exemplo n.º 1
0
func (config *Config) InfoHandler(resp http.ResponseWriter, request *http.Request) {
	omni_http.SetCORSHeaders(resp)
	buildInfo := config.BuildInfo
	info := Info{
		Commit:         buildInfo.GetCommitHash(),
		BuildTimestamp: buildInfo.GetBuildTimestamp(),
		BuildNumber:    buildInfo.GetBuildNumber(),
		Uptime:         time.Since(startTime).Seconds(),
	}
	enc := json.NewEncoder(resp)
	_ = enc.Encode(info)
	return
}
Exemplo n.º 2
0
func StartUpdateHandler(resp http.ResponseWriter, request *http.Request) {
	omni_http.SetCORSHeaders(resp)
	body, err := ioutil.ReadAll(request.Body)
	if err != nil {
		renderJsonError(resp, request, err.Error(), http.StatusInternalServerError)
		return
	}

	var message UpdateExecutableRequest
	dec := json.NewDecoder(strings.NewReader(string(body)))
	for {
		if err := dec.Decode(&message); err == io.EOF {
			break
		} else if err != nil {
			renderJsonError(resp, request, err.Error(), http.StatusBadRequest)
			return
		}
	}

	if message.DownloadUrl == "" {
		renderJsonError(resp, request, "update-no-download-url", http.StatusBadRequest)
		return
	}

	// Blocks while update is happening
	result := <-RunUpdate(&message)

	if result.Error != nil {
		renderJsonError(resp, request, "update-error-download", http.StatusInternalServerError)
		return
	} else if result.RecoverError != nil {
		renderJsonError(resp, request, "update-recover-error", http.StatusInternalServerError)
		return
	}

	resp.Write([]byte(fmt.Sprintf("{\"status\":\"installed\"}")))
	return
}