diff --git a/data/creators/europe.json b/data/creators/europe.json index 80313a3..7c4243e 100644 --- a/data/creators/europe.json +++ b/data/creators/europe.json @@ -1,189 +1,201 @@ -{ - "papaplatte": { - "name": "Papaplatte", - "aliases": [ - "lattensepp" - ], - "steam": { - "id": "76561198013760707", - "name": "lattensepp" - }, - "discord": { - "id": "169926504657059840", - "username": "papaplatte420", - "partner": true - }, - "twitch": { - "id": "papaplatte", - "partner": true - }, - "youtube": { - "handle": "@papaplatte", - "id": "UCDmbhGe7-wC1a55l5ZYAZJw", - "partner": true +[ + { + "papaplatte": { + "name": "Papaplatte", + "aliases": ["lattensepp"], + "steam": { + "id": "76561198013760707", + "name": "lattensepp" + }, + "discord": { + "id": "169926504657059840", + "username": "papaplatte420", + "partner": true + }, + "twitch": { + "id": "papaplatte", + "partner": true + }, + "youtube": { + "handle": "@papaplatte", + "id": "UCDmbhGe7-wC1a55l5ZYAZJw", + "partner": true + } } }, - "honeypuu": { - "name": "HoneyPuu", - "aliases": null, - "steam": { - "id": "76561198405910426", - "name": "HoneyPuu" - }, - "discord": { - "id": "247064492427444224", - "username": "honeypuu", - "partner": false - }, - "twitch": { - "id": "honeypuu", - "partner": true - }, - "youtube": { - "handle": "honeypuu", - "id": "UC6lv714giE5fvmlUhS3d9gg", - "partner": true + { + "honeypuu": { + "name": "HoneyPuu", + "aliases": null, + "steam": { + "id": "76561198405910426", + "name": "HoneyPuu" + }, + "discord": { + "id": "247064492427444224", + "username": "honeypuu", + "partner": false + }, + "twitch": { + "id": "honeypuu", + "partner": true + }, + "youtube": { + "handle": "honeypuu", + "id": "UC6lv714giE5fvmlUhS3d9gg", + "partner": true + } } }, - "letshugo": { - "name": "LetsHugo", - "aliases": null, - "steam": { - "id": "76561198287958160", - "name": "LetsHugo" - }, - "discord": { - "id": "252817918159486977", - "username": "letshugo", - "partner": false - }, - "twitch": { - "id": "letshugotv", - "partner": true - }, - "youtube": { - "handle": "@LetsHugo", - "id": "UCGrEhW-D986zSjijnnhq5hg", - "partner": true + { + "letshugo": { + "name": "LetsHugo", + "aliases": null, + "steam": { + "id": "76561198287958160", + "name": "LetsHugo" + }, + "discord": { + "id": "252817918159486977", + "username": "letshugo", + "partner": false + }, + "twitch": { + "id": "letshugotv", + "partner": true + }, + "youtube": { + "handle": "@LetsHugo", + "id": "UCGrEhW-D986zSjijnnhq5hg", + "partner": true + } } }, - "zarbex": { - "name": "zarbex", - "aliases": [ - "Mr.Geil" - ], - "steam": { - "id": "76561198399217625", - "name": "zarbex" - }, - "discord": { - "id": "278274544668639232", - "username": "zrbx", - "partner": false - }, - "twitch": { - "id": "zarbex", - "partner": true - }, - "youtube": { - "handle": "@zarbex", - "id": "UCk5IRwxIo4lYyV4PzHhWxsg", - "partner": true + { + "zarbex": { + "name": "zarbex", + "aliases": ["Mr.Geil"], + "steam": { + "id": "76561198399217625", + "name": "zarbex" + }, + "discord": { + "id": "278274544668639232", + "username": "zrbx", + "partner": false + }, + "twitch": { + "id": "zarbex", + "partner": true + }, + "youtube": { + "handle": "@zarbex", + "id": "UCk5IRwxIo4lYyV4PzHhWxsg", + "partner": true + } } }, - "filow": { - "name": "Filow", - "aliases": [], - "steam": { - "id": "76561198055228237", - "name": "Filow" - }, - "discord": { - "id": "289395749538627584", - "username": "filow", - "partner": false - }, - "twitch": { - "id": "filow", - "partner": true - }, - "youtube": { - "handle": "UCeyP7G6IFDUa6UypHghbxdw", - "id": "@Filow", - "partner": true + { + "filow": { + "name": "Filow", + "aliases": [], + "steam": { + "id": "76561198055228237", + "name": "Filow" + }, + "discord": { + "id": "289395749538627584", + "username": "filow", + "partner": false + }, + "twitch": { + "id": "filow", + "partner": true + }, + "youtube": { + "handle": "@Filow", + "id": "UCeyP7G6IFDUa6UypHghbxdw", + "partner": true + } } }, - "reeze": { - "name": "Reeze", - "aliases": [], - "steam": { - "id": "76561198131535172", - "name": "Reeze" - }, - "discord": { - "id": "141704368217915392", - "username": "lemonreezy", - "partner": false - }, - "twitch": { - "id": "reeze", - "partner": true - }, - "youtube": { - "handle": "@Reeze", - "id": "UCaOAZtbdp0K5CCzgEXM0F6Q", - "partner": true + { + "reeze": { + "name": "Reeze", + "aliases": [], + "steam": { + "id": "76561198131535172", + "name": "Reeze" + }, + "discord": { + "id": "141704368217915392", + "username": "lemonreezy", + "partner": false + }, + "twitch": { + "id": "reeze", + "partner": true + }, + "youtube": { + "handle": "@Reeze", + "id": "UCaOAZtbdp0K5CCzgEXM0F6Q", + "partner": true + } } }, - "gronkh": { - "name": "Gronkh", - "aliases": [], - "steam": { - "id": "76561197984767093", - "name": "Gronkh" - }, - "discord": { - "id": "99010890275225600", - "username": "grnkh", - "partner": false - }, - "twitch": { - "id": "gronkh", - "partner": true - }, - "youtube": { - "handle": "@gronkh", - "id": "UCYJ61XIK64sp6ZFFS8sctxw", - "partner": true + { + "gronkh": { + "name": "Gronkh", + "aliases": [], + "steam": { + "id": "76561197984767093", + "name": "Gronkh" + }, + "discord": { + "id": "99010890275225600", + "username": "grnkh", + "partner": false + }, + "twitch": { + "id": "gronkh", + "partner": true + }, + "youtube": { + "handle": "@gronkh", + "id": "UCYJ61XIK64sp6ZFFS8sctxw", + "partner": true + } } }, - "montanablack88": { - "name": "Montanablack", - "aliases": [ - "Montanablack88", - "GetOnMyLvL", - "Monte", - "MontanaBlack88", - "spontanablack", - "SpontanaBlack" - ], - "steam": { - "id": "76561198202200829", - "name": "MisterFister" - }, - "discord": { - "id": "332250378819338251", - "username": "getonmylvl", - "partner": false - }, - "twitch": { - "id": "montanablack88", - "partner": true - }, - "youtube": { - "handle": "@montanablack", - "id": "UCpAMOlA_0hFXopIxMq8ar0w", - "partner": true + { + "montanablack88": { + "name": "Montanablack", + "aliases": [ + "Montanablack88", + "GetOnMyLvL", + "Monte", + "MontanaBlack88", + "spontanablack", + "SpontanaBlack" + ], + "steam": { + "id": "76561198202200829", + "name": "MisterFister" + }, + "discord": { + "id": "332250378819338251", + "username": "getonmylvl", + "partner": false + }, + "twitch": { + "id": "montanablack88", + "partner": true + }, + "youtube": { + "handle": "@montanablack", + "id": "UCpAMOlA_0hFXopIxMq8ar0w", + "partner": true + } } } -} +] diff --git a/packages/api/api.go b/packages/api/api.go new file mode 100644 index 0000000..e51a8a6 --- /dev/null +++ b/packages/api/api.go @@ -0,0 +1,82 @@ +package main + +import ( + "encoding/json" + "fmt" + "log" + "net/http" + "os" +) + +type APIServer struct { + port string +} + +type Creator map[string]interface{} + +func NewAPIServer(port string) *APIServer { + return &APIServer{ + port, + } +} + +func (s *APIServer) Run() error { + router := http.NewServeMux() + router.HandleFunc("GET /{continent}/creator/{creatorID}", s.handleGetCreator) + + v1 := http.NewServeMux() + v1.Handle("/api/v1/", http.StripPrefix("/api/v1", router)) + + server := http.Server{ + Addr: s.port, + Handler: v1, + } + + log.Printf("Server has started on %s", s.port) + return server.ListenAndServe() +} + +func (s *APIServer) handleGetCreator(w http.ResponseWriter, r *http.Request) { + creatorID := r.PathValue("creatorID") + continent := r.PathValue("continent") + urlPath := fmt.Sprintf("../../data/creators/%s.json", continent) + creators, err := loadCreators(urlPath) + + if err != nil { + http.Error(w, "Failed to load creators data", http.StatusInternalServerError) + return + } + + creator, found := findCreator(creators, creatorID) + if !found { + http.Error(w, "Creator not found", http.StatusNotFound) + return + } + + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(creator) +} + +func loadCreators(filePath string) ([]Creator, error) { + fileContent, err := os.ReadFile(filePath) + if err != nil { + return nil, fmt.Errorf("error reading file: %v", err) + } + + var creators []Creator + err = json.Unmarshal(fileContent, &creators) + if err != nil { + return nil, fmt.Errorf("error unmarshalling JSON: %v", err) + } + + return creators, nil +} + +func findCreator(creators []Creator, creatorID string) (Creator, bool) { + for _, creator := range creators { + if _, ok := creator[creatorID]; ok { + return creator, true + } + } + return nil, false +} diff --git a/packages/api/go.mod b/packages/api/go.mod index 193d19b..2b5dc76 100644 --- a/packages/api/go.mod +++ b/packages/api/go.mod @@ -1,3 +1,3 @@ -module example/web-service-gin +module creatorlink/api go 1.23.0 diff --git a/packages/api/main.go b/packages/api/main.go index c9ecbf5..b130455 100644 --- a/packages/api/main.go +++ b/packages/api/main.go @@ -1,2 +1,13 @@ package main +import ( + "log" +) + +func main() { + server := NewAPIServer(":6575") + server.Run() + if server != nil { + log.Fatal(server) + } +}