commit 952c1362116698ad9b465b6e0d793961839d5743 Author: Sebastian Date: Tue Oct 13 18:02:23 2020 +0200 Initial commit diff --git a/.idea/MusicServer.iml b/.idea/MusicServer.iml new file mode 100644 index 0000000..ab1898c --- /dev/null +++ b/.idea/MusicServer.iml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..9ce91d9 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..83a0dd8 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app.yaml b/app.yaml new file mode 100644 index 0000000..def3f4a --- /dev/null +++ b/app.yaml @@ -0,0 +1,8 @@ +application: musicserver +version: 1 +runtime: go115 +api_version: go1 + +handlers: +- url: /.* + script: _go_app \ No newline at end of file diff --git a/musicserver.go b/musicserver.go new file mode 100644 index 0000000..2c6ea7b --- /dev/null +++ b/musicserver.go @@ -0,0 +1,39 @@ +package main + +import ( + "fmt" + "log" + "net/http" + "os" +) + +func main() { + http.HandleFunc("/", indexHandler) + port := os.Getenv("PORT") + if port == "" { + port = "8080" + log.Printf("Defaulting to port %s", port) + } + + log.Printf("Listening on port %s", port) + log.Printf("Open http://localhost:%s in the browser", port) + log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil)) +} + +func indexHandler(w http.ResponseWriter, r *http.Request) { + if r.URL.Path == "/test" { + _, err := fmt.Fprint(w, "Testing path") + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + } + } else if r.URL.Path == "/" { + _, err := fmt.Fprint(w, "Hello, World!!") + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + } + } else { + http.NotFound(w, r) + return + } + +} \ No newline at end of file