Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "github.com/gin-gonic/gin"
  6. "gopkg.in/urfave/cli.v2"
  7. "log"
  8. "os"
  9. "runtime"
  10. "strconv"
  11. "sort“
  12. )
  13. var (
  14. app = &cli.App{
  15. Name: "trader",
  16. Usage: "free quantization for cryptocurrency !",
  17. Version : "1.0.0",
  18. Flags: []cli.Flag {
  19. &cli.StringFlag{
  20. Name: "lang",
  21. Value: "english",
  22. Usage: "language for display",
  23. },
  24. &cli.IntFlag {
  25. Name: "port, p",
  26. Value: 8080,
  27. Usage: "listening web port",
  28. },
  29. },
  30. Commands: []*cli.Command{
  31. {
  32. Name: "complete",
  33. Aliases: []string{"c"},
  34. Usage: "complete a task on the list",
  35. Action: func(c *cli.Context) error {
  36. return nil
  37. },
  38. },
  39. {
  40. Name: "add",
  41. Aliases: []string{"a"},
  42. Usage: "add a task to the list",
  43. Action: func(c *cli.Context) error {
  44. return nil
  45. },
  46. },
  47. },
  48. })
  49. func init() {
  50. app.Action = rundeamon
  51. app.Before = func(ctx *cli.Context) error {
  52. runtime.GOMAXPROCS(runtime.NumCPU())
  53. return nil
  54. }
  55. app.After = func(c *cli.Context) error {
  56. fmt.Println("app After")
  57. return nil
  58. }
  59. sort.Sort(cli.FlagsByName(app.Flags))
  60. sort.Sort(cli.CommandsByName(app.Commands))
  61. }
  62. func rundeamon(ctx *cli.Context) error {
  63. if args := ctx.Args(); args.Len() > 0 {
  64. return fmt.Errorf("invalid command: %q", args.Get(0))
  65. }
  66. port := ctx.Int("port")
  67. r := gin.Default()
  68. r.GET("/ping", func(c *gin.Context) {
  69. c.JSON(200, gin.H{
  70. "message": "pong",
  71. })
  72. })
  73. r.Run(fmt.Sprintf(":%s",strconv.Itoa(port))) // listen and serve on 0.0.0.0:8080
  74. return nil
  75. }
  76. func main() {
  77. err := app.Run(os.Args)
  78. if err != nil {
  79. log.Fatal(err)
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement