Skip to content

Commit

Permalink
endpoint for libcosim libcosimc versions #164 (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
Levi Jamt authored May 28, 2020
1 parent 106b63d commit 90d6f3a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
15 changes: 15 additions & 0 deletions libcosim/libcosim.go
Original file line number Diff line number Diff line change
Expand Up @@ -981,3 +981,18 @@ func SetupLogging() {
log.Println("Console logging set up with severity: INFO")
}
}

type Versions struct {
LibVer string `json:"libcosim"`
LibcVer string `json:"libcosimc"`
}

func Version() Versions {
libVer := C.cosim_libcosim_version()
libcVer := C.cosim_libcosimc_version()

return Versions{
LibVer: fmt.Sprintf("%d.%d.%d", int(libVer.major), int(libVer.minor), int(libVer.patch)),
LibcVer: fmt.Sprintf("%d.%d.%d", int(libcVer.major), int(libcVer.minor), int(libcVer.patch)),
}
}
5 changes: 5 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ func Server(command chan []string, state chan structs.JsonResponse, simulationSt
json.NewEncoder(w).Encode(libcosim.GenerateJsonResponse(simulationStatus, sim, structs.CommandFeedback{}, structs.ShortLivedData{}))
})

router.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(libcosim.Version())
})

router.HandleFunc("/modules", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(sim.MetaData)
Expand Down

0 comments on commit 90d6f3a

Please sign in to comment.