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-25 21:48:10 -05:00
|
|
|
"github.com/gregjones/httpcache"
|
2013-12-26 11:06:00 -05:00
|
|
|
"github.com/gregjones/httpcache/diskcache"
|
2013-12-26 14:14:28 -05:00
|
|
|
"github.com/willnorris/imageproxy/proxy"
|
2013-11-27 15:10:29 -05:00
|
|
|
)
|
|
|
|
|
2013-12-26 14:00:50 -05:00
|
|
|
// goxc values
|
|
|
|
var (
|
2013-12-26 14:14:28 -05:00
|
|
|
// VERSION is the version string for imageproxy.
|
2013-12-26 16:55:52 -05:00
|
|
|
VERSION = "HEAD"
|
|
|
|
|
2013-12-26 14:14:28 -05:00
|
|
|
// BUILD_DATE is the timestamp of when imageproxy was built.
|
2013-12-26 14:00:50 -05:00
|
|
|
BUILD_DATE string
|
|
|
|
)
|
|
|
|
|
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-26 11:06:00 -05:00
|
|
|
var cacheDir = flag.String("cacheDir", "", "directory to use for file cache")
|
2013-12-26 14:00:50 -05:00
|
|
|
var version = flag.Bool("version", false, "print version information")
|
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-26 14:00:50 -05:00
|
|
|
if *version {
|
|
|
|
fmt.Printf("%v\nBuild: %v\n", VERSION, BUILD_DATE)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2013-12-26 11:06:00 -05:00
|
|
|
var c httpcache.Cache
|
|
|
|
if *cacheDir != "" {
|
|
|
|
c = diskcache.New(*cacheDir)
|
|
|
|
} else {
|
|
|
|
c = httpcache.NewMemoryCache()
|
|
|
|
}
|
|
|
|
|
2013-12-25 21:48:10 -05:00
|
|
|
p := proxy.NewProxy(nil, c)
|
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-12-26 16:55:52 -05:00
|
|
|
|
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,
|
|
|
|
}
|
2013-12-26 16:55:52 -05:00
|
|
|
|
|
|
|
fmt.Printf("imageproxy (version %v) listening on %s\n", VERSION, server.Addr)
|
2013-11-27 15:10:29 -05:00
|
|
|
err := server.ListenAndServe()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("ListenAndServe: ", err)
|
|
|
|
}
|
|
|
|
}
|