Initial server skeleton

This commit is contained in:
Drew DeVault 2022-02-21 10:10:25 +01:00
parent c804095480
commit 96ef5f9b2a
3 changed files with 48 additions and 0 deletions

41
cmd/tokidoki/main.go Normal file
View File

@ -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())
}
}

5
go.mod Normal file
View File

@ -0,0 +1,5 @@
module git.sr.ht/~sircmpwn/tokidoki
go 1.17
require github.com/go-chi/chi/v5 v5.0.7 // indirect

2
go.sum Normal file
View File

@ -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=