main.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package main
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "time"
  7. "git.chuangxin1.com/csacred/toolkit"
  8. "git.chuangxin1.com/csacred/toolkit/http"
  9. "github.com/go-kit/kit/log"
  10. )
  11. func main() {
  12. var (
  13. addr = flag.String("listen", ":9999", "Address for HTTP server")
  14. consulAddr = flag.String("consul", "", "Consul agent address")
  15. )
  16. flag.Parse()
  17. // Logging domain.
  18. var logger log.Logger
  19. {
  20. logger = log.NewLogfmtLogger(os.Stderr)
  21. logger = log.With(logger, "ts", log.DefaultTimestampUTC)
  22. logger = log.With(logger, "caller", log.DefaultCaller)
  23. }
  24. router := http.NewRouter()
  25. ctx := context.Background()
  26. options := toolkit.ServiceOptions{}
  27. if len(*consulAddr) > 0 {
  28. options.Address = *consulAddr
  29. }
  30. genUserHandlers(ctx, router, options, logger)
  31. //genWechatHandlers(ctx, router, options, logger)
  32. var (
  33. readTimeout time.Duration
  34. writeTimeout time.Duration
  35. maxHeaderBytes int
  36. )
  37. readTimeout = 5 * time.Second
  38. writeTimeout = 10 * time.Second
  39. maxHeaderBytes = 1024 * 1024
  40. http.ListenAndServe(*addr, router, readTimeout, writeTimeout, maxHeaderBytes, logger)
  41. }