main.go 918 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "time"
  8. "go-common/library/log"
  9. bm "go-common/library/net/http/blademaster"
  10. xtime "go-common/library/time"
  11. )
  12. var bind = flag.String("bind", "localhost:10010", "bind addr example: localhost:10010")
  13. func main() {
  14. flag.Parse()
  15. engineOuter := bm.DefaultServer(&bm.ServerConfig{
  16. Addr: *bind,
  17. Timeout: xtime.Duration(time.Second),
  18. })
  19. // bm不支持 get post 绑定一个路径 为了获取body只能用post
  20. engineOuter.POST("/", handle)
  21. if err := engineOuter.Start(); err != nil {
  22. log.Error("engine.Start error(%v)", err)
  23. panic(err)
  24. }
  25. c := make(chan os.Signal, 1)
  26. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  27. for {
  28. s := <-c
  29. log.Info("get a signal %s", s.String())
  30. switch s {
  31. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  32. log.Info("exit")
  33. return
  34. default:
  35. return
  36. }
  37. }
  38. }