Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply review suggestions on query graph code #74

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions go/summarize/force-graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"encoding/json"
"fmt"
"html/template"
"net"
"net/http"
)

Expand Down Expand Up @@ -67,15 +68,25 @@ func createForceGraphData(s *Summary) forceGraphData {
func renderQueryGraph(s *Summary) {
data := createForceGraphData(s)

// Start the HTTP server
http.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
serveIndex(w, data)
})
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
panic(err)
}
defer listener.Close()

port := "1010"
fmt.Printf("Server started at http://localhost:%s\n", port)
// Get the assigned port
addr, ok := listener.Addr().(*net.TCPAddr)
if !ok {
exit("could not create a listener")
}
fmt.Printf("Server started at http://localhost:%d\nExit the program with CTRL+C\n", addr.Port)

// Start the server
// nolint: gosec,nolintlint // this is all ran locally so no need to care about vulnerabilities around timeouts
if err := http.ListenAndServe(":"+port, nil); err != nil {
err = http.Serve(listener, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
serveIndex(w, data)
}))
if err != nil {
exit(err.Error())
}
}
Expand Down
Loading