main.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package main
  2. import (
  3. "crm-api/cmd/commands"
  4. "crm-api/pkg/utils"
  5. "fmt"
  6. "os"
  7. "runtime"
  8. "time"
  9. "github.com/urfave/cli"
  10. )
  11. var (
  12. gitCommitCode string
  13. buildDateTime string
  14. goVersion string
  15. )
  16. func init() {
  17. locationName := utils.GetLocationName()
  18. if locationName != "" {
  19. time.Local, _ = time.LoadLocation(locationName)
  20. }
  21. runtime.GOMAXPROCS(runtime.NumCPU())
  22. }
  23. func main() {
  24. initVersion()
  25. app := cli.NewApp()
  26. app.Name = "pbx-api-gin"
  27. app.Usage = "A PBX Manager Server"
  28. app.Version = fmt.Sprintf("%s-%s-%s", buildDateTime, gitCommitCode, goVersion)
  29. app.Commands = []cli.Command{
  30. commands.CmdWeb,
  31. commands.CmdService,
  32. }
  33. app.Flags = []cli.Flag{
  34. cli.IntFlag{
  35. Name: "level",
  36. Usage: "log level 0(panic)-6(trace), default 4(info)",
  37. Value: 4,
  38. },
  39. cli.BoolFlag{
  40. Name: "reportCaller",
  41. Usage: "if true report logger caller",
  42. },
  43. cli.BoolFlag{
  44. Name: "disableConsoleLog",
  45. Usage: "if true cancel console log",
  46. },
  47. cli.BoolFlag{
  48. Name: "release",
  49. Usage: "if true gin set release",
  50. },
  51. cli.BoolFlag{
  52. Name: "prompt",
  53. Usage: "if ture, prompt will show",
  54. },
  55. }
  56. _ = app.Run(os.Args)
  57. }
  58. func initVersion() {
  59. if gitCommitCode != "" {
  60. utils.VersionInstance.BuildDate = buildDateTime
  61. utils.VersionInstance.GoVersion = goVersion
  62. utils.VersionInstance.GitCommitCode = gitCommitCode
  63. }
  64. }