From 173a1fcc99fd81b8d677bf30a5eb673bebf57478 Mon Sep 17 00:00:00 2001 From: Marcel Edmund Franke Date: Wed, 5 Dec 2018 11:38:54 +0100 Subject: [PATCH 1/2] docker: changed start mode of service --- Dockerfile | 12 ++---------- cmd/httpcache/main.go | 2 +- entrypoint.sh | 2 -- 3 files changed, 3 insertions(+), 13 deletions(-) delete mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile index b342dbf..33f6e56 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,23 +10,15 @@ RUN mkdir -p /go/src/${PACKAGE} WORKDIR /go/src/${PACKAGE} COPY . /go/src/${PACKAGE} -RUN go build ${PACKAGE}/cmd/httpcache +RUN CGO_ENABLED=0 go build ${PACKAGE}/cmd/httpcache FROM alpine:3.7 ENV PACKAGE=github.com/donutloop/httpcache COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ - COPY --from=builder /go/src/${PACKAGE}/httpcache /httpcache -COPY --from=builder /go/src/${PACKAGE}/entrypoint.sh /entrypoint.sh -RUN chmod +x /entrypoint.sh USER nobody:nobody -ENV PORT=":8000" -ENV CAP=1000000 -ENV EXPIRE=5 - -EXPOSE 8000 -ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["./httpcache"] \ No newline at end of file diff --git a/cmd/httpcache/main.go b/cmd/httpcache/main.go index fe0b17c..54496a5 100644 --- a/cmd/httpcache/main.go +++ b/cmd/httpcache/main.go @@ -21,7 +21,7 @@ func main() { fs := flag.NewFlagSet("http-proxy", flag.ExitOnError) var ( - httpAddr = fs.String("http", ":80", "serve HTTP on this address (optional)") + httpAddr = fs.String("http", ":8000", "serve HTTP on this address (optional)") tlsAddr = fs.String("tls", "", "serve TLS on this address (optional)") cert = fs.String("cert", "server.crt", "TLS certificate") key = fs.String("key", "server.key", "TLS key") diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100644 index 14c41bf..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -/httpcache --http ${PORT} --cap ${CAP} --expire ${EXPIRE} \ No newline at end of file From e3b7b952e1c9680dbfa67ee55406be037455c522 Mon Sep 17 00:00:00 2001 From: Marcel Edmund Franke Date: Wed, 5 Dec 2018 11:42:07 +0100 Subject: [PATCH 2/2] add example for cache --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index a3feb13..289c50f 100644 --- a/README.md +++ b/README.md @@ -50,4 +50,29 @@ FLAGS -key server.key TLS key -rbcl 524288000 response size limit -tls serve TLS on this address (optional) +``` + +## Usage of cache from outside (GO Example) + +```golang +... +transport := &http.Transport{ + Proxy: SetProxyURL(proxyServer.URL), // Set url of http cache + DialContext: (&net.Dialer{ + Timeout: 30 * time.Second, + KeepAlive: 30 * time.Second, + DualStack: true, + }).DialContext, + MaxIdleConns: 100, + IdleConnTimeout: 90 * time.Second, + TLSHandshakeTimeout: 10 * time.Second, + ExpectContinueTimeout: 1 * time.Second, +} + +client = &http.Client{ + Transport: transport, +} + +client.Do(req) +... ``` \ No newline at end of file