Configurable img server prefix and listen address

This commit is contained in:
Andreas Neue 2019-01-09 09:15:04 +01:00
parent f76b07ed5c
commit 4853a60cb0
1 changed files with 12 additions and 2 deletions

14
main.go
View File

@ -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)