35 lines
969 B
Go
35 lines
969 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"git.cin.su/m/Assistant/adapters/models"
|
|
"git.cin.su/m/Assistant/runtime/health"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
addr := os.Getenv("LISTEN_ADDR")
|
|
if addr == "" {
|
|
addr = ":8083"
|
|
}
|
|
mux := http.NewServeMux()
|
|
mux.Handle("/healthz", health.Handler{Runtime: "cognitive-worker", SemanticGeneration: 1, ArchitectureGeneration: 1})
|
|
mux.HandleFunc("POST /v1/proposals/deterministic", deterministicProposal)
|
|
log.Printf("cognitive-worker listening on %s", addr)
|
|
if err := http.ListenAndServe(addr, mux); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func deterministicProposal(w http.ResponseWriter, r *http.Request) {
|
|
var request models.DeterministicRequest
|
|
if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
|
|
http.Error(w, "invalid deterministic proposal request", http.StatusBadRequest)
|
|
return
|
|
}
|
|
w.Header().Set("Content-Type", "application/json")
|
|
_ = json.NewEncoder(w).Encode(models.Propose(request))
|
|
}
|