From 5bb6f7b96ed528d679d21c1698378806654ec98e Mon Sep 17 00:00:00 2001 From: facundo Date: Tue, 23 Jul 2024 18:11:09 -0300 Subject: [PATCH 1/2] port github actions from jorge --- .github/workflows/release.yml | 33 +++++++++++++++++++++++++++++++ .github/workflows/test.yml | 37 +++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..5cf3368 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,33 @@ +name: Upload release binaries + +on: + push: + tags: + - '*' + +jobs: + build: + name: Build Binaries + runs-on: ubuntu-latest + + strategy: + matrix: + goos: [linux, darwin] + goarch: [amd64, arm64] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.22' + + - name: Build Binary + run: GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w" -o ngtop-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.ext }} . + + - name: Release + uses: softprops/action-gh-release@v1 + with: + files: "ngtop-*" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..3b79f4f --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,37 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: Test project + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.22' + + - name: Build + run: go build -v ./... + + - name: Test + run: go test -v ./... + + - name: Vet + run: go vet -v ./... + + - name: install staticcheck + run: go install "honnef.co/go/tools/cmd/staticcheck@latest" + + - name: staticcheck + run: staticcheck ./... From c7c5c018b54a82248af34bf1286f43f4ddcf65b0 Mon Sep 17 00:00:00 2001 From: facundo Date: Tue, 23 Jul 2024 18:22:50 -0300 Subject: [PATCH 2/2] fix staticcheck errors --- db.go | 4 ++-- main.go | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/db.go b/db.go index 459c0d5..a0e64f5 100644 --- a/db.go +++ b/db.go @@ -91,7 +91,7 @@ func (dbs *dbSession) PrepareForUpdate(columns []string) (*time.Time, error) { return nil, err } - t, err := timeFromDBFormat(lastSeenTimeStr) + t, _ := timeFromDBFormat(lastSeenTimeStr) lastSeemTime = &t } @@ -154,7 +154,7 @@ func (dbs *dbSession) QueryTop(spec *RequestCountSpec) ([]string, [][]string, er } strValues := make([]string, len(values)) for i, value := range values { - strValues[i] = fmt.Sprintf("%s", *value.(*sql.RawBytes)) + strValues[i] = string(*value.(*sql.RawBytes)) } results = append(results, strValues) } diff --git a/main.go b/main.go index d55c4a1..771e80b 100644 --- a/main.go +++ b/main.go @@ -115,10 +115,8 @@ func resolveWhereConditions(clauses []string) (map[string][]string, error) { } if column, found := FIELD_NAMES[keyvalue[0]]; !found { return nil, fmt.Errorf("unknown field name %s", keyvalue[0]) - } else if _, found := conditions[column]; found { - conditions[column] = append(conditions[column], keyvalue[1]) } else { - conditions[column] = []string{keyvalue[1]} + conditions[column] = append(conditions[column], keyvalue[1]) } }