diff --git a/README.md b/README.md index 8f5e2c0..56b6812 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ Certain sites may display missing images or encounter formatting issues. This ca - [x] Basic Auth - [x] Disable logs - [x] No Tracking +- [ ] Optional TOR proxy ## Installation diff --git a/cmd/main.go b/cmd/main.go index ef6d404..dcbbdfa 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -2,6 +2,7 @@ package main import ( _ "embed" + "fmt" "ladder/handlers" "log" @@ -9,6 +10,7 @@ import ( "strconv" "strings" + "github.com/akamensky/argparse" "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/middleware/basicauth" "github.com/gofiber/fiber/v2/middleware/favicon" @@ -19,10 +21,33 @@ var faviconData string func main() { - prefork, _ := strconv.ParseBool(os.Getenv("PREFORK")) + parser := argparse.NewParser("ladder", "Every Wall needs a Ladder") + + p := os.Getenv("PORT") + if os.Getenv("PORT") == "" { + p = "8080" + } + port := parser.String("p", "port", &argparse.Options{ + Required: false, + Default: p, + Help: "Port the webserver will listen on"}) + + pf, _ := strconv.ParseBool(os.Getenv("PREFORK")) + + prefork := parser.Flag("P", "prefork", &argparse.Options{ + Required: false, + Default: pf, + Help: "This will spawn multiple processes listening"}) + + // Parse input + err := parser.Parse(os.Args) + if err != nil { + fmt.Print(parser.Usage(err)) + } + app := fiber.New( fiber.Config{ - Prefork: prefork, + Prefork: *prefork, }, ) @@ -54,10 +79,6 @@ func main() { app.Get("api/*", handlers.Api) app.Get("/*", handlers.ProxySite) - port := os.Getenv("PORT") - if os.Getenv("PORT") == "" { - port = "8080" - } - log.Fatal(app.Listen(":" + port)) + log.Fatal(app.Listen(":" + *port)) } diff --git a/go.mod b/go.mod index 0e3e77e..25aae3b 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ require ( require ( github.com/PuerkitoBio/goquery v1.8.1 + github.com/akamensky/argparse v1.4.0 github.com/andybalholm/brotli v1.0.6 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/google/uuid v1.4.0 // indirect diff --git a/go.sum b/go.sum index 4a0a052..0b166c6 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/PuerkitoBio/goquery v1.8.1 h1:uQxhNlArOIdbrH1tr0UXwdVFgDcZDrZVdcpygAcwmWM= github.com/PuerkitoBio/goquery v1.8.1/go.mod h1:Q8ICL1kNUJ2sXGoAhPGUdYDJvgQgHzJsnnd3H7Ho5jQ= +github.com/akamensky/argparse v1.4.0 h1:YGzvsTqCvbEZhL8zZu2AiA5nq805NZh75JNj4ajn1xc= +github.com/akamensky/argparse v1.4.0/go.mod h1:S5kwC7IuDcEr5VeXtGPRVZ5o/FdhcMlQz4IZQuw64xA= github.com/andybalholm/brotli v1.0.6 h1:Yf9fFpf49Zrxb9NlQaluyE92/+X7UVHlhMNJN2sxfOI= github.com/andybalholm/brotli v1.0.6/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= github.com/andybalholm/cascadia v1.3.1 h1:nhxRkql1kdYCc8Snf7D5/D3spOX+dBgjA6u8x004T2c=