diff --git a/images/README.md b/images/README.md new file mode 100644 index 0000000..08b5eb8 --- /dev/null +++ b/images/README.md @@ -0,0 +1,5 @@ +# Image Service + +```sh +curl -v localhost:5000/images/1/ --data-binary @ +``` diff --git a/images/files/local_test.go b/images/files/local_test.go index 880f40b..d901aff 100644 --- a/images/files/local_test.go +++ b/images/files/local_test.go @@ -17,7 +17,7 @@ func setupLocal(t *testing.T) (*Local, string, func()) { t.Fatal(err) } - l, err := NewLocal(dir) + l, err := NewLocal(dir, 100) if err != nil { t.Fatal(err) } diff --git a/images/frappuccino.png b/images/frappuccino.png new file mode 100644 index 0000000..555dfa4 Binary files /dev/null and b/images/frappuccino.png differ diff --git a/images/go.mod b/images/go.mod index 09253dd..48445f7 100644 --- a/images/go.mod +++ b/images/go.mod @@ -5,5 +5,6 @@ go 1.14 require ( github.com/gorilla/mux v1.7.4 github.com/hashicorp/go-hclog v0.14.1 + github.com/stretchr/testify v1.6.1 golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 ) diff --git a/images/go.sum b/images/go.sum index 1e92988..fea1ef6 100644 --- a/images/go.sum +++ b/images/go.sum @@ -1,3 +1,5 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= @@ -10,9 +12,19 @@ github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVc github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10= github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20191008105621-543471e840be h1:QAcqgptGM8IQBC9K/RC4o+O9YmqEm0diQn9QmZw/0mU= golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/images/handlers/middleware.go b/images/handlers/middleware.go new file mode 100644 index 0000000..0a792d6 --- /dev/null +++ b/images/handlers/middleware.go @@ -0,0 +1,24 @@ +package handlers + +import ( + "compress/gzip" + "net/http" +) + +// GZipResponseMiddleware detects if the client can handle zipped content and if +// so returns the response in GZipped format +func GZipResponseMiddleware(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + next.ServeHTTP(w, r) + }) +} + +type WrappedResponseWriter struct { + w http.ResponseWriter + g *gzip.Writer +} + +func NewWrappedResponseWriter(w http.ResponseWriter) *WrappedResponseWriter { + g := gzip.NewWriter(w) + return &WrappedResponseWriter{w, g} +} diff --git a/images/imagestore/1/frap.png b/images/imagestore/1/frap.png new file mode 100644 index 0000000..555dfa4 Binary files /dev/null and b/images/imagestore/1/frap.png differ