Initial server skeleton
This commit is contained in:
parent
c804095480
commit
96ef5f9b2a
41
cmd/tokidoki/main.go
Normal file
41
cmd/tokidoki/main.go
Normal 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
5
go.mod
Normal 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
|
Loading…
Reference in New Issue
Block a user