Skip to content

Commit

Permalink
deps: remove deprecated functions and use rand/v2
Browse files Browse the repository at this point in the history
  • Loading branch information
criyle committed Apr 5, 2024
1 parent b4352b1 commit 2ade4b9
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ cmd = "go build -o ./tmp/go-judge ./cmd/go-judge"
full_bin = "tmp/go-judge -enable-grpc -enable-debug -enable-metrics -http-addr=:5050 -grpc-addr=:5051"

include_ext = ["go"]
exclude_dir = ["dist"]
exclude_dir = ["dist", "node_modules"]
46 changes: 19 additions & 27 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,26 @@ jobs:
name: Goreleaser
runs-on: ubuntu-latest
steps:
-
name: Checkout
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
-
name: Fetch all tags
- name: Fetch all tags
run: git fetch --force --tags
-
name: Set up QEMU
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to DockerHub
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Set up Go
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
-
name: Run GoReleaser
go-version: "1.22"
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
if: ${{ contains(github.ref, 'v') }}
with:
Expand All @@ -46,8 +39,7 @@ jobs:
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
name: Test GoReleaser
- name: Test GoReleaser
uses: goreleaser/goreleaser-action@v5
if: ${{ ! contains(github.ref, 'v') }}
with:
Expand All @@ -65,7 +57,7 @@ jobs:
- ubuntu-latest
- macos-latest
GOARCH:
- amd64
- amd64
include:
- os: ubuntu-latest
GOARCH: "386"
Expand All @@ -75,15 +67,15 @@ jobs:
GOARCH: "arm64"
- os: ubuntu-latest
GOARCH: "riscv64"
- os: macos-latest
- os: macos-latest
GOARCH: "arm64"
steps:
- name: Check out
uses: actions/checkout@v4
- name: Set up Go 1.22
uses: actions/setup-go@v5
with:
go-version: '1.22'
go-version: "1.22"
- name: Get git tag ref
run: git fetch --prune --unshallow --tags
- name: Download dependencies
Expand All @@ -92,7 +84,7 @@ jobs:
run: go generate ./cmd/go-judge/version

- name: Build on Linux
if: ${{ matrix.os == 'ubuntu-latest' }}
if: ${{ matrix.os == 'ubuntu-latest' }}
env:
GOARCH: ${{ matrix.GOARCH }}
CGO_ENABLE: 0
Expand All @@ -101,31 +93,31 @@ jobs:
go build -v -o go-judge-shell ./cmd/go-judge-shell
go build -o go-judge-init ./cmd/go-judge-init
- name: Build shared objects on Linux
if: ${{ matrix.os == 'ubuntu-latest' && matrix.GOARCH == 'amd64' }}
if: ${{ matrix.os == 'ubuntu-latest' && matrix.GOARCH == 'amd64' }}
env:
GOARCH: ${{ matrix.GOARCH }}
run: |
go build -buildmode=c-shared -o go-judge.so ./cmd/go-judge-ffi
- name: Upload go-judge on linux
if: ${{ matrix.os == 'ubuntu-latest' }}
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: actions/upload-artifact@v4
with:
name: go-judge-${{ matrix.GOARCH }}
path: go-judge
- name: Upload go-judge-shell on linux
if: ${{ matrix.os == 'ubuntu-latest' }}
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: actions/upload-artifact@v4
with:
name: go-judge-shell-${{ matrix.GOARCH }}
path: go-judge-shell
- name: Upload go-judge-init on linux
if: ${{ matrix.os == 'ubuntu-latest' }}
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: actions/upload-artifact@v4
with:
name: go-judge-init-${{ matrix.GOARCH }}
path: go-judge-init
- name: Upload go-judge.so on linux
if: ${{ matrix.os == 'ubuntu-latest' && matrix.GOARCH == 'amd64' }}
if: ${{ matrix.os == 'ubuntu-latest' && matrix.GOARCH == 'amd64' }}
uses: actions/upload-artifact@v4
with:
name: go-judge-${{ matrix.GOARCH }}.so
Expand Down Expand Up @@ -186,4 +178,4 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: go-judge-${{ matrix.GOARCH }}.dylib
path: go-judge.dylib
path: go-judge.dylib
2 changes: 1 addition & 1 deletion cmd/go-judge-grpc-proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func main() {
if token != "" {
opts = append(opts, grpc.WithPerRPCCredentials(newTokenAuth(token)))
}
conn, err := grpc.Dial(*srvAddr, opts...)
conn, err := grpc.NewClient(*srvAddr, opts...)
if err != nil {
log.Fatalln("client", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/go-judge-shell/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func newGrpc(args []string, srvAddr string) Stream {
if token != "" {
opts = append(opts, grpc.WithPerRPCCredentials(newTokenAuth(token)))
}
conn, err := grpc.Dial(srvAddr, opts...)
conn, err := grpc.NewClient(srvAddr, opts...)
if err != nil {
log.Fatalln("client", err)
}
Expand Down
14 changes: 8 additions & 6 deletions filestore/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ package filestore
import (
"encoding/base32"
"errors"
"math/rand"
"math/rand/v2"
"os"

"github.com/criyle/go-judge/envexec"
)

const randIDLength = 5

var errUniqueIDNotGenerated = errors.New("unique id does not exists after tried 50 times")

// FileStore defines interface to store file
Expand All @@ -23,9 +21,13 @@ type FileStore interface {
}

func generateID() (string, error) {
const randIDLength = 5
b := make([]byte, randIDLength)
if _, err := rand.Read(b); err != nil {
return "", err
}
r := rand.Int64N(1 << 40)
b[0] = byte(r)
b[1] = byte(r >> 8)
b[2] = byte(r >> 16)
b[3] = byte(r >> 24)
b[4] = byte(r >> 32)
return base32.StdEncoding.EncodeToString(b), nil
}
36 changes: 18 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ go 1.22
require (
github.com/coreos/go-systemd/v22 v22.5.0
github.com/creack/pty v1.1.21
github.com/criyle/go-sandbox v0.10.1
github.com/criyle/go-sandbox v0.10.2
github.com/elastic/go-seccomp-bpf v1.4.0
github.com/elastic/go-ucfg v0.8.6
github.com/gin-contrib/zap v1.1.0
github.com/elastic/go-ucfg v0.8.8
github.com/gin-contrib/zap v1.1.1
github.com/gin-gonic/gin v1.9.1
github.com/godbus/dbus/v5 v5.1.0
github.com/gorilla/websocket v1.5.1
Expand All @@ -18,21 +18,21 @@ require (
github.com/prometheus/client_golang v1.19.0
github.com/zsais/go-gin-prometheus v0.1.0
go.uber.org/zap v1.27.0
golang.org/x/net v0.21.0
golang.org/x/sync v0.6.0
golang.org/x/sys v0.17.0
golang.org/x/term v0.17.0
google.golang.org/grpc v1.62.0
golang.org/x/net v0.24.0
golang.org/x/sync v0.7.0
golang.org/x/sys v0.19.0
golang.org/x/term v0.19.0
google.golang.org/grpc v1.63.0
google.golang.org/protobuf v1.33.0
gopkg.in/yaml.v2 v2.4.0
)

require (
cloud.google.com/go/compute v1.24.0 // indirect
cloud.google.com/go/compute v1.25.1 // indirect
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/sonic v1.11.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/bytedance/sonic v1.11.3 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/fatih/camelcase v1.0.0 // indirect
Expand All @@ -43,25 +43,25 @@ require (
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.19.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.49.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.52.2 // indirect
github.com/prometheus/procfs v0.13.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/arch v0.7.0 // indirect
golang.org/x/crypto v0.20.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240228224816-df926f6c8641 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

Expand Down
Loading

0 comments on commit 2ade4b9

Please sign in to comment.