From 952c1362116698ad9b465b6e0d793961839d5743 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 13 Oct 2020 18:02:23 +0200 Subject: [PATCH] Initial commit --- .idea/MusicServer.iml | 17 +++++++++++++ .idea/modules.xml | 8 ++++++ .idea/workspace.xml | 57 +++++++++++++++++++++++++++++++++++++++++++ app.yaml | 8 ++++++ musicserver.go | 39 +++++++++++++++++++++++++++++ 5 files changed, 129 insertions(+) create mode 100644 .idea/MusicServer.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/workspace.xml create mode 100644 app.yaml create mode 100644 musicserver.go 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