feat: Makefile
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
*.exe
|
bin/
|
||||||
|
|
||||||
|
*.exe
|
||||||
tcping
|
tcping
|
||||||
46
Makefile
46
Makefile
@@ -0,0 +1,46 @@
|
|||||||
|
NAME=tcping
|
||||||
|
BINDIR=bin
|
||||||
|
GOBUILD=CGO_ENABLED=0 go build -ldflags '-w -s -buildid='
|
||||||
|
VERSION=1.0.0
|
||||||
|
# The -w and -s flags reduce binary sizes by excluding unnecessary symbols and debug info
|
||||||
|
# The -buildid= flag makes builds reproducible
|
||||||
|
|
||||||
|
all: linux macos-amd64 macos-arm64 win64 win32
|
||||||
|
|
||||||
|
linux:
|
||||||
|
GOARCH=amd64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
|
||||||
|
|
||||||
|
darwin-amd64:
|
||||||
|
GOARCH=amd64 GOOS=darwin $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
|
||||||
|
|
||||||
|
darwin-arm64:
|
||||||
|
GOARCH=arm64 GOOS=darwin $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
|
||||||
|
|
||||||
|
win64:
|
||||||
|
GOARCH=amd64 GOOS=windows $(GOBUILD) -o $(BINDIR)/$(NAME)-$@.exe
|
||||||
|
|
||||||
|
win32:
|
||||||
|
GOARCH=386 GOOS=windows $(GOBUILD) -o $(BINDIR)/$(NAME)-$@.exe
|
||||||
|
|
||||||
|
releases: linux darwin-amd64 darwin-arm64 win64 win32
|
||||||
|
chmod +x $(BINDIR)/$(NAME)-*
|
||||||
|
tar zcf $(BINDIR)/$(NAME)-linux-$(VERSION).tar.gz -C $(BINDIR) $(NAME)-linux
|
||||||
|
tar zcf $(BINDIR)/$(NAME)-darwin-amd64-$(VERSION).tar.gz -C $(BINDIR) $(NAME)-darwin-amd64
|
||||||
|
tar zcf $(BINDIR)/$(NAME)-darwin-arm64-$(VERSION).tar.gz -C $(BINDIR) $(NAME)-darwin-arm64
|
||||||
|
zip -j $(BINDIR)/$(NAME)-win32-$(VERSION).zip $(BINDIR)/$(NAME)-win32.exe
|
||||||
|
zip -j $(BINDIR)/$(NAME)-win64-$(VERSION).zip $(BINDIR)/$(NAME)-win64.exe
|
||||||
|
rm -f $(BINDIR)/socks5-darwin-amd64 $(BINDIR)/socks5-darwin-arm64 $(BINDIR)/socks5-linux $(BINDIR)/socks5-win32.exe $(BINDIR)/socks5-win64.exe
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm $(BINDIR)/*
|
||||||
|
|
||||||
|
# Remove trailing {} from the release upload url
|
||||||
|
GITHUB_UPLOAD_URL=$(shell echo $${GITHUB_RELEASE_UPLOAD_URL%\{*})
|
||||||
|
|
||||||
|
upload: releases
|
||||||
|
curl -H "Authorization: token $(GITHUB_TOKEN)" -H "Content-Type: application/gzip" --data-binary @$(BINDIR)/$(NAME)-linux.tgz "$(GITHUB_UPLOAD_URL)?name=$(NAME)-linux.tgz"
|
||||||
|
curl -H "Authorization: token $(GITHUB_TOKEN)" -H "Content-Type: application/gzip" --data-binary @$(BINDIR)/$(NAME)-linux.gz "$(GITHUB_UPLOAD_URL)?name=$(NAME)-linux.gz"
|
||||||
|
curl -H "Authorization: token $(GITHUB_TOKEN)" -H "Content-Type: application/gzip" --data-binary @$(BINDIR)/$(NAME)-macos-amd64.gz "$(GITHUB_UPLOAD_URL)?name=$(NAME)-macos-amd64.gz"
|
||||||
|
curl -H "Authorization: token $(GITHUB_TOKEN)" -H "Content-Type: application/gzip" --data-binary @$(BINDIR)/$(NAME)-macos-arm64.gz "$(GITHUB_UPLOAD_URL)?name=$(NAME)-macos-arm64.gz"
|
||||||
|
curl -H "Authorization: token $(GITHUB_TOKEN)" -H "Content-Type: application/zip" --data-binary @$(BINDIR)/$(NAME)-win64.zip "$(GITHUB_UPLOAD_URL)?name=$(NAME)-win64.zip"
|
||||||
|
curl -H "Authorization: token $(GITHUB_TOKEN)" -H "Content-Type: application/zip" --data-binary @$(BINDIR)/$(NAME)-win32.zip "$(GITHUB_UPLOAD_URL)?name=$(NAME)-win32.zip"
|
||||||
12
main.go
12
main.go
@@ -23,8 +23,11 @@ func main() {
|
|||||||
stopped bool
|
stopped bool
|
||||||
)
|
)
|
||||||
|
|
||||||
|
version := "1.0.0"
|
||||||
|
|
||||||
// 设置命令行参数
|
// 设置命令行参数
|
||||||
help := flag.BoolP("help", "h", false, "显示帮助信息")
|
showHelp := flag.BoolP("help", "h", false, "显示帮助信息")
|
||||||
|
showVersion := flag.BoolP("version", "v", false, "显示版本信息")
|
||||||
flag.IntVarP(&port, "port", "p", 80, "端口,默认为80")
|
flag.IntVarP(&port, "port", "p", 80, "端口,默认为80")
|
||||||
flag.IntVarP(&count, "count", "c", 4, "测试次数,默认为4次")
|
flag.IntVarP(&count, "count", "c", 4, "测试次数,默认为4次")
|
||||||
flag.DurationVarP(&timeoutDuration, "timeout", "s", 2*time.Second, "超时时间,默认为2秒")
|
flag.DurationVarP(&timeoutDuration, "timeout", "s", 2*time.Second, "超时时间,默认为2秒")
|
||||||
@@ -33,11 +36,16 @@ func main() {
|
|||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if *help {
|
if *showHelp {
|
||||||
flag.Usage()
|
flag.Usage()
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *showVersion {
|
||||||
|
fmt.Printf("tcping v%s\n", version)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
args := flag.Args()
|
args := flag.Args()
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
flag.Usage()
|
flag.Usage()
|
||||||
|
|||||||
Reference in New Issue
Block a user