update at 2019-11-20 16:33:37 by ehlxr
This commit is contained in:
parent
c86c54dfec
commit
3e22a37dab
20
main.go
20
main.go
@ -32,16 +32,20 @@ GoVersion: %s
|
|||||||
|
|
||||||
opts struct {
|
opts struct {
|
||||||
Addr string `short:"a" long:"addr" default:":80" 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"`
|
||||||
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"`
|
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() {
|
func init() {
|
||||||
initLog()
|
initLog()
|
||||||
}
|
}
|
||||||
@ -49,7 +53,7 @@ func init() {
|
|||||||
func main() {
|
func main() {
|
||||||
parseArg()
|
parseArg()
|
||||||
|
|
||||||
robot = dt.NewRobot(opts.Token, opts.Secret)
|
dingTalk = dt.NewRobot(opts.Robot.Token, opts.Robot.Secret)
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.HandleFunc("/", requestHandle)
|
mux.HandleFunc("/", requestHandle)
|
||||||
@ -100,6 +104,8 @@ func initLog() {
|
|||||||
|
|
||||||
func parseArg() {
|
func parseArg() {
|
||||||
parser := flags.NewParser(&opts, flags.HelpFlag|flags.PassDoubleDash)
|
parser := flags.NewParser(&opts, flags.HelpFlag|flags.PassDoubleDash)
|
||||||
|
parser.NamespaceDelimiter = "-"
|
||||||
|
|
||||||
if AppName != "" {
|
if AppName != "" {
|
||||||
parser.Name = AppName
|
parser.Name = AppName
|
||||||
}
|
}
|
||||||
@ -140,7 +146,7 @@ func requestHandle(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = robot.SendTextMessage(content, opts.AtMobiles, opts.IsAtAll)
|
err = dingTalk.SendTextMessage(content, opts.Robot.AtMobiles, opts.Robot.IsAtAll)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("%+v", err)
|
log.Error("%+v", err)
|
||||||
_, _ = fmt.Fprintln(w, err)
|
_, _ = fmt.Fprintln(w, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user