mirror of
https://github.com/willnorris/imageproxy.git
synced 2024-12-30 22:34:18 -05:00
parent
dfcfda52de
commit
50e0d1104d
7 changed files with 89 additions and 0 deletions
|
@ -287,6 +287,13 @@ you want to use a different caching implementation, it's probably easiest to
|
|||
just make a copy of `cmd/imageproxy/main.go` and customize it to fit your
|
||||
needs... it's a very simple command.
|
||||
|
||||
### Environment Variables ###
|
||||
|
||||
All configuration flags have equivalent environment variables of the form
|
||||
`IMAGEPROXY_$NAME`. For example, an on-disk cache could be configured by calling
|
||||
|
||||
IMAGEPROXY_CACHE="/tmp/imageproxy" imageproxy
|
||||
|
||||
## Deploying ##
|
||||
|
||||
In most cases, you can follow the normal procedure for building a deploying any
|
||||
|
|
|
@ -33,6 +33,7 @@ import (
|
|||
"github.com/garyburd/redigo/redis"
|
||||
"github.com/gregjones/httpcache/diskcache"
|
||||
rediscache "github.com/gregjones/httpcache/redis"
|
||||
"github.com/jamiealquiza/envy"
|
||||
"github.com/peterbourgon/diskv"
|
||||
"willnorris.com/go/imageproxy"
|
||||
"willnorris.com/go/imageproxy/internal/gcscache"
|
||||
|
@ -60,6 +61,7 @@ func init() {
|
|||
}
|
||||
|
||||
func main() {
|
||||
envy.Parse("IMAGEPROXY")
|
||||
flag.Parse()
|
||||
|
||||
p := imageproxy.NewProxy(nil, cache.Cache)
|
||||
|
|
4
go.mod
4
go.mod
|
@ -17,6 +17,7 @@ require (
|
|||
github.com/gregjones/httpcache v0.0.0-20190212212710-3befbb6ad0cc
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.8.5 // indirect
|
||||
github.com/hashicorp/golang-lru v0.5.1 // indirect
|
||||
github.com/jamiealquiza/envy v1.1.0
|
||||
github.com/marstr/guid v0.0.0-20170427235115-8bdf7d1a087c // indirect
|
||||
github.com/muesli/smartcrop v0.2.1-0.20181030220600-548bbf0c0965
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
|
||||
|
@ -36,3 +37,6 @@ require (
|
|||
|
||||
// temporary fix to https://github.com/golang/lint/issues/436 which still seems to be a problem
|
||||
replace github.com/golang/lint => github.com/golang/lint v0.0.0-20190227174305-8f45f776aaf1
|
||||
|
||||
// local copy of envy package without cobra support
|
||||
replace github.com/jamiealquiza/envy => ./third_party/envy
|
||||
|
|
21
third_party/envy/LICENSE
vendored
Normal file
21
third_party/envy/LICENSE
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017 Jamie Alquiza
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
2
third_party/envy/README.md
vendored
Normal file
2
third_party/envy/README.md
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
envy is a copy of https://github.com/jamiealquiza/envy without the cobra
|
||||
support.
|
50
third_party/envy/envy.go
vendored
Normal file
50
third_party/envy/envy.go
vendored
Normal file
|
@ -0,0 +1,50 @@
|
|||
// Package envy automatically exposes environment
|
||||
// variables for all of your flags.
|
||||
package envy
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Parse takes a prefix string and exposes environment variables
|
||||
// for all flags in the default FlagSet (flag.CommandLine) in the
|
||||
// form of PREFIX_FLAGNAME.
|
||||
func Parse(p string) {
|
||||
update(p, flag.CommandLine)
|
||||
}
|
||||
|
||||
// update takes a prefix string p and *flag.FlagSet. Each flag
|
||||
// in the FlagSet is exposed as an upper case environment variable
|
||||
// prefixed with p. Any flag that was not explicitly set by a user
|
||||
// is updated to the environment variable, if set.
|
||||
func update(p string, fs *flag.FlagSet) {
|
||||
// Build a map of explicitly set flags.
|
||||
set := map[string]interface{}{}
|
||||
fs.Visit(func(f *flag.Flag) {
|
||||
set[f.Name] = nil
|
||||
})
|
||||
|
||||
fs.VisitAll(func(f *flag.Flag) {
|
||||
// Create an env var name
|
||||
// based on the supplied prefix.
|
||||
envVar := fmt.Sprintf("%s_%s", p, strings.ToUpper(f.Name))
|
||||
envVar = strings.Replace(envVar, "-", "_", -1)
|
||||
|
||||
// Update the Flag.Value if the
|
||||
// env var is non "".
|
||||
if val := os.Getenv(envVar); val != "" {
|
||||
// Update the value if it hasn't
|
||||
// already been set.
|
||||
if _, defined := set[f.Name]; !defined {
|
||||
fs.Set(f.Name, val)
|
||||
}
|
||||
}
|
||||
|
||||
// Append the env var to the
|
||||
// Flag.Usage field.
|
||||
f.Usage = fmt.Sprintf("%s [%s]", f.Usage, envVar)
|
||||
})
|
||||
}
|
3
third_party/envy/go.mod
vendored
Normal file
3
third_party/envy/go.mod
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
module .
|
||||
|
||||
go 1.12
|
Loading…
Reference in a new issue