From e1d0c7810937dff1516858fb03951591b5120fed Mon Sep 17 00:00:00 2001 From: Henri Koski Date: Wed, 1 Feb 2017 16:31:04 +0200 Subject: [PATCH] Equalent go benchmark --- benchmarks/golang/micro.go | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/benchmarks/golang/micro.go b/benchmarks/golang/micro.go index ee87387..52062c6 100644 --- a/benchmarks/golang/micro.go +++ b/benchmarks/golang/micro.go @@ -1,28 +1,22 @@ package main -import ( - "io" - "net/http" -) +import "net/http" -func hello(response http.ResponseWriter, request *http.Request) { - header := response.Header() - header["Date"] = nil +var ( + helloResp = []byte("Hello world!") + notFoundResp = []byte("Not Found") +) - var text string - var status int - if request.URL.Path == "/" { - status = 200 - text = "Hello world!" - } else { - status = 404 - text = "Not Found" - } - response.WriteHeader(status) - io.WriteString(response, text) +func hello(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/" { + w.WriteHeader(http.StatusNotFound) + w.Write(notFoundResp) + return + } + w.Write(helloResp) } func main() { - http.HandleFunc("/", hello) - http.ListenAndServe("0.0.0.0:8080", nil) + http.HandleFunc("/", hello) + http.ListenAndServe("0.0.0.0:8080", nil) }