2013-12-06 20:40:35 -05:00
|
|
|
// Copyright 2013 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
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-06 17:17:39 -05:00
|
|
|
p.MaxWidth = 2000
|
|
|
|
p.MaxHeight = 2000
|
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)
|
|
|
|
}
|
|
|
|
}
|