Skip to content

Commit

Permalink
add gopogh version footer
Browse files Browse the repository at this point in the history
  • Loading branch information
JudahNour committed Aug 11, 2023
1 parent 670fa5a commit 69ece72
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/gopogh-server/flake_chart.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<body>
<div id="dropdown_container"></div>
<div id="chart_div"></div>
<div id="version_div"></div>
</body>
<script>
const el = document.createElement('script');
Expand Down
17 changes: 17 additions & 0 deletions cmd/gopogh-server/flake_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,14 @@ function createTopnDropdown(currentTopn) {
document.getElementById('dropdown_container').appendChild(dropdownContainer)
}

function displayGopoghVersion(verData) {
const footerElement = document.getElementById('version_div');
const version = verData.version

footerElement.className = "mdl-mega-footer";
footerElement.innerHTML = "generated by <a href=\"https://github.com/medyagh/gopogh/\">Gopogh " + version + "</a>";
}


async function init() {
const query = parseUrlQuery(window.location.search);
Expand Down Expand Up @@ -791,6 +799,15 @@ async function init() {
} else {
displayTestAndEnvironmentChart(data, query);
}
url = basePath + '/version'

const verResponse = await fetch(url);
if (!verResponse.ok) {
throw new Error('Network response was not ok');
}
const verData = await verResponse.json();
console.log(verData)
displayGopoghVersion(verData)
} catch (err) {
displayError(err);
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/gopogh-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func main() {

http.HandleFunc("/summary", db.ServeOverview)

http.HandleFunc("/version", handler.ServeGopoghVersion)

// Start the HTTP server
err = http.ListenAndServe(":8080", nil)
if err != nil {
Expand Down
20 changes: 20 additions & 0 deletions pkg/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strconv"

"github.com/medyagh/gopogh/pkg/db"
"github.com/medyagh/gopogh/pkg/report"
)

type DB struct {
Expand Down Expand Up @@ -138,3 +139,22 @@ func (m *DB) ServeOverview(w http.ResponseWriter, _ *http.Request) {
return
}
}

// ServeGopoghVersion writes the gopogh version to a json response
func ServeGopoghVersion(w http.ResponseWriter, _ *http.Request) {
data := map[string]interface{}{
"version": report.Version,
}
jsonData, err := json.Marshal(data)
if err != nil {
http.Error(w, "Failed to marshal JSON", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Access-Control-Allow-Origin", "*")
_, err = w.Write(jsonData)
if err != nil {
http.Error(w, "Failed to write JSON data", http.StatusInternalServerError)
return
}
}

0 comments on commit 69ece72

Please sign in to comment.