From b968c4329cef1a9a3cb40fcf9b9d520aaee6e078 Mon Sep 17 00:00:00 2001 From: Florian Fankhauser Date: Mon, 9 Feb 2015 23:02:40 +0100 Subject: [PATCH 1/3] Initial commit of golang server --- server.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 server.go diff --git a/server.go b/server.go new file mode 100644 index 00000000..ff02e123 --- /dev/null +++ b/server.go @@ -0,0 +1,24 @@ +package main + +import ( + "fmt" + "net/http" + "os" + "io" +) + +func main() { + http.Handle("/", http.FileServer(http.Dir("./public"))) + + http.HandleFunc("/comments.json", func(w http.ResponseWriter, r *http.Request) { + file, err := os.Open("_comments.json") + if err != nil { + panic(err) + } + w.Header().Set("Content-Type", "application/json") + io.Copy(w, file) + }) + + fmt.Println("Starte Server") + http.ListenAndServe(":3000", nil) +} From 530ad798a1112e172e71615bbd6ab3eee8a8c061 Mon Sep 17 00:00:00 2001 From: Florian Fankhauser Date: Mon, 9 Feb 2015 23:05:19 +0100 Subject: [PATCH 2/3] Formatting source --- server.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/server.go b/server.go index ff02e123..128b534d 100644 --- a/server.go +++ b/server.go @@ -1,24 +1,24 @@ package main import ( - "fmt" - "net/http" - "os" - "io" + "fmt" + "io" + "net/http" + "os" ) func main() { - http.Handle("/", http.FileServer(http.Dir("./public"))) + http.Handle("/", http.FileServer(http.Dir("./public"))) - http.HandleFunc("/comments.json", func(w http.ResponseWriter, r *http.Request) { - file, err := os.Open("_comments.json") - if err != nil { - panic(err) - } - w.Header().Set("Content-Type", "application/json") - io.Copy(w, file) - }) + http.HandleFunc("/comments.json", func(w http.ResponseWriter, r *http.Request) { + file, err := os.Open("_comments.json") + if err != nil { + panic(err) + } + w.Header().Set("Content-Type", "application/json") + io.Copy(w, file) + }) - fmt.Println("Starte Server") - http.ListenAndServe(":3000", nil) + fmt.Println("Starte Server") + http.ListenAndServe(":3000", nil) } From d81d5a6c9911b38fb8687d018f5cef37675f8a24 Mon Sep 17 00:00:00 2001 From: Florian Fankhauser Date: Mon, 9 Feb 2015 23:06:52 +0100 Subject: [PATCH 3/3] Remove debug code --- server.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/server.go b/server.go index 128b534d..ddf8b9c1 100644 --- a/server.go +++ b/server.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "io" "net/http" "os" @@ -19,6 +18,5 @@ func main() { io.Copy(w, file) }) - fmt.Println("Starte Server") http.ListenAndServe(":3000", nil) }