Skip to content

Commit

Permalink
ci: add stylecheck to golangci-lint (#9334)
Browse files Browse the repository at this point in the history
This commit was moved from ipfs/kubo@e550d9e
  • Loading branch information
guseggert authored Oct 6, 2022
1 parent 7d12bb8 commit 637ed0f
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions gateway/core/corehttp/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func GatewayOption(writable bool, paths ...string) ServeOption {

AddAccessControlHeaders(headers)

offlineApi, err := api.WithOptions(options.Api.Offline(true))
offlineAPI, err := api.WithOptions(options.Api.Offline(true))
if err != nil {
return nil, err
}
Expand All @@ -86,7 +86,7 @@ func GatewayOption(writable bool, paths ...string) ServeOption {
Headers: headers,
Writable: writable,
FastDirIndexThreshold: int(cfg.Gateway.FastDirIndexThreshold.WithDefault(100)),
}, api, offlineApi)
}, api, offlineAPI)

gateway = otelhttp.NewHandler(gateway, "Gateway.Request")

Expand Down
16 changes: 8 additions & 8 deletions gateway/core/corehttp/gateway_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const (
)

var (
onlyAscii = regexp.MustCompile("[[:^ascii:]]")
onlyASCII = regexp.MustCompile("[[:^ascii:]]")
noModtime = time.Unix(0, 0) // disables Last-Modified header if passed as modtime
)

Expand Down Expand Up @@ -68,7 +68,7 @@ type redirectTemplateData struct {
type gatewayHandler struct {
config GatewayConfig
api NodeAPI
offlineApi NodeAPI
offlineAPI NodeAPI

// generic metrics
firstContentBlockGetMetric *prometheus.HistogramVec
Expand Down Expand Up @@ -214,15 +214,15 @@ func newGatewayHistogramMetric(name string, help string) *prometheus.HistogramVe

// NewGatewayHandler returns an http.Handler that can act as a gateway to IPFS content
// offlineApi is a version of the API that should not make network requests for missing data
func NewGatewayHandler(c GatewayConfig, api NodeAPI, offlineApi NodeAPI) http.Handler {
return newGatewayHandler(c, api, offlineApi)
func NewGatewayHandler(c GatewayConfig, api NodeAPI, offlineAPI NodeAPI) http.Handler {
return newGatewayHandler(c, api, offlineAPI)
}

func newGatewayHandler(c GatewayConfig, api NodeAPI, offlineApi NodeAPI) *gatewayHandler {
func newGatewayHandler(c GatewayConfig, api NodeAPI, offlineAPI NodeAPI) *gatewayHandler {
i := &gatewayHandler{
config: c,
api: api,
offlineApi: offlineApi,
offlineAPI: offlineAPI,
// Improved Metrics
// ----------------------------
// Time till the first content block (bar in /ipfs/cid/foo/bar)
Expand Down Expand Up @@ -683,7 +683,7 @@ func addContentDispositionHeader(w http.ResponseWriter, r *http.Request, content
// Set Content-Disposition to arbitrary filename and disposition
func setContentDispositionHeader(w http.ResponseWriter, filename string, disposition string) {
utf8Name := url.PathEscape(filename)
asciiName := url.PathEscape(onlyAscii.ReplaceAllLiteralString(filename, "_"))
asciiName := url.PathEscape(onlyASCII.ReplaceAllLiteralString(filename, "_"))
w.Header().Set("Content-Disposition", fmt.Sprintf("%s; filename=\"%s\"; filename*=UTF-8''%s", disposition, asciiName, utf8Name))
}

Expand Down Expand Up @@ -933,7 +933,7 @@ func (i *gatewayHandler) handlePathResolution(w http.ResponseWriter, r *http.Req
// https://github.com/ipfs/specs/blob/main/http-gateways/PATH_GATEWAY.md#cache-control-request-header
func (i *gatewayHandler) handleOnlyIfCached(w http.ResponseWriter, r *http.Request, contentPath ipath.Path, logger *zap.SugaredLogger) (requestHandled bool) {
if r.Header.Get("Cache-Control") == "only-if-cached" {
_, err := i.offlineApi.Block().Stat(r.Context(), contentPath)
_, err := i.offlineAPI.Block().Stat(r.Context(), contentPath)
if err != nil {
if r.Method == http.MethodHead {
w.WriteHeader(http.StatusPreconditionFailed)
Expand Down
10 changes: 5 additions & 5 deletions gateway/core/corehttp/gateway_handler_unixfs_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ func (i *gatewayHandler) serveDirectory(ctx context.Context, w http.ResponseWrit
webError(w, "failed to parse request path", err, http.StatusInternalServerError)
return
}
originalUrlPath := requestURI.Path
originalURLPath := requestURI.Path

// Ensure directory paths end with '/'
if originalUrlPath[len(originalUrlPath)-1] != '/' {
if originalURLPath[len(originalURLPath)-1] != '/' {
// don't redirect to trailing slash if it's go get
// https://github.com/ipfs/kubo/pull/3963
goget := r.URL.Query().Get("go-get") == "1"
Expand All @@ -53,7 +53,7 @@ func (i *gatewayHandler) serveDirectory(ctx context.Context, w http.ResponseWrit
suffix = suffix + "?" + r.URL.RawQuery
}
// /ipfs/cid/foo?bar must be redirected to /ipfs/cid/foo/?bar
redirectURL := originalUrlPath + suffix
redirectURL := originalURLPath + suffix
logger.Debugw("directory location moved permanently", "status", http.StatusMovedPermanently)
http.Redirect(w, r, redirectURL, http.StatusMovedPermanently)
return
Expand Down Expand Up @@ -125,7 +125,7 @@ func (i *gatewayHandler) serveDirectory(ctx context.Context, w http.ResponseWrit
di := directoryItem{
Size: "", // no size because we did not fetch child nodes
Name: link.Name,
Path: gopath.Join(originalUrlPath, link.Name),
Path: gopath.Join(originalURLPath, link.Name),
Hash: hash,
ShortHash: shortHash(hash),
}
Expand All @@ -149,7 +149,7 @@ func (i *gatewayHandler) serveDirectory(ctx context.Context, w http.ResponseWrit

// construct the correct back link
// https://github.com/ipfs/kubo/issues/1365
var backLink string = originalUrlPath
backLink := originalURLPath

// don't go further up than /ipfs/$hash/
pathSplit := path.SplitList(contentPath.String())
Expand Down
4 changes: 2 additions & 2 deletions gateway/core/corehttp/gateway_indexPage.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ func init() {

// custom template-escaping function to escape a full path, including '#' and '?'
urlEscape := func(rawUrl string) string {
pathUrl := url.URL{Path: rawUrl}
return pathUrl.String()
pathURL := url.URL{Path: rawUrl}
return pathURL.String()
}

// Directory listing template
Expand Down
6 changes: 3 additions & 3 deletions gateway/core/corehttp/lazyseek_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ type badSeeker struct {
io.ReadSeeker
}

var badSeekErr = fmt.Errorf("I'm a bad seeker")
var errBadSeek = fmt.Errorf("bad seeker")

func (bs badSeeker) Seek(offset int64, whence int) (int64, error) {
off, err := bs.ReadSeeker.Seek(0, io.SeekCurrent)
if err != nil {
panic(err)
}
return off, badSeekErr
return off, errBadSeek
}

func TestLazySeekerError(t *testing.T) {
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestLazySeekerError(t *testing.T) {
if err == nil {
t.Fatalf("expected an error, got output %s", string(b))
}
if err != badSeekErr {
if err != errBadSeek {
t.Fatalf("expected a bad seek error, got %s", err)
}
if len(b) != 0 {
Expand Down
2 changes: 1 addition & 1 deletion gateway/core/corehttp/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ type IpfsNodeCollector struct {
Node *core.IpfsNode
}

func (_ IpfsNodeCollector) Describe(ch chan<- *prometheus.Desc) {
func (IpfsNodeCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- peersTotalMetric
}

Expand Down
6 changes: 3 additions & 3 deletions gateway/core/corehttp/p2p_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ func parseRequest(request *http.Request) (*proxyRequest, error) {

split := strings.SplitN(path, "/", 5)
if len(split) < 5 {
return nil, fmt.Errorf("Invalid request path '%s'", path)
return nil, fmt.Errorf("invalid request path '%s'", path)
}

if _, err := peer.Decode(split[2]); err != nil {
return nil, fmt.Errorf("Invalid request path '%s'", path)
return nil, fmt.Errorf("invalid request path '%s'", path)
}

if split[3] == "http" {
Expand All @@ -71,7 +71,7 @@ func parseRequest(request *http.Request) (*proxyRequest, error) {

split = strings.SplitN(path, "/", 7)
if len(split) < 7 || split[3] != "x" || split[5] != "http" {
return nil, fmt.Errorf("Invalid request path '%s'", path)
return nil, fmt.Errorf("invalid request path '%s'", path)
}

return &proxyRequest{split[2], protocol.ID("/x/" + split[4] + "/http"), split[6]}, nil
Expand Down
2 changes: 1 addition & 1 deletion gateway/core/corehttp/redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ type redirectHandler struct {
}

func (i *redirectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, i.path, 302)
http.Redirect(w, r, i.path, http.StatusFound)
}
2 changes: 1 addition & 1 deletion gateway/core/corehttp/webui.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package corehttp
// TODO: move to IPNS
const WebUIPath = "/ipfs/bafybeiageaoxg6d7npaof6eyzqbwvbubyler7bq44hayik2hvqcggg7d2y" // v2.18.1

// this is a list of all past webUI paths.
// WebUIPaths is a list of all past webUI paths.
var WebUIPaths = []string{
WebUIPath,
"/ipfs/bafybeidb5eryh72zajiokdggzo7yct2d6hhcflncji5im2y5w26uuygdsm",
Expand Down

0 comments on commit 637ed0f

Please sign in to comment.