-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add config & update go to 1.22
- Loading branch information
1 parent
787e361
commit d3fb4f1
Showing
10 changed files
with
295 additions
and
57 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,6 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "gomod" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" |
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,132 @@ | ||
name: Build and Release | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- "**/*.go" | ||
- "go.mod" | ||
- "go.sum" | ||
- ".github/workflows/*.yml" | ||
pull_request: | ||
types: [ opened, synchronize, reopened ] | ||
paths: | ||
- "**/*.go" | ||
- "go.mod" | ||
- "go.sum" | ||
- ".github/workflows/*.yml" | ||
release: | ||
types: [ published ] | ||
|
||
jobs: | ||
|
||
build: | ||
strategy: | ||
matrix: | ||
build-tag: [ 'none' ] | ||
goos: [ linux ] | ||
goarch: [ amd64 ] | ||
goamd64: [ v1, v3 ] | ||
include: | ||
- build-tag: none | ||
goos: linux | ||
goarch: arm64 | ||
- build-tag: none | ||
goos: linux | ||
goarch: riscv64 | ||
fail-fast: false | ||
|
||
runs-on: ubuntu-latest | ||
env: | ||
BUILD_TAG: ${{ matrix.build-tag }} | ||
GOOS: ${{ matrix.goos }} | ||
GOARCH: ${{ matrix.goarch }} | ||
GOAMD64: ${{ matrix.goamd64 }} | ||
CGO_ENABLED: 0 | ||
steps: | ||
- name: Checkout codebase | ||
uses: actions/checkout@v4 | ||
|
||
- name: Configure & show workflow information | ||
id: get_filename | ||
run: | | ||
echo "BUILD_TAG: $BUILD_TAG, GOOS: $GOOS, GOARCH: $GOARCH, GOAMD64: $GOAMD64" | ||
if [ "$GOAMD64" == "v3" ]; then | ||
if [ "$BUILD_TAG" == "none" ]; then | ||
echo "ASSET_NAME=$GOOS-$GOARCH$GOAMD64" >> $GITHUB_OUTPUT | ||
echo "ASSET_NAME=$GOOS-$GOARCH$GOAMD64" >> $GITHUB_ENV | ||
else | ||
echo "ASSET_NAME=$GOOS-$GOARCH$GOAMD64-$BUILD_TAG" >> $GITHUB_OUTPUT | ||
echo "ASSET_NAME=$GOOS-$GOARCH$GOAMD64-$BUILD_TAG" >> $GITHUB_ENV | ||
fi | ||
else | ||
if [ "$BUILD_TAG" == "none" ]; then | ||
echo "ASSET_NAME=$GOOS-$GOARCH" >> $GITHUB_OUTPUT | ||
echo "ASSET_NAME=$GOOS-$GOARCH" >> $GITHUB_ENV | ||
else | ||
echo "ASSET_NAME=$GOOS-$GOARCH-$BUILD_TAG" >> $GITHUB_OUTPUT | ||
echo "ASSET_NAME=$GOOS-$GOARCH-$BUILD_TAG" >> $GITHUB_ENV | ||
fi | ||
fi | ||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: ^1.22 | ||
|
||
- name: Get project dependencies | ||
run: go mod download | ||
|
||
- name: Build netstatus-api-go | ||
run: | | ||
mkdir -p build_assets | ||
if [ $BUILD_TAG != "none" ]; then | ||
go build -v -o build_assets/netstatus-api-go -trimpath -ldflags "-s -w -buildid=" -tags $BUILD_TAG | ||
else | ||
go build -v -o build_assets/netstatus-api-go -trimpath -ldflags "-s -w -buildid=" | ||
fi | ||
- name: Prepare to release | ||
uses: nick-fields/retry@v3 | ||
with: | ||
timeout_minutes: 60 | ||
retry_wait_seconds: 60 | ||
max_attempts: 5 | ||
command: | | ||
cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md | ||
cp ${GITHUB_WORKSPACE}/LICENSE ./build_assets/LICENSE | ||
cp ${GITHUB_WORKSPACE}/config.json.example ./build_assets/config.json | ||
- name: Create ZIP archive | ||
shell: bash | ||
run: | | ||
pushd build_assets || exit 1 | ||
touch -mt $(date +%Y01010000) * | ||
zip -9vr ../netstatus-api-go-$ASSET_NAME.zip . | ||
popd || exit 1 | ||
FILE=./netstatus-api-go-$ASSET_NAME.zip | ||
DGST=$FILE.dgst | ||
openssl dgst -sha256 $FILE | sed 's/([^)]*)//g' >>$DGST | ||
openssl dgst -sha3-256 $FILE | sed 's/([^)]*)//g' >>$DGST | ||
- name: Change the name | ||
run: | | ||
mv build_assets netstatus-api-go-$ASSET_NAME | ||
- name: Upload files to Artifacts | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: netstatus-api-go-${{ steps.get_filename.outputs.ASSET_NAME }} | ||
path: | | ||
./netstatus-api-go-${{ steps.get_filename.outputs.ASSET_NAME }}/* | ||
- name: Upload binaries to release | ||
uses: svenstaro/upload-release-action@v2 | ||
if: github.event_name == 'release' | ||
with: | ||
repo_token: ${{ secrets.GITHUB_TOKEN }} | ||
file: ./netstatus-api-go-${{ steps.get_filename.outputs.ASSET_NAME }}.zip* | ||
tag: ${{ github.ref }} | ||
file_glob: true |
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,6 @@ | ||
package api | ||
|
||
type tcpingRes struct { | ||
Status string `json:"status"` | ||
Message string `json:"message"` | ||
} |
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,4 @@ | ||
{ | ||
"port": 8080, | ||
"tcpping_timeout": 1000, | ||
} |
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,28 @@ | ||
package config | ||
|
||
import "github.com/spf13/viper" | ||
|
||
var config = viper.New() | ||
|
||
func init() { | ||
config.SetConfigName("config") | ||
config.SetConfigType("json") | ||
config.AddConfigPath("/etc/netstatus-api-go/") | ||
config.AddConfigPath(".") | ||
|
||
config.SetDefault("port", 8080) | ||
config.SetDefault("timeout", 1000) | ||
|
||
err := config.ReadInConfig() | ||
if err != nil { | ||
return | ||
} | ||
} | ||
|
||
func GetPort() int { | ||
return config.GetInt("port") | ||
} | ||
|
||
func GetTimeout() int { | ||
return config.GetInt("timeout") | ||
} |
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 @@ | ||
package config |
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 |
---|---|---|
@@ -1,32 +1,50 @@ | ||
module github.com/sspanel-uim/NetStatus-API-Go | ||
|
||
go 1.21 | ||
go 1.22.1 | ||
|
||
require github.com/gin-gonic/gin v1.9.1 | ||
require ( | ||
github.com/gin-gonic/gin v1.9.1 | ||
github.com/spf13/viper v1.18.2 | ||
) | ||
|
||
require ( | ||
github.com/bytedance/sonic v1.9.1 // indirect | ||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect | ||
github.com/fsnotify/fsnotify v1.7.0 // indirect | ||
github.com/gabriel-vasile/mimetype v1.4.2 // indirect | ||
github.com/gin-contrib/sse v0.1.0 // indirect | ||
github.com/go-playground/locales v0.14.1 // indirect | ||
github.com/go-playground/universal-translator v0.18.1 // indirect | ||
github.com/go-playground/validator/v10 v10.14.0 // indirect | ||
github.com/goccy/go-json v0.10.2 // indirect | ||
github.com/hashicorp/hcl v1.0.0 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/klauspost/cpuid/v2 v2.2.4 // indirect | ||
github.com/leodido/go-urn v1.2.4 // indirect | ||
github.com/magiconair/properties v1.8.7 // indirect | ||
github.com/mattn/go-isatty v0.0.19 // indirect | ||
github.com/mitchellh/mapstructure v1.5.0 // 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.0.8 // indirect | ||
github.com/pelletier/go-toml/v2 v2.1.0 // indirect | ||
github.com/sagikazarmark/locafero v0.4.0 // indirect | ||
github.com/sagikazarmark/slog-shim v0.1.0 // indirect | ||
github.com/sourcegraph/conc v0.3.0 // indirect | ||
github.com/spf13/afero v1.11.0 // indirect | ||
github.com/spf13/cast v1.6.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/subosito/gotenv v1.6.0 // indirect | ||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect | ||
github.com/ugorji/go/codec v1.2.11 // indirect | ||
go.uber.org/atomic v1.9.0 // indirect | ||
go.uber.org/multierr v1.9.0 // indirect | ||
golang.org/x/arch v0.3.0 // indirect | ||
golang.org/x/crypto v0.9.0 // indirect | ||
golang.org/x/net v0.10.0 // indirect | ||
golang.org/x/sys v0.8.0 // indirect | ||
golang.org/x/text v0.9.0 // indirect | ||
google.golang.org/protobuf v1.30.0 // indirect | ||
golang.org/x/crypto v0.16.0 // indirect | ||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect | ||
golang.org/x/net v0.19.0 // indirect | ||
golang.org/x/sys v0.15.0 // indirect | ||
golang.org/x/text v0.14.0 // indirect | ||
google.golang.org/protobuf v1.31.0 // indirect | ||
gopkg.in/ini.v1 v1.67.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.