diff --git a/cmd/tokidoki/main.go b/cmd/tokidoki/main.go new file mode 100644 index 0000000..3279797 --- /dev/null +++ b/cmd/tokidoki/main.go @@ -0,0 +1,41 @@ +package main + +import ( + "flag" + "log" + "net/http" + "os" + + "github.com/go-chi/chi/v5" + "github.com/go-chi/chi/v5/middleware" +) + +func main() { + var ( + addr string + ) + flag.StringVar(&addr, "addr", ":8080", "listening address") + flag.Parse() + + if len(flag.Args()) != 0 { + flag.Usage() + os.Exit(1) + } + + mux := chi.NewRouter() + mux.Use(middleware.Logger) + + mux.Get("/", func (w http.ResponseWriter, r *http.Request) { + w.Write([]byte("Hello world!\n")) + }) + + server := http.Server { + Addr: addr, + Handler: mux, + } + log.Printf("Server running on %s", addr) + err := server.ListenAndServe() + if err != http.ErrServerClosed { + log.Fatalf("ListenAndServe: %s", err.Error()) + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..788df4c --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module git.sr.ht/~sircmpwn/tokidoki + +go 1.17 + +require github.com/go-chi/chi/v5 v5.0.7 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..433d671 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8= +github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=