diff --git a/Dockerfile b/Dockerfile index a222c0b..f2461f5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,7 @@ FROM ehlxr/alpine LABEL maintainer="ehlxr " -COPY ./dist/ddgo /usr/local/bin/ -COPY ./entrypoint.sh /entrypoint.sh +COPY ./dist/ddgo_linux_amd64 /usr/local/bin/ddgo -ENTRYPOINT ["sh", "/entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["/usr/local/bin/ddgo"] \ No newline at end of file diff --git a/Makefile b/Makefile index c470d28..b428005 100644 --- a/Makefile +++ b/Makefile @@ -6,11 +6,12 @@ DIST_DIR := $(ROOT_DIR)/dist/ #VERSION_PATH := $(shell cat `go env GOMOD` | awk '/^module/{print $$2}')/ VERSION_PATH := main +LD_APP_NAMW := -X '$(VERSION_PATH).AppName=$(shell basename `pwd`)' LD_GIT_COMMIT := -X '$(VERSION_PATH).GitCommit=$(COMMIT_SHA1)' LD_BUILD_TIME := -X '$(VERSION_PATH).BuildTime=$(BUILD_TIME)' LD_GO_VERSION := -X '$(VERSION_PATH).GoVersion=`go version`' LD_VERSION := -X '$(VERSION_PATH).Version=$(BUILD_VERSION)' -LD_FLAGS := "$(LD_GIT_COMMIT) $(LD_BUILD_TIME) $(LD_GO_VERSION) $(LD_VERSION) -w -s" +LD_FLAGS := "$(LD_APP_NAMW) $(LD_GIT_COMMIT) $(LD_BUILD_TIME) $(LD_GO_VERSION) $(LD_VERSION) -w -s" .PHONY : build release clean install upx diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100755 index f420b96..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -# 须以特权模式运行(docker run --privileged) -sysctl net.core.somaxconn=1024 - -/usr/local/bin/ddgo $@ \ No newline at end of file diff --git a/main.go b/main.go index 65b2f0e..5083276 100644 --- a/main.go +++ b/main.go @@ -16,13 +16,14 @@ import ( ) var ( + AppName string Version string BuildTime string GitCommit string GoVersion string versionTpl = `%s -Name: ddgo +Name: %s Version: %s BuildTime: %s GitCommit: %s @@ -32,7 +33,7 @@ GoVersion: %s bannerBase64 = "DQogX19fXyAgX19fXyAgICBfX18gIF9fX19fIA0KKCAgXyBcKCAgXyBcICAvIF9fKSggIF8gICkNCiApKF8pICkpKF8pICkoIChfLS4gKShfKSggDQooX19fXy8oX19fXy8gIFxfX18vKF9fX19fKQ0K" opts struct { - Addr string `short:"a" long:"addr" default:"0.0.0.0:10141" env:"ADDR" description:"Addr to listen on for HTTP server"` + Addr string `short:"a" long:"addr" default:":80" env:"ADDR" description:"Addr to listen on for HTTP server"` WebHookUrl string `short:"u" long:"webhook-url" env:"URL" description:"Webhook url of dingding" required:"true"` Version bool `short:"v" long:"version" description:"Show version info"` } @@ -49,7 +50,7 @@ func main() { mux.HandleFunc("/", requestHandle) server := &http.Server{ - Addr: ":4000", + Addr: opts.Addr, Handler: mux, } @@ -93,14 +94,19 @@ func initLog() { } func parseArg() { - if _, err := flags.NewParser(&opts, flags.Default).Parse(); err != nil { + parser := flags.NewParser(&opts, flags.Default) + if _, err := parser.Parse(); err != nil { if opts.Version { printVersion() os.Exit(0) } + if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrHelp { os.Exit(0) } else { + parser.Name = AppName + parser.WriteHelp(os.Stderr) + os.Exit(1) } } @@ -161,5 +167,5 @@ func dingToInfo(msg string) []byte { // printVersion Print out version information func printVersion() { banner, _ := base64.StdEncoding.DecodeString(bannerBase64) - fmt.Printf(versionTpl, banner, Version, BuildTime, GitCommit, GoVersion) + fmt.Printf(versionTpl, banner, AppName, Version, BuildTime, GitCommit, GoVersion) }