Skip to content

Commit 2ade4b9

Browse files
committed
deps: remove deprecated functions and use rand/v2
1 parent b4352b1 commit 2ade4b9

File tree

7 files changed

+90
-98
lines changed

7 files changed

+90
-98
lines changed

.air.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ cmd = "go build -o ./tmp/go-judge ./cmd/go-judge"
55
full_bin = "tmp/go-judge -enable-grpc -enable-debug -enable-metrics -http-addr=:5050 -grpc-addr=:5051"
66

77
include_ext = ["go"]
8-
exclude_dir = ["dist"]
8+
exclude_dir = ["dist", "node_modules"]

.github/workflows/build.yml

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,26 @@ jobs:
1010
name: Goreleaser
1111
runs-on: ubuntu-latest
1212
steps:
13-
-
14-
name: Checkout
13+
- name: Checkout
1514
uses: actions/checkout@v4
1615
with:
1716
fetch-depth: 0
18-
-
19-
name: Fetch all tags
17+
- name: Fetch all tags
2018
run: git fetch --force --tags
21-
-
22-
name: Set up QEMU
19+
- name: Set up QEMU
2320
uses: docker/setup-qemu-action@v3
24-
-
25-
name: Set up Docker Buildx
21+
- name: Set up Docker Buildx
2622
uses: docker/setup-buildx-action@v3
27-
-
28-
name: Login to DockerHub
23+
- name: Login to DockerHub
2924
uses: docker/login-action@v3
3025
with:
3126
username: ${{ secrets.DOCKERHUB_USERNAME }}
3227
password: ${{ secrets.DOCKERHUB_TOKEN }}
33-
-
34-
name: Set up Go
28+
- name: Set up Go
3529
uses: actions/setup-go@v5
3630
with:
37-
go-version: '1.22'
38-
-
39-
name: Run GoReleaser
31+
go-version: "1.22"
32+
- name: Run GoReleaser
4033
uses: goreleaser/goreleaser-action@v5
4134
if: ${{ contains(github.ref, 'v') }}
4235
with:
@@ -46,8 +39,7 @@ jobs:
4639
args: release --clean
4740
env:
4841
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49-
-
50-
name: Test GoReleaser
42+
- name: Test GoReleaser
5143
uses: goreleaser/goreleaser-action@v5
5244
if: ${{ ! contains(github.ref, 'v') }}
5345
with:
@@ -65,7 +57,7 @@ jobs:
6557
- ubuntu-latest
6658
- macos-latest
6759
GOARCH:
68-
- amd64
60+
- amd64
6961
include:
7062
- os: ubuntu-latest
7163
GOARCH: "386"
@@ -75,15 +67,15 @@ jobs:
7567
GOARCH: "arm64"
7668
- os: ubuntu-latest
7769
GOARCH: "riscv64"
78-
- os: macos-latest
70+
- os: macos-latest
7971
GOARCH: "arm64"
8072
steps:
8173
- name: Check out
8274
uses: actions/checkout@v4
8375
- name: Set up Go 1.22
8476
uses: actions/setup-go@v5
8577
with:
86-
go-version: '1.22'
78+
go-version: "1.22"
8779
- name: Get git tag ref
8880
run: git fetch --prune --unshallow --tags
8981
- name: Download dependencies
@@ -92,7 +84,7 @@ jobs:
9284
run: go generate ./cmd/go-judge/version
9385

9486
- name: Build on Linux
95-
if: ${{ matrix.os == 'ubuntu-latest' }}
87+
if: ${{ matrix.os == 'ubuntu-latest' }}
9688
env:
9789
GOARCH: ${{ matrix.GOARCH }}
9890
CGO_ENABLE: 0
@@ -101,31 +93,31 @@ jobs:
10193
go build -v -o go-judge-shell ./cmd/go-judge-shell
10294
go build -o go-judge-init ./cmd/go-judge-init
10395
- name: Build shared objects on Linux
104-
if: ${{ matrix.os == 'ubuntu-latest' && matrix.GOARCH == 'amd64' }}
96+
if: ${{ matrix.os == 'ubuntu-latest' && matrix.GOARCH == 'amd64' }}
10597
env:
10698
GOARCH: ${{ matrix.GOARCH }}
10799
run: |
108100
go build -buildmode=c-shared -o go-judge.so ./cmd/go-judge-ffi
109101
- name: Upload go-judge on linux
110-
if: ${{ matrix.os == 'ubuntu-latest' }}
102+
if: ${{ matrix.os == 'ubuntu-latest' }}
111103
uses: actions/upload-artifact@v4
112104
with:
113105
name: go-judge-${{ matrix.GOARCH }}
114106
path: go-judge
115107
- name: Upload go-judge-shell on linux
116-
if: ${{ matrix.os == 'ubuntu-latest' }}
108+
if: ${{ matrix.os == 'ubuntu-latest' }}
117109
uses: actions/upload-artifact@v4
118110
with:
119111
name: go-judge-shell-${{ matrix.GOARCH }}
120112
path: go-judge-shell
121113
- name: Upload go-judge-init on linux
122-
if: ${{ matrix.os == 'ubuntu-latest' }}
114+
if: ${{ matrix.os == 'ubuntu-latest' }}
123115
uses: actions/upload-artifact@v4
124116
with:
125117
name: go-judge-init-${{ matrix.GOARCH }}
126118
path: go-judge-init
127119
- name: Upload go-judge.so on linux
128-
if: ${{ matrix.os == 'ubuntu-latest' && matrix.GOARCH == 'amd64' }}
120+
if: ${{ matrix.os == 'ubuntu-latest' && matrix.GOARCH == 'amd64' }}
129121
uses: actions/upload-artifact@v4
130122
with:
131123
name: go-judge-${{ matrix.GOARCH }}.so
@@ -186,4 +178,4 @@ jobs:
186178
uses: actions/upload-artifact@v4
187179
with:
188180
name: go-judge-${{ matrix.GOARCH }}.dylib
189-
path: go-judge.dylib
181+
path: go-judge.dylib

cmd/go-judge-grpc-proxy/proxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func main() {
135135
if token != "" {
136136
opts = append(opts, grpc.WithPerRPCCredentials(newTokenAuth(token)))
137137
}
138-
conn, err := grpc.Dial(*srvAddr, opts...)
138+
conn, err := grpc.NewClient(*srvAddr, opts...)
139139
if err != nil {
140140
log.Fatalln("client", err)
141141
}

cmd/go-judge-shell/grpc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func newGrpc(args []string, srvAddr string) Stream {
2727
if token != "" {
2828
opts = append(opts, grpc.WithPerRPCCredentials(newTokenAuth(token)))
2929
}
30-
conn, err := grpc.Dial(srvAddr, opts...)
30+
conn, err := grpc.NewClient(srvAddr, opts...)
3131
if err != nil {
3232
log.Fatalln("client", err)
3333
}

filestore/interface.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ package filestore
33
import (
44
"encoding/base32"
55
"errors"
6-
"math/rand"
6+
"math/rand/v2"
77
"os"
88

99
"github.com/criyle/go-judge/envexec"
1010
)
1111

12-
const randIDLength = 5
13-
1412
var errUniqueIDNotGenerated = errors.New("unique id does not exists after tried 50 times")
1513

1614
// FileStore defines interface to store file
@@ -23,9 +21,13 @@ type FileStore interface {
2321
}
2422

2523
func generateID() (string, error) {
24+
const randIDLength = 5
2625
b := make([]byte, randIDLength)
27-
if _, err := rand.Read(b); err != nil {
28-
return "", err
29-
}
26+
r := rand.Int64N(1 << 40)
27+
b[0] = byte(r)
28+
b[1] = byte(r >> 8)
29+
b[2] = byte(r >> 16)
30+
b[3] = byte(r >> 24)
31+
b[4] = byte(r >> 32)
3032
return base32.StdEncoding.EncodeToString(b), nil
3133
}

go.mod

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ go 1.22
55
require (
66
github.com/coreos/go-systemd/v22 v22.5.0
77
github.com/creack/pty v1.1.21
8-
github.com/criyle/go-sandbox v0.10.1
8+
github.com/criyle/go-sandbox v0.10.2
99
github.com/elastic/go-seccomp-bpf v1.4.0
10-
github.com/elastic/go-ucfg v0.8.6
11-
github.com/gin-contrib/zap v1.1.0
10+
github.com/elastic/go-ucfg v0.8.8
11+
github.com/gin-contrib/zap v1.1.1
1212
github.com/gin-gonic/gin v1.9.1
1313
github.com/godbus/dbus/v5 v5.1.0
1414
github.com/gorilla/websocket v1.5.1
@@ -18,21 +18,21 @@ require (
1818
github.com/prometheus/client_golang v1.19.0
1919
github.com/zsais/go-gin-prometheus v0.1.0
2020
go.uber.org/zap v1.27.0
21-
golang.org/x/net v0.21.0
22-
golang.org/x/sync v0.6.0
23-
golang.org/x/sys v0.17.0
24-
golang.org/x/term v0.17.0
25-
google.golang.org/grpc v1.62.0
21+
golang.org/x/net v0.24.0
22+
golang.org/x/sync v0.7.0
23+
golang.org/x/sys v0.19.0
24+
golang.org/x/term v0.19.0
25+
google.golang.org/grpc v1.63.0
2626
google.golang.org/protobuf v1.33.0
2727
gopkg.in/yaml.v2 v2.4.0
2828
)
2929

3030
require (
31-
cloud.google.com/go/compute v1.24.0 // indirect
31+
cloud.google.com/go/compute v1.25.1 // indirect
3232
github.com/BurntSushi/toml v1.3.2 // indirect
3333
github.com/beorn7/perks v1.0.1 // indirect
34-
github.com/bytedance/sonic v1.11.2 // indirect
35-
github.com/cespare/xxhash/v2 v2.2.0 // indirect
34+
github.com/bytedance/sonic v1.11.3 // indirect
35+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
3636
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
3737
github.com/chenzhuoyu/iasm v0.9.1 // indirect
3838
github.com/fatih/camelcase v1.0.0 // indirect
@@ -43,25 +43,25 @@ require (
4343
github.com/go-playground/universal-translator v0.18.1 // indirect
4444
github.com/go-playground/validator/v10 v10.19.0 // indirect
4545
github.com/goccy/go-json v0.10.2 // indirect
46-
github.com/golang/protobuf v1.5.3 // indirect
46+
github.com/golang/protobuf v1.5.4 // indirect
4747
github.com/json-iterator/go v1.1.12 // indirect
4848
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
4949
github.com/leodido/go-urn v1.4.0 // indirect
5050
github.com/mattn/go-isatty v0.0.20 // indirect
5151
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
5252
github.com/modern-go/reflect2 v1.0.2 // indirect
53-
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
54-
github.com/prometheus/client_model v0.6.0 // indirect
55-
github.com/prometheus/common v0.49.0 // indirect
56-
github.com/prometheus/procfs v0.12.0 // indirect
53+
github.com/pelletier/go-toml/v2 v2.2.0 // indirect
54+
github.com/prometheus/client_model v0.6.1 // indirect
55+
github.com/prometheus/common v0.52.2 // indirect
56+
github.com/prometheus/procfs v0.13.0 // indirect
5757
github.com/sirupsen/logrus v1.9.3 // indirect
5858
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
5959
github.com/ugorji/go/codec v1.2.12 // indirect
6060
go.uber.org/multierr v1.11.0 // indirect
6161
golang.org/x/arch v0.7.0 // indirect
62-
golang.org/x/crypto v0.20.0 // indirect
62+
golang.org/x/crypto v0.22.0 // indirect
6363
golang.org/x/text v0.14.0 // indirect
64-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240228224816-df926f6c8641 // indirect
64+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
6565
gopkg.in/yaml.v3 v3.0.1 // indirect
6666
)
6767

0 commit comments

Comments
 (0)