diff options
| author | Ewy~ <ewy0@protonmail.com> | 2026-03-31 17:18:35 +0200 |
|---|---|---|
| committer | Ewy~ <ewy0@protonmail.com> | 2026-03-31 17:18:35 +0200 |
| commit | cf085e93b7abc53b8ecc78c07210384e0ff8d516 (patch) | |
| tree | 270bc83c7e4d1c468bd7fcc61d2d65d6f447eda6 /main.go | |
initial commit
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 40 |
1 files changed, 40 insertions, 0 deletions
@@ -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) + } + +} |
