Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
07fdff979c | |||
3e22a37dab | |||
c86c54dfec | |||
acc7a80e3a | |||
e8319d1b34 | |||
d5882aeb11 |
2
go.mod
2
go.mod
@@ -3,7 +3,7 @@ module github.com/ehlxr/ddgo
|
||||
go 1.13
|
||||
|
||||
require (
|
||||
github.com/JetBlink/dingtalk-notify-go-sdk v0.0.0-20191112085213-0dc836cea13e // indirect
|
||||
github.com/JetBlink/dingtalk-notify-go-sdk v0.0.0-20191112085213-0dc836cea13e
|
||||
github.com/jessevdk/go-flags v1.4.1-0.20181221193153-c0795c8afcf4
|
||||
golang.org/x/sys v0.0.0-20191113165036-4c7a9d0fe056 // indirect
|
||||
unknwon.dev/clog/v2 v2.0.0-beta.5
|
||||
|
31
main.go
31
main.go
@@ -10,6 +10,7 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
log "unknwon.dev/clog/v2"
|
||||
)
|
||||
|
||||
@@ -31,17 +32,21 @@ GoVersion: %s
|
||||
bannerBase64 = "DQogX19fXyAgX19fXyAgICBfX18gIF9fX19fIA0KKCAgXyBcKCAgXyBcICAvIF9fKSggIF8gICkNCiApKF8pICkpKF8pICkoIChfLS4gKShfKSggDQooX19fXy8oX19fXy8gIFxfX18vKF9fX19fKQ0K"
|
||||
|
||||
opts struct {
|
||||
Addr string `short:"a" long:"addr" default:":80" env:"ADDR" description:"Addr to listen on for HTTP server"`
|
||||
Token string `short:"t" long:"token" env:"TOKEN" description:"Dingtalk robot access token" required:"true"`
|
||||
Secret string `short:"s" long:"secret" env:"SECRET" description:"Dingtalk robot secret"`
|
||||
AtMobiles []string `short:"m" long:"at-mobiles" env:"AT_MOBILES" env-delim:"," description:"The mobile of the person will be @"`
|
||||
IsAtAll bool `short:"e" long:"at-all" env:"AT_ALL" description:"Whether @ everyone"`
|
||||
Version bool `short:"v" long:"version" description:"Show version info"`
|
||||
Addr string `short:"a" long:"addr" default:":80" env:"ADDR" description:"Addr to listen on for HTTP server"`
|
||||
Version bool `short:"v" long:"version" description:"Show version info"`
|
||||
Robot robot `group:"DingTalk Robot Options" namespace:"robot" env-namespace:"ROBOT" `
|
||||
}
|
||||
|
||||
robot *dt.Robot
|
||||
dingTalk *dt.Robot
|
||||
)
|
||||
|
||||
type robot struct {
|
||||
Token string `short:"t" long:"token" env:"TOKEN" description:"DingTalk robot access token" required:"true"`
|
||||
Secret string `short:"s" long:"secret" env:"SECRET" description:"DingTalk robot secret"`
|
||||
AtMobiles []string `short:"m" long:"at-mobiles" env:"AT_MOBILES" env-delim:"," description:"The mobile of the person will be at"`
|
||||
IsAtAll bool `short:"e" long:"at-all" env:"AT_ALL" description:"Whether at everyone"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
initLog()
|
||||
}
|
||||
@@ -49,7 +54,7 @@ func init() {
|
||||
func main() {
|
||||
parseArg()
|
||||
|
||||
robot = dt.NewRobot(opts.Token, opts.Secret)
|
||||
dingTalk = dt.NewRobot(opts.Robot.Token, opts.Robot.Secret)
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/", requestHandle)
|
||||
@@ -100,6 +105,8 @@ func initLog() {
|
||||
|
||||
func parseArg() {
|
||||
parser := flags.NewParser(&opts, flags.HelpFlag|flags.PassDoubleDash)
|
||||
parser.NamespaceDelimiter = "-"
|
||||
|
||||
if AppName != "" {
|
||||
parser.Name = AppName
|
||||
}
|
||||
@@ -140,7 +147,13 @@ func requestHandle(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err = robot.SendTextMessage(content, opts.AtMobiles, opts.IsAtAll)
|
||||
ats := opts.Robot.AtMobiles
|
||||
at := r.Form.Get("at")
|
||||
if at != "" {
|
||||
ats = append(ats, strings.Split(at, ",")...)
|
||||
}
|
||||
|
||||
err = dingTalk.SendTextMessage(content, ats, opts.Robot.IsAtAll)
|
||||
if err != nil {
|
||||
log.Error("%+v", err)
|
||||
_, _ = fmt.Fprintln(w, err)
|
||||
|
Reference in New Issue
Block a user