2013-11-27 15:10:29 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2013-12-04 05:55:56 -05:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
2013-11-27 15:10:29 -05:00
|
|
|
"log"
|
|
|
|
"net/http"
|
2013-12-04 06:12:56 -05:00
|
|
|
"strings"
|
2013-11-27 15:10:29 -05:00
|
|
|
|
2013-12-04 05:55:56 -05:00
|
|
|
"github.com/willnorris/go-imageproxy/cache"
|
2013-11-27 15:10:29 -05:00
|
|
|
"github.com/willnorris/go-imageproxy/proxy"
|
|
|
|
)
|
|
|
|
|
2013-12-04 06:58:26 -05:00
|
|
|
var addr = flag.String("addr", "localhost:8080", "TCP address to listen on")
|
2013-12-04 06:12:56 -05:00
|
|
|
var whitelist = flag.String("whitelist", "", "comma separated list of allowed remote hosts")
|
2013-12-04 05:55:56 -05:00
|
|
|
|
2013-11-27 15:10:29 -05:00
|
|
|
func main() {
|
2013-12-04 05:55:56 -05:00
|
|
|
flag.Parse()
|
|
|
|
|
2013-12-04 06:58:26 -05:00
|
|
|
fmt.Printf("go-imageproxy listening on %s\n", *addr)
|
2013-12-04 05:55:56 -05:00
|
|
|
|
2013-11-27 15:10:29 -05:00
|
|
|
p := proxy.NewProxy(nil)
|
2013-12-04 05:55:56 -05:00
|
|
|
p.Cache = cache.NewMemoryCache()
|
2013-12-04 06:12:56 -05:00
|
|
|
if *whitelist != "" {
|
|
|
|
p.Whitelist = strings.Split(*whitelist, ",")
|
|
|
|
}
|
2013-11-27 15:10:29 -05:00
|
|
|
server := &http.Server{
|
2013-12-04 06:58:26 -05:00
|
|
|
Addr: *addr,
|
2013-11-27 15:10:29 -05:00
|
|
|
Handler: p,
|
|
|
|
}
|
|
|
|
err := server.ListenAndServe()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("ListenAndServe: ", err)
|
|
|
|
}
|
|
|
|
}
|