update at 2019-11-20 16:33:37 by ehlxr
This commit is contained in:
parent
c86c54dfec
commit
3e22a37dab
24
main.go
24
main.go
@ -31,17 +31,21 @@ GoVersion: %s
|
|||||||
bannerBase64 = "DQogX19fXyAgX19fXyAgICBfX18gIF9fX19fIA0KKCAgXyBcKCAgXyBcICAvIF9fKSggIF8gICkNCiApKF8pICkpKF8pICkoIChfLS4gKShfKSggDQooX19fXy8oX19fXy8gIFxfX18vKF9fX19fKQ0K"
|
bannerBase64 = "DQogX19fXyAgX19fXyAgICBfX18gIF9fX19fIA0KKCAgXyBcKCAgXyBcICAvIF9fKSggIF8gICkNCiApKF8pICkpKF8pICkoIChfLS4gKShfKSggDQooX19fXy8oX19fXy8gIFxfX18vKF9fX19fKQ0K"
|
||||||
|
|
||||||
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"`
|
Version bool `short:"v" long:"version" description:"Show version info"`
|
||||||
Secret string `short:"s" long:"secret" env:"SECRET" description:"DingTalk robot secret"`
|
Robot robot `group:"DingTalk Robot Options" namespace:"robot" env-namespace:"ROBOT" `
|
||||||
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"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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