-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: created linter and gosec rules
- Loading branch information
1 parent
ec8f66c
commit 5a8ddab
Showing
36 changed files
with
516 additions
and
494 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
version: 2 | ||
|
||
updates: | ||
- package-ecosystem: "gomod" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: hygeiene | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
|
||
jobs: | ||
golangci: | ||
# Linting job | ||
# https://github.com/golangci/golangci-lint-action | ||
name: lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v3 | ||
with: | ||
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version | ||
version: v1.52.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: security | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
|
||
jobs: | ||
# Static security scan using gosec | ||
# https://github.com/securego/gosec | ||
gosec: | ||
runs-on: ubuntu-latest | ||
env: | ||
GO111MODULE: on | ||
steps: | ||
- name: Checkout Source | ||
uses: actions/checkout@v3 | ||
- name: Run Gosec Security Scanner | ||
uses: securego/gosec@master | ||
with: | ||
args: ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Go test workflow | ||
name: test | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.22 | ||
|
||
- name: Install project dependencies | ||
run: | | ||
go mod download | ||
- name: Build App | ||
run: make build-app | ||
|
||
go-test: | ||
outputs: | ||
COVERAGE: ${{ steps.unit.outputs.coverage }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.22 | ||
|
||
- name: Install project dependencies | ||
run: | | ||
go mod download | ||
- name: Run Tests | ||
id: unit | ||
run: | | ||
make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package main | ||
|
||
import ( | ||
"math" | ||
"slices" | ||
"sort" | ||
) | ||
|
||
const ( | ||
msFactor = 1000000 | ||
) | ||
|
||
type Stats struct { | ||
Avg float64 | ||
Min float64 | ||
Max float64 | ||
P50 float64 | ||
P75 float64 | ||
P90 float64 | ||
P95 float64 | ||
P99 float64 | ||
} | ||
|
||
func GetStats(data []int) Stats { | ||
if len(data) == 0 { | ||
return Stats{} | ||
} | ||
|
||
sort.Ints(data) | ||
minv, maxv := slices.Min(data), slices.Max(data) | ||
|
||
return Stats{ | ||
Avg: avg(data) / msFactor, | ||
Min: float64(minv / msFactor), | ||
Max: float64(maxv / msFactor), | ||
P50: percent(data, 0.5) / msFactor, | ||
P75: percent(data, 0.75) / msFactor, | ||
P90: percent(data, 0.9) / msFactor, | ||
P95: percent(data, 0.95) / msFactor, | ||
P99: percent(data, 0.99) / msFactor, | ||
} | ||
} | ||
|
||
func avg(data []int) float64 { | ||
r := float64(0) | ||
for _, d := range data { | ||
r += float64(d) | ||
} | ||
return r / float64(len(data)) | ||
} | ||
|
||
func percent(data []int, p float64) float64 { | ||
idx := pIdx(len(data), p) | ||
return float64(data[idx]) | ||
} | ||
|
||
func pIdx(datalen int, p float64) int { | ||
w := math.Ceil(float64(datalen) * p) | ||
return int(min(w, float64(datalen-1))) | ||
} |
Oops, something went wrong.