From 96ef5f9b2af166b19b8d0d0465f8bd374d9a0ff7 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 21 Feb 2022 10:10:25 +0100 Subject: [PATCH] Initial server skeleton --- cmd/tokidoki/main.go | 41 +++++++++++++++++++++++++++++++++++++++++ go.mod | 5 +++++ go.sum | 2 ++ 3 files changed, 48 insertions(+) create mode 100644 cmd/tokidoki/main.go create mode 100644 go.mod create mode 100644 go.sum 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=