diff --git a/main.go b/main.go index dd941d0..69ca06e 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( + "flag" "fmt" "log" "net/http" @@ -12,13 +13,22 @@ import ( "github.com/davidbyttow/govips/pkg/vips" ) +var ( + imgServer = flag.String("s", "https://images.example.com/", "URL prefix") + listenAddr = flag.Int("l", "0.0.0.0:8080", "Listen address") +) + +func init() { + flag.Parse() +} + func main() { // Start vips with the default configuration vips.Startup(nil) defer vips.Shutdown() http.HandleFunc("/", resizeHandler) - log.Fatal(http.ListenAndServe("0.0.0.0:4444", nil)) + log.Fatal(http.ListenAndServe(listenAddr, nil)) } func resizeHandler(w http.ResponseWriter, r *http.Request) { @@ -57,7 +67,7 @@ func resizeHandler(w http.ResponseWriter, r *http.Request) { } // Start fetching the image from the given url - resp, err := http.Get(queryUrl) + resp, err := http.Get(imgServer + queryUrl) if err != nil { w.Write([]byte(fmt.Sprintf("failed to get %s: %v", queryUrl, err))) w.WriteHeader(http.StatusBadRequest)