| 30 | } |
| 31 | |
| 32 | func NewOperatorHTTP() (OperatorHTTP, error) { |
| 33 | retval := &operatorHTTP{ |
| 34 | router: mux.NewRouter(), |
| 35 | results: make(map[string]preparedEntry), |
| 36 | } |
| 37 | |
| 38 | retval.router.HandleFunc("/health", func(rw http.ResponseWriter, _ *http.Request) { |
| 39 | rw.WriteHeader(http.StatusOK) |
| 40 | _, _ = io.WriteString(rw, "OK") |
| 41 | }) |
| 42 | |
| 43 | akashVersion := version.NewInfo() |
| 44 | buf := &bytes.Buffer{} |
| 45 | enc := json.NewEncoder(buf) |
| 46 | err := enc.Encode(akashVersion) |
| 47 | |
| 48 | if err != nil { |
| 49 | return nil, err |
| 50 | } |
| 51 | |
| 52 | akashVersionJSON := buf.Bytes() |
| 53 | buf = nil // remove from scope |
| 54 | enc = nil // remove from scope |
| 55 | |
| 56 | retval.router.HandleFunc("/version", func(rw http.ResponseWriter, _ *http.Request) { |
| 57 | rw.WriteHeader(http.StatusOK) |
| 58 | _, _ = io.Copy(rw, bytes.NewReader(akashVersionJSON)) |
| 59 | }).Methods("GET") |
| 60 | |
| 61 | return retval, nil |
| 62 | } |
| 63 | |
| 64 | func (opHttp *operatorHTTP) GetRouter() *mux.Router { |
| 65 | return opHttp.router |