diff --git a/2022/01/golang_demo1/.gitignore b/2022/01/golang_demo1/.gitignore new file mode 100644 index 0000000..c38fa4e --- /dev/null +++ b/2022/01/golang_demo1/.gitignore @@ -0,0 +1,2 @@ +.idea +*.iml diff --git a/2022/01/golang_demo1/Program.go b/2022/01/golang_demo1/Program.go new file mode 100644 index 0000000..a6ea32b --- /dev/null +++ b/2022/01/golang_demo1/Program.go @@ -0,0 +1,23 @@ +package main + +import ( + "encoding/json" + "fmt" + "net/http" +) + +func main() { + fmt.Println("Hello World!!!") + f := func(writer http.ResponseWriter, req *http.Request) { + writer.Header().Set("Content-Type", "application/json") + m := map[string]string{ + "result": "ok", + } + p, _ := json.Marshal(m) + writer.WriteHeader(201) + _, _ = writer.Write(p) + } + + http.HandleFunc("/", f) + _ = http.ListenAndServe(":8080", nil) +}