Skip to content

Commit a8b1941

Browse files
committed
添加ZK基础操作
1 parent 7d8ee99 commit a8b1941

13 files changed

+741
-0
lines changed

.github/workflows/release.yml

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
name: release
2+
on:
3+
push:
4+
# tags: # 当我们提交代码为tag 是以'v'开头的时候才会触发自动部署到服务端 如 git push tag v0.1.0
5+
# - 'v*'
6+
branches:
7+
- main
8+
# - dev
9+
# package.json 更改后再触发发布
10+
# paths: [ "package.json" ]
11+
jobs:
12+
13+
# buildWindow:
14+
# runs-on: windows-latest
15+
# steps:
16+
# # 下载源码
17+
# - name: Checkout code
18+
# uses: actions/checkout@v2
19+
#
20+
# # 打包构建 Server
21+
# - name: Build Server
22+
# uses: actions/setup-go@v2
23+
# with:
24+
# go-version: "^1.18"
25+
#
26+
# - run: |
27+
# mkdir -p release/windows
28+
# go build -o release/windows/main.exe
29+
#
30+
# # 上传共享资源
31+
# - uses: actions/upload-artifact@v2
32+
# with:
33+
# name: release
34+
# path: release
35+
#
36+
# buildLinux:
37+
# runs-on: ubuntu-latest
38+
# steps:
39+
# # 下载源码
40+
# - name: Checkout code
41+
# uses: actions/checkout@v2
42+
#
43+
# # 打包构建 Server
44+
# - name: Build Server
45+
# uses: actions/setup-go@v2
46+
# with:
47+
# go-version: "^1.18"
48+
#
49+
# - run: |
50+
# mkdir -p release/linux
51+
# go build -o release/linux/main
52+
#
53+
# # 上传共享资源
54+
# - uses: actions/upload-artifact@v2
55+
# with:
56+
# name: release
57+
# path: release
58+
#
59+
# buildMAC:
60+
# runs-on: macos-latest
61+
# steps:
62+
# # 下载源码
63+
# - name: Checkout code
64+
# uses: actions/checkout@v2
65+
#
66+
# # 打包构建 Server
67+
# - name: Build Server
68+
# uses: actions/setup-go@v2
69+
# with:
70+
# go-version: "^1.18"
71+
#
72+
# - run: |
73+
# mkdir -p release/macos
74+
# go build -o release/macos/main
75+
#
76+
# # 上传共享资源
77+
# - uses: actions/upload-artifact@v2
78+
# with:
79+
# name: release
80+
# path: release
81+
82+
83+
release:
84+
# needs:
85+
# - buildLinux
86+
# - buildWindow
87+
runs-on: ubuntu-latest
88+
steps:
89+
90+
- name: Checkout git repo
91+
uses: actions/checkout@v1
92+
93+
# 下载共享资源
94+
# - uses: actions/download-artifact@v2
95+
# with:
96+
# name: release
97+
# path: release
98+
99+
# 读取发布版本
100+
- name: Read Release Version
101+
id: release_version
102+
uses: ashley-taylor/[email protected]
103+
with:
104+
path: package.json
105+
property: version
106+
107+
- id: release_check
108+
run: |
109+
echo "::set-output name=RELEASE_STATUS::$(curl -I -m 10 -o /dev/null -s -w %{http_code} https://github.com/team-ide/go-tool/releases/tag/v${{ steps.release_version.outputs.value }})"
110+
111+
# 读取发布说明
112+
- name: Read Release Description
113+
id: release_body
114+
if: ${{ steps.release_check.outputs.RELEASE_STATUS == 404 }}
115+
uses: juliangruber/read-file-action@v1
116+
with:
117+
path: RELEASE.md
118+
# - if: ${{ steps.release_check.outputs.RELEASE_STATUS == 404 }}
119+
# run: |
120+
# cd release
121+
# zip -q -r windows-amd64.zip windows-amd64
122+
# zip -q -r linux-amd64.zip linux-amd64
123+
# zip -q -r linux-arm64.zip linux-arm64
124+
# zip -q -r linux-loong64.zip linux-loong64
125+
# zip -q -r linux-mips64.zip linux-mips64
126+
# 发布
127+
- name: Create Release
128+
id: create_release
129+
if: ${{ steps.release_check.outputs.RELEASE_STATUS == 404 }}
130+
uses: actions/create-release@v1
131+
env:
132+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
133+
with:
134+
tag_name: v${{steps.release_version.outputs.value}}
135+
release_name: v${{steps.release_version.outputs.value}}
136+
body: ${{steps.release_body.outputs.content}}
137+
draft: false # 是否是草稿
138+
prerelease: false # 是否是预发布
139+
140+
# 上传 到 Release
141+
# - if: ${{ steps.release_check.outputs.RELEASE_STATUS == 404 }}
142+
# uses: actions/upload-release-asset@master
143+
# env:
144+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
145+
# with:
146+
# upload_url: ${{ steps.create_release.outputs.upload_url }} # 上传地址,通过创建Release获取到的
147+
# asset_path: release/windows-amd64.zip
148+
# asset_name: windows-amd64.zip # 上传后的文件名
149+
# asset_content_type: application/zip
150+
#
151+
# # 上传 到 Release
152+
# - if: ${{ steps.release_check.outputs.RELEASE_STATUS == 404 }}
153+
# uses: actions/upload-release-asset@master
154+
# env:
155+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
156+
# with:
157+
# upload_url: ${{ steps.create_release.outputs.upload_url }} # 上传地址,通过创建Release获取到的
158+
# asset_path: release/linux-amd64.zip
159+
# asset_name: linux-amd64.zip # 上传后的文件名
160+
# asset_content_type: application/zip

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313

1414
# Dependency directories (remove the comment below to include it)
1515
# vendor/
16+
17+
18+
.idea

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# 0.0.1
2+
3+
## Version 0.0.1 (2023/02/28)
4+
5+
发布功能
6+
7+
1. 提交基础工具

RELEASE.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# 0.0.1
2+
3+
## Version 0.0.1 (2023/02/28)
4+
5+
发布功能
6+
7+
1. 提交基础工具

go.mod

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module github.com/team-ide/go-tool
2+
3+
go 1.18
4+
5+
require (
6+
github.com/go-zookeeper/zk v1.0.3
7+
go.uber.org/zap v1.24.0
8+
)
9+
10+
require (
11+
go.uber.org/atomic v1.7.0 // indirect
12+
go.uber.org/multierr v1.6.0 // indirect
13+
)

go.sum

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
2+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
4+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5+
github.com/go-zookeeper/zk v1.0.3 h1:7M2kwOsc//9VeeFiPtf+uSJlVpU66x9Ba5+8XK7/TDg=
6+
github.com/go-zookeeper/zk v1.0.3/go.mod h1:nOB03cncLtlp4t+UAkGSV+9beXP/akpekBwL+UX1Qcw=
7+
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
8+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
9+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
10+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
11+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
12+
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
13+
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
14+
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
15+
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
16+
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
17+
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
18+
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
19+
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
20+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

main.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package main
2+
3+
func main() {
4+
5+
}

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"version": "0.0.1"
3+
}

util/logger.go

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package util
2+
3+
import "go.uber.org/zap"
4+
5+
var (
6+
Logger *zap.Logger
7+
)
8+
9+
func init() {
10+
loggerConfig := zap.NewDevelopmentConfig()
11+
loggerConfig.Development = false
12+
Logger, _ = loggerConfig.Build()
13+
}

util/time.go

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package util
2+
3+
import "time"
4+
5+
// GetNowTime 获取当前时间戳
6+
func GetNowTime() int64 {
7+
return GetTimeTime(time.Now())
8+
}
9+
10+
// GetNowTimeSecond 获取当前时间戳 秒
11+
func GetNowTimeSecond() int64 {
12+
return GetTimeSecond(time.Now())
13+
}
14+
15+
// GetTimeTime 获取当前时间戳
16+
func GetTimeTime(time time.Time) int64 {
17+
return time.UnixNano() / 1e6
18+
}
19+
20+
// GetTimeSecond 获取当前时间秒
21+
func GetTimeSecond(time time.Time) int64 {
22+
return time.Unix()
23+
}
24+
25+
// Now 获取当前时间
26+
func Now() time.Time {
27+
return time.Now()
28+
}
29+
30+
func NowStr() string {
31+
now := time.Now()
32+
return Format(now)
33+
}
34+
35+
func Format(date time.Time) string {
36+
return date.Format("2006-01-02 15:04:05.000")
37+
}

0 commit comments

Comments
 (0)