Skip to content

Commit 7b2f084

Browse files
committed
new
1 parent b66aa94 commit 7b2f084

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

Diff for: go_graph/graph

0 Bytes
Binary file not shown.

Diff for: go_service/go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module go_service/test
2+
3+
go 1.22.1

Diff for: go_service/main.go

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"io"
7+
"net/http"
8+
"sort"
9+
)
10+
11+
type DonkeyKong struct {
12+
PlayerName string `json:"player_name"`
13+
Score uint32 `json:"score"`
14+
}
15+
16+
func draw_donkey(w http.ResponseWriter, r *http.Request) {
17+
w.Header().Set("Content-Type", "application/json")
18+
HighScores := []DonkeyKong{}
19+
20+
P1 := DonkeyKong{PlayerName: "RRD", Score: 123123}
21+
HighScores = append(HighScores, DonkeyKong{PlayerName: "RRD", Score: 234234})
22+
HighScores = append(HighScores, DonkeyKong{PlayerName: "PHX", Score: 323234})
23+
HighScores = append(HighScores, DonkeyKong{PlayerName: "ALX", Score: 3323234})
24+
HighScores = append(HighScores, P1)
25+
26+
sort.Slice(HighScores, func(i, j int) bool {
27+
return HighScores[i].Score > HighScores[j].Score
28+
})
29+
30+
err := json.NewEncoder(w).Encode(HighScores)
31+
if err != nil {
32+
_, err = io.WriteString(w, err.Error())
33+
if err != nil {
34+
fmt.Println("Oops!!! {s}", err.Error())
35+
}
36+
}
37+
}
38+
39+
func main() {
40+
fmt.Println("Running web serivce")
41+
http.HandleFunc("/api/v1/donkey", draw_donkey)
42+
err := http.ListenAndServe(":8088", nil)
43+
if err != nil {
44+
fmt.Println("Oops {s}", err.Error())
45+
}
46+
}

Diff for: go_service/test

6.65 MB
Binary file not shown.

0 commit comments

Comments
 (0)