Skip to content

Commit ae41d3c

Browse files
authored
Bump to go 1.17 (#187)
- Specify new go version - Update usage of io/ioutil & os - Upgrade linter - Fix potential slow loris attack by adding read_header_timeout to server config.
1 parent 1e7791e commit ae41d3c

File tree

8 files changed

+125
-16
lines changed

8 files changed

+125
-16
lines changed

.github/workflows/tests.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
name: Test
1313
strategy:
1414
matrix:
15-
go-version: [ 1.15.x ]
15+
go-version: [ 1.17.x ]
1616
platform: [ ubuntu-latest ]
1717
runs-on: ${{ matrix.platform }}
1818
steps:
@@ -36,11 +36,14 @@ jobs:
3636
name: Lint & License Check
3737
runs-on: ubuntu-latest
3838
steps:
39+
- uses: actions/setup-go@v3
40+
with:
41+
go-version: 1.17
3942
- uses: actions/checkout@v3
4043
- name: golangci-lint
4144
uses: golangci/golangci-lint-action@v2
4245
with:
43-
version: v1.36
46+
version: v1.48
4447
args: --timeout=5m
4548
- name: License Check
4649
run: make license-check

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2021 ChainSafe Systems
22
# SPDX-License-Identifier: LGPL-3.0-only
33

4-
FROM golang:1.16-alpine AS builder
4+
FROM golang:1.17-alpine AS builder
55

66
RUN apk add build-base
77
WORKDIR /code

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ license-check:
3333
test:
3434
go test ./...
3535

36+
build:
37+
go build -o ./bin/crawler cmd/main.go
38+
3639
run:
3740
@echo " > \033[32mUsing Docker Container for development...\033[0m "
3841
@echo " > \033[32mRemoving old User Service stuff...\033[0m "

cmd/config/config.dev.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ server:
55
port: 8080
66
debug: true
77
read_timeout_seconds: 360
8+
read_header_timeout_seconds: 360
89
write_timeout_seconds: 360
910
cors: ["*"]
1011

go.mod

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module eth2-crawler
22

3-
go 1.16
3+
go 1.17
44

55
require (
66
github.com/99designs/gqlgen v0.16.0
@@ -23,3 +23,104 @@ require (
2323
go.mongodb.org/mongo-driver v1.8.3
2424
gopkg.in/yaml.v2 v2.4.0
2525
)
26+
27+
require (
28+
github.com/agnivade/levenshtein v1.1.0 // indirect
29+
github.com/beorn7/perks v1.0.1 // indirect
30+
github.com/btcsuite/btcd v0.22.0-beta // indirect
31+
github.com/cespare/xxhash/v2 v2.1.1 // indirect
32+
github.com/davecgh/go-spew v1.1.1 // indirect
33+
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
34+
github.com/flynn/noise v1.0.0 // indirect
35+
github.com/go-stack/stack v1.8.0 // indirect
36+
github.com/gogo/protobuf v1.3.2 // indirect
37+
github.com/golang/protobuf v1.5.2 // indirect
38+
github.com/google/gopacket v1.1.19 // indirect
39+
github.com/gorilla/websocket v1.4.2 // indirect
40+
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
41+
github.com/holiman/uint256 v1.2.0 // indirect
42+
github.com/huin/goupnp v1.0.2 // indirect
43+
github.com/ipfs/go-cid v0.0.7 // indirect
44+
github.com/ipfs/go-ipfs-util v0.0.2 // indirect
45+
github.com/ipfs/go-log v1.0.5 // indirect
46+
github.com/ipfs/go-log/v2 v2.3.0 // indirect
47+
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
48+
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
49+
github.com/jbenet/goprocess v0.1.4 // indirect
50+
github.com/kilic/bls12-381 v0.1.0 // indirect
51+
github.com/klauspost/compress v1.13.6 // indirect
52+
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
53+
github.com/koron/go-ssdp v0.0.2 // indirect
54+
github.com/libp2p/go-addr-util v0.1.0 // indirect
55+
github.com/libp2p/go-buffer-pool v0.0.2 // indirect
56+
github.com/libp2p/go-conn-security-multistream v0.2.1 // indirect
57+
github.com/libp2p/go-eventbus v0.2.1 // indirect
58+
github.com/libp2p/go-flow-metrics v0.0.3 // indirect
59+
github.com/libp2p/go-libp2p-autonat v0.4.2 // indirect
60+
github.com/libp2p/go-libp2p-blankhost v0.2.0 // indirect
61+
github.com/libp2p/go-libp2p-circuit v0.4.0 // indirect
62+
github.com/libp2p/go-libp2p-discovery v0.5.1 // indirect
63+
github.com/libp2p/go-libp2p-mplex v0.4.1 // indirect
64+
github.com/libp2p/go-libp2p-nat v0.0.6 // indirect
65+
github.com/libp2p/go-libp2p-peerstore v0.2.8 // indirect
66+
github.com/libp2p/go-libp2p-pnet v0.2.0 // indirect
67+
github.com/libp2p/go-libp2p-swarm v0.5.3 // indirect
68+
github.com/libp2p/go-libp2p-tls v0.2.0 // indirect
69+
github.com/libp2p/go-libp2p-transport-upgrader v0.4.6 // indirect
70+
github.com/libp2p/go-libp2p-yamux v0.5.4 // indirect
71+
github.com/libp2p/go-maddr-filter v0.1.0 // indirect
72+
github.com/libp2p/go-mplex v0.3.0 // indirect
73+
github.com/libp2p/go-msgio v0.0.6 // indirect
74+
github.com/libp2p/go-nat v0.0.5 // indirect
75+
github.com/libp2p/go-netroute v0.1.6 // indirect
76+
github.com/libp2p/go-openssl v0.0.7 // indirect
77+
github.com/libp2p/go-reuseport v0.0.2 // indirect
78+
github.com/libp2p/go-reuseport-transport v0.0.5 // indirect
79+
github.com/libp2p/go-sockaddr v0.1.1 // indirect
80+
github.com/libp2p/go-stream-muxer-multistream v0.3.0 // indirect
81+
github.com/libp2p/go-ws-transport v0.5.0 // indirect
82+
github.com/libp2p/go-yamux/v2 v2.2.0 // indirect
83+
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect
84+
github.com/mattn/go-isatty v0.0.13 // indirect
85+
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
86+
github.com/miekg/dns v1.1.43 // indirect
87+
github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect
88+
github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect
89+
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect
90+
github.com/minio/sha256-simd v1.0.0 // indirect
91+
github.com/mitchellh/mapstructure v1.4.1 // indirect
92+
github.com/mr-tron/base58 v1.2.0 // indirect
93+
github.com/multiformats/go-base32 v0.0.3 // indirect
94+
github.com/multiformats/go-base36 v0.1.0 // indirect
95+
github.com/multiformats/go-multiaddr-dns v0.3.1 // indirect
96+
github.com/multiformats/go-multiaddr-fmt v0.1.0 // indirect
97+
github.com/multiformats/go-multibase v0.0.3 // indirect
98+
github.com/multiformats/go-multihash v0.0.15 // indirect
99+
github.com/multiformats/go-multistream v0.2.2 // indirect
100+
github.com/multiformats/go-varint v0.0.6 // indirect
101+
github.com/opentracing/opentracing-go v1.2.0 // indirect
102+
github.com/pkg/errors v0.9.1 // indirect
103+
github.com/pmezard/go-difflib v1.0.0 // indirect
104+
github.com/prometheus/client_golang v1.11.0 // indirect
105+
github.com/prometheus/client_model v0.2.0 // indirect
106+
github.com/prometheus/common v0.30.0 // indirect
107+
github.com/prometheus/procfs v0.7.3 // indirect
108+
github.com/protolambda/bls12-381-util v0.0.0-20210720105258-a772f2aac13e // indirect
109+
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect
110+
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
111+
github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 // indirect
112+
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
113+
github.com/xdg-go/scram v1.0.2 // indirect
114+
github.com/xdg-go/stringprep v1.0.2 // indirect
115+
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
116+
go.uber.org/atomic v1.9.0 // indirect
117+
go.uber.org/multierr v1.7.0 // indirect
118+
go.uber.org/zap v1.19.0 // indirect
119+
golang.org/x/crypto v0.0.0-20210813211128-0a44fdfbc16e // indirect
120+
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d // indirect
121+
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
122+
golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912 // indirect
123+
golang.org/x/text v0.3.7 // indirect
124+
google.golang.org/protobuf v1.27.1 // indirect
125+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
126+
)

resolver/ipgeolocation/ipgeolocation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"context"
99
"encoding/json"
1010
"fmt"
11-
"io/ioutil"
11+
"io"
1212
"net/http"
1313
"strconv"
1414
"time"
@@ -61,7 +61,7 @@ func (c *client) GetGeoLocation(ctx context.Context, ipAddr string) (*models.Geo
6161

6262
// nolint
6363
defer res.Body.Close()
64-
resBody, err := ioutil.ReadAll(res.Body)
64+
resBody, err := io.ReadAll(res.Body)
6565
if err != nil {
6666
return nil, fmt.Errorf("unable to read response body")
6767
}

utils/config/config.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package config
77
import (
88
"errors"
99
"fmt"
10-
"io/ioutil"
1110
"os"
1211

1312
"gopkg.in/yaml.v2"
@@ -22,10 +21,11 @@ type Configuration struct {
2221

2322
// Server holds data necessary for server configuration
2423
type Server struct {
25-
Port string `yaml:"port,omitempty"`
26-
ReadTimeout int `yaml:"read_timeout_seconds,omitempty"`
27-
WriteTimeout int `yaml:"write_timeout_seconds,omitempty"`
28-
CORS []string `yaml:"cors,omitempty"`
24+
Port string `yaml:"port,omitempty"`
25+
ReadTimeout int `yaml:"read_timeout_seconds,omitempty"`
26+
ReadHeaderTimeout int `yaml:"read_header_timeout_seconds,omitempty"`
27+
WriteTimeout int `yaml:"write_timeout_seconds,omitempty"`
28+
CORS []string `yaml:"cors,omitempty"`
2929
}
3030

3131
// Database is a MongoDB config
@@ -61,7 +61,7 @@ func loadResolverAPIKey() (string, error) {
6161

6262
// Load returns Configuration struct
6363
func Load(path string) (*Configuration, error) {
64-
bytes, err := ioutil.ReadFile(path)
64+
bytes, err := os.ReadFile(path)
6565

6666
if err != nil {
6767
return nil, fmt.Errorf("error reading config file, %w", err)

utils/server/server.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ func Start(ctx context.Context, cfg *config.Server, handler http.Handler) {
2525
})
2626

2727
server := &http.Server{
28-
Addr: ":" + cfg.Port,
29-
ReadTimeout: time.Duration(cfg.ReadTimeout) * time.Second,
30-
WriteTimeout: time.Duration(cfg.WriteTimeout) * time.Second,
31-
Handler: cors.Handler(handler),
28+
Addr: ":" + cfg.Port,
29+
ReadTimeout: time.Duration(cfg.ReadTimeout) * time.Second,
30+
ReadHeaderTimeout: time.Duration(cfg.ReadHeaderTimeout) * time.Second,
31+
WriteTimeout: time.Duration(cfg.WriteTimeout) * time.Second,
32+
Handler: cors.Handler(handler),
3233
}
3334

3435
go func() {

0 commit comments

Comments
 (0)