|
@@ -0,0 +1,36 @@
|
|
|
|
+package main
|
|
|
|
+
|
|
|
|
+import (
|
|
|
|
+ "errors"
|
|
|
|
+ "log"
|
|
|
|
+ "net/http"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+const (
|
|
|
|
+ addr = ":8080"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+/*
|
|
|
|
+@app.route("/")
|
|
|
|
+def index():
|
|
|
|
+*/
|
|
|
|
+func RouteIndex(w http.ResponseWriter, r *http.Request) {
|
|
|
|
+ w.Write([]byte("Hello World!"))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func setupRoutes(mux *http.ServeMux) {
|
|
|
|
+ mux.HandleFunc("/", RouteIndex)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func main() {
|
|
|
|
+ mux := http.NewServeMux()
|
|
|
|
+ setupRoutes(mux)
|
|
|
|
+ log.Printf("Listening on http://localhost%s", addr)
|
|
|
|
+ if err := http.ListenAndServe(addr, mux); err != nil {
|
|
|
|
+ if !errors.Is(err, http.ErrServerClosed) {
|
|
|
|
+ log.Printf("Server error: %v\n", err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ log.Println("Server shutdown")
|
|
|
|
+}
|