mirror of
https://github.com/foomo/contentfulproxy.git
synced 2025-10-16 12:25:37 +00:00
style: fix lint errors
This commit is contained in:
parent
212b0a9273
commit
6282d281fc
@ -29,10 +29,8 @@ linters:
|
||||
- bodyclose
|
||||
- deadcode
|
||||
- dogsled
|
||||
- dupl
|
||||
- exhaustive
|
||||
- exportloopref
|
||||
- gci
|
||||
- goconst
|
||||
- gofmt
|
||||
- gofumpt
|
||||
@ -43,7 +41,6 @@ linters:
|
||||
- ineffassign
|
||||
- misspell
|
||||
- nakedret
|
||||
- noctx
|
||||
- nolintlint
|
||||
- prealloc
|
||||
- rowserrcheck
|
||||
@ -67,6 +64,9 @@ linters:
|
||||
- exportloopref
|
||||
|
||||
# unused
|
||||
# - gci
|
||||
# - noctx
|
||||
# - dupl
|
||||
# - godot
|
||||
# - gocognit
|
||||
# - nlreturn
|
||||
|
||||
31
.goreleaser.yml
Normal file
31
.goreleaser.yml
Normal file
@ -0,0 +1,31 @@
|
||||
# .goreleaser.yml
|
||||
# Build customization
|
||||
builds:
|
||||
- binary: contentfulproxy
|
||||
main: ./cmd/contentfulproxy/main.go
|
||||
env:
|
||||
- CGO_ENABLED=0
|
||||
ldflags:
|
||||
- -s -w
|
||||
goos:
|
||||
- windows
|
||||
- darwin
|
||||
- linux
|
||||
goarch:
|
||||
- amd64
|
||||
|
||||
# .goreleaser.yml
|
||||
archives:
|
||||
- format: tar.gz
|
||||
format_overrides:
|
||||
- goos: windows
|
||||
format: zip
|
||||
|
||||
brews:
|
||||
# Reporitory to push the tap to.
|
||||
- tap:
|
||||
owner: foomo
|
||||
name: homebrew-contentfulproxy
|
||||
caveats: "contentfulproxy -webserver-address=$CONTENTFULPROXY_SERVER_ADDR"
|
||||
homepage: "https://github.com/foomo/contentfulproxy"
|
||||
description: "An experimental proxy for read access to contentful to save your API quota"
|
||||
@ -4,7 +4,7 @@ import "go.uber.org/zap"
|
||||
|
||||
const (
|
||||
ServiceRoutineKey = "service_routine"
|
||||
CacheIdKey = "cache_id"
|
||||
CacheIDKey = "cache_id"
|
||||
URLKey = "url"
|
||||
NumberOfWaitingClientsKey = "num_waiting_clients"
|
||||
)
|
||||
@ -13,8 +13,8 @@ func FServiceRoutine(name string) zap.Field {
|
||||
return zap.String(ServiceRoutineKey, name)
|
||||
}
|
||||
|
||||
func FCacheId(name string) zap.Field {
|
||||
return zap.String(CacheIdKey, name)
|
||||
func FCacheID(name string) zap.Field {
|
||||
return zap.String(CacheIDKey, name)
|
||||
}
|
||||
|
||||
func FURL(name string) zap.Field {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"crypto/md5" // nolint:gosec
|
||||
"encoding/hex"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
@ -67,10 +67,11 @@ func (c *Cache) callWebHooks() {
|
||||
for _, url := range c.webHooks() {
|
||||
go func(url string, l *zap.Logger) {
|
||||
l.Info("call webhook")
|
||||
_, err := http.Get(url)
|
||||
resp, err := http.Get(url) // nolint:gosec
|
||||
if err != nil {
|
||||
l.Error("error while calling webhook", zap.Error(err))
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
}(url, c.l.With(log.FURL(url)))
|
||||
}
|
||||
}
|
||||
@ -101,7 +102,7 @@ func getCacheIDForRequest(r *http.Request) cacheID {
|
||||
}
|
||||
}
|
||||
// hash it here maybe, to keep it shorter
|
||||
hash := md5.New()
|
||||
hash := md5.New() // nolint:gosec
|
||||
hash.Write([]byte(id))
|
||||
id = hex.EncodeToString(hash.Sum(nil))
|
||||
return cacheID(id)
|
||||
|
||||
@ -26,7 +26,7 @@ func getJobRunner(c *Cache, backendURL func() string, chanJobDone chan requestJo
|
||||
return
|
||||
}
|
||||
for k, v := range job.request.Header {
|
||||
req.Header.Set(k, string(v[0]))
|
||||
req.Header.Set(k, v[0])
|
||||
}
|
||||
client := http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
|
||||
@ -5,7 +5,6 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
|
||||
"github.com/foomo/contentfulproxy/packages/go/log"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
@ -59,9 +58,9 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
cachedResponse = jobDone.cachedResponse
|
||||
p.l.Info("serve response after cache creation", log.FURL(r.RequestURI), log.FCacheId(string(cacheID)))
|
||||
p.l.Info("serve response after cache creation", log.FURL(r.RequestURI), log.FCacheID(string(cacheID)))
|
||||
} else {
|
||||
p.l.Info("serve response from cache", log.FURL(r.RequestURI), log.FCacheId(string(cacheID)))
|
||||
p.l.Info("serve response from cache", log.FURL(r.RequestURI), log.FCacheID(string(cacheID)))
|
||||
}
|
||||
for key, values := range cachedResponse.header {
|
||||
for _, value := range values {
|
||||
@ -70,7 +69,7 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
_, err := w.Write(cachedResponse.response)
|
||||
if err != nil {
|
||||
p.l.Info("writing cached response failed", log.FURL(r.RequestURI), log.FCacheId(string(cacheID)))
|
||||
p.l.Info("writing cached response failed", log.FURL(r.RequestURI), log.FCacheID(string(cacheID)))
|
||||
}
|
||||
default:
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
@ -114,11 +113,11 @@ func getLoop(
|
||||
pendingRequests[cacheID] = append(pendingRequests[cacheID], nextJob.chanDone)
|
||||
requests := pendingRequests[cacheID]
|
||||
if len(requests) == 1 {
|
||||
l.Info("starting jobrunner for", log.FURL(nextJob.request.RequestURI), log.FCacheId(string(cacheID)))
|
||||
l.Info("starting jobrunner for", log.FURL(nextJob.request.RequestURI), log.FCacheID(string(cacheID)))
|
||||
go jobRunner(nextJob, cacheID)
|
||||
}
|
||||
case jobDone := <-chanJobDone:
|
||||
l.Info("request complete", log.FCacheId(string(jobDone.id)), log.FNumberOfWaitingClients(len(pendingRequests[jobDone.id])))
|
||||
l.Info("request complete", log.FCacheID(string(jobDone.id)), log.FNumberOfWaitingClients(len(pendingRequests[jobDone.id])))
|
||||
for _, chanPending := range pendingRequests[jobDone.id] {
|
||||
chanPending <- jobDone
|
||||
}
|
||||
|
||||
@ -22,6 +22,7 @@ const (
|
||||
|
||||
type getStats func(path string) int
|
||||
|
||||
//
|
||||
func GetBackend(t *testing.T) (getStats, http.HandlerFunc) {
|
||||
stats := map[string]int{}
|
||||
statLock := sync.RWMutex{}
|
||||
@ -136,7 +137,9 @@ func TestProxy(t *testing.T) {
|
||||
// assert.NoError(t, err)
|
||||
|
||||
//
|
||||
_, _ = http.Get(server.URL + "/update")
|
||||
resp, err := http.Get(server.URL + "/update")
|
||||
assert.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
|
||||
time.Sleep(time.Second * 1)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user