From cf085e93b7abc53b8ecc78c07210384e0ff8d516 Mon Sep 17 00:00:00 2001 From: Ewy~ Date: Tue, 31 Mar 2026 17:18:35 +0200 Subject: initial commit --- main.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 main.go (limited to 'main.go') diff --git a/main.go b/main.go new file mode 100644 index 0000000..d30f292 --- /dev/null +++ b/main.go @@ -0,0 +1,40 @@ +package main + +import ( + "delayed.link/pages" + _ "delayed.link/pages" + "delayed.link/storage" + "delayed.link/storage/sqlite" + "github.com/spf13/pflag" + "log" + "net" + "net/http" + "os" + "os/signal" + "syscall" +) + +var ( + port = pflag.StringP("port", "p", "8080", "port to listen on") + host = pflag.StringP("host", "h", "0.0.0.0", "host to listen on") +) + +func main() { + pflag.Parse() + + http.HandleFunc("GET /{$}", pages.Land) + http.HandleFunc("POST /", pages.Create) + http.HandleFunc("GET /l/{id}", pages.Get) + + storage.Current = sqlite.New() + defer storage.Current.Close() + err := http.ListenAndServe(net.JoinHostPort(*host, *port), http.DefaultServeMux) + log.Printf("Started listening on %v:%v\n", *host, *port) + ch := make(chan os.Signal, 1) + signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM) + <-ch + if err != nil { + log.Panic(err) + } + +} -- cgit v1.3