github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/publicapi/endpoint_version.go (about) 1 package publicapi 2 3 import ( 4 "encoding/json" 5 "net/http" 6 7 "github.com/filecoin-project/bacalhau/pkg/model" 8 "github.com/filecoin-project/bacalhau/pkg/version" 9 ) 10 11 type VersionRequest struct { 12 ClientID string `json:"client_id" example:"ac13188e93c97a9c2e7cf8e86c7313156a73436036f30da1ececc2ce79f9ea51"` 13 } 14 15 type VersionResponse struct { 16 VersionInfo *model.BuildVersionInfo `json:"build_version_info"` 17 } 18 19 // version godoc 20 // 21 // @ID apiServer/version 22 // @Summary Returns the build version running on the server. 23 // @Description See https://github.com/filecoin-project/bacalhau/releases for a complete list of `gitversion` tags. 24 // @Tags Misc 25 // @Accept json 26 // @Produce json 27 // @Param VersionRequest body VersionRequest true "Request must specify a `client_id`. To retrieve your `client_id`, you can do the following: (1) submit a dummy job to Bacalhau (or use one you created before), (2) run `bacalhau describe <job-id>` and fetch the `ClientID` field." 28 // @Success 200 {object} VersionResponse 29 // @Failure 400 {object} string 30 // @Failure 500 {object} string 31 // @Router /version [post] 32 // 33 //nolint:lll 34 func (apiServer *APIServer) version(res http.ResponseWriter, req *http.Request) { 35 var versionReq VersionRequest 36 err := json.NewDecoder(req.Body).Decode(&versionReq) 37 if err != nil { 38 http.Error(res, err.Error(), http.StatusBadRequest) 39 return 40 } 41 42 res.WriteHeader(http.StatusOK) 43 err = json.NewEncoder(res).Encode(VersionResponse{ 44 VersionInfo: version.Get(), 45 }) 46 if err != nil { 47 http.Error(res, err.Error(), http.StatusInternalServerError) 48 return 49 } 50 }