implement running options

This commit is contained in:
csehviktor
2025-08-01 22:01:43 +02:00
parent aed36d860d
commit a9e46f5fcf
3 changed files with 32 additions and 12 deletions

14
main.go
View File

@@ -1,6 +1,7 @@
package main
import (
"flag"
"log/slog"
"net/http"
@@ -8,12 +9,17 @@ import (
"github.com/csehviktor/pastebin/store"
)
const addr = ":3000"
func main() {
addrPtr := flag.String("addr", ":3000", "port to listen on")
maxSizePtr := flag.Int("max-size", 32*1024, "maximum size of a paste in bytes")
flag.Parse()
addr := *addrPtr
maxSize := int64(*maxSizePtr)
mux := http.NewServeMux()
store := store.NewMemoryStore()
httpHandler := handler.NewHandler(store)
httpHandler := handler.NewHandler(store, maxSize)
mux.HandleFunc("GET /style.css", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "view/style.css")
@@ -23,7 +29,7 @@ func main() {
mux.HandleFunc("GET /{id}", httpHandler.HandleGet)
mux.HandleFunc("GET /{id}/{theme}", httpHandler.HandleGet)
slog.Info("starting http server on", "addr", addr)
slog.Info("starting http server", "addr", addr, "maxSize", maxSize)
err := http.ListenAndServe(addr, mux)
if err != nil {
panic(err)