0
Fork 0
mirror of https://github.com/willnorris/imageproxy.git synced 2024-12-16 21:56:43 -05:00
imageproxy/imageproxy.go

76 lines
1.9 KiB
Go
Raw Normal View History

// 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.
package main
import (
"flag"
"fmt"
"log"
"net/http"
2013-12-04 06:12:56 -05:00
"strings"
2013-12-25 21:48:10 -05:00
"github.com/gregjones/httpcache"
"github.com/gregjones/httpcache/diskcache"
"github.com/willnorris/imageproxy/proxy"
)
// goxc values
var (
// VERSION is the version string for imageproxy.
2013-12-26 16:55:52 -05:00
VERSION = "HEAD"
// BUILD_DATE is the timestamp of when imageproxy was built.
BUILD_DATE string
)
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")
var cacheDir = flag.String("cacheDir", "", "directory to use for file cache")
var version = flag.Bool("version", false, "print version information")
func main() {
flag.Parse()
if *version {
fmt.Printf("%v\nBuild: %v\n", VERSION, BUILD_DATE)
return
}
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)
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
server := &http.Server{
Addr: *addr,
Handler: p,
}
2013-12-26 16:55:52 -05:00
fmt.Printf("imageproxy (version %v) listening on %s\n", VERSION, server.Addr)
err := server.ListenAndServe()
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}