init
This commit is contained in:
parent
06337d2aba
commit
3bc08d0a96
@ -2,8 +2,7 @@ FROM ehlxr/alpine
|
||||
|
||||
LABEL maintainer="ehlxr <ehlxr.me@gmail.com>"
|
||||
|
||||
COPY ./dist/ddgo /usr/local/bin/
|
||||
COPY ./entrypoint.sh /entrypoint.sh
|
||||
COPY ./dist/ddgo_linux_amd64 /usr/local/bin/ddgo
|
||||
|
||||
|
||||
ENTRYPOINT ["sh", "/entrypoint.sh"]
|
||||
ENTRYPOINT ["/usr/local/bin/ddgo"]
|
3
Makefile
3
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
|
||||
|
||||
|
@ -1,6 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 须以特权模式运行(docker run --privileged)
|
||||
sysctl net.core.somaxconn=1024
|
||||
|
||||
/usr/local/bin/ddgo $@
|
16
main.go
16
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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user