Exemple #1
0
func main() {

	// create channel to communicate over
	jobs := make(chan todos.Job)

	//log.Crit("start process job")
	// start watching jobs channel for work
	go todos.ProcessJobs(jobs, Db)

	// create dependencies
	client := &todos.TodoClient{Jobs: jobs}
	handlers := &TodoHandlers{Client: client}

	//************************************************************

	app := cli.NewApp()
	app.Name = "todo-cli"
	app.Usage = "todo cli"
	app.Action = func(c *cli.Context) {
		println("Hello friend!")
	}

	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:   "lang, l",
			Value:  "english",
			Usage:  "language for the greeting",
			EnvVar: "LEGACY_COMPAT_LANG,APP_LANG,LANG",
		},
	}

	app.Action = func(c *cli.Context) {
		//name := "someone"
		if len(c.Args()) > 0 {
			name := c.Args()[0]
			fmt.Println("name is ", name)
		} else {
			cli.ShowAppHelp(c)
		}
	}

	app.Commands = []cli.Command{
		{
			Name:    "add",
			Aliases: []string{"a"},
			Usage:   "add a task to the list",
			Action: func(c *cli.Context) {
				handlers.AddTodo(c)
			},
		},
		{
			Name:    "add",
			Aliases: []string{"a"},
			Usage:   "add a todo to the list",
			Action: func(c *cli.Context) {
				handlers.AddTodo(c)
			},
		},
		{
			Name:    "update",
			Aliases: []string{"u"},
			Usage:   "update todo by id ",
			Action: func(c *cli.Context) {
				handlers.SaveTodo(c)
			},
		},
		{
			Name:    "delete",
			Aliases: []string{"d"},
			Usage:   "delete a todo by id",
			Action: func(c *cli.Context) {
				handlers.DeleteTodo(c)
			},
		},
		{
			Name:    "query",
			Aliases: []string{"q"},
			Usage:   "query a todo by id",
			Action: func(c *cli.Context) {
				handlers.GetTodo(c)
			},
		},

		{
			Name:    "list",
			Aliases: []string{"l"},
			Usage:   "list all todos",
			Action: func(c *cli.Context) {
				handlers.GetTodos(c)
			},
		},
	}

	app.Run(os.Args)
}
Exemple #2
0
func main() {
	// runtime.GOMAXPROCS(runtime.NumCPU() * 2)
	/*
		// init postgres DB connection
		dbhost := "localhost"
		dbuser := "******"
		dbpassword := "******"
		dbname := "tsingcloud"

		taskPgdb := new(postgres.PostgresDB)
		taskPgdb.InitDb(dbhost, dbuser, dbpassword, dbname)
		defer taskPgdb.Pool.Close()

		taskPgdb.ListTasks()
	*/

	// create channel to communicate over
	jobs := make(chan todos.Job)

	log.Crit("start process job")
	// start watching jobs channel for work
	go todos.ProcessJobs(jobs, Db)

	// create dependencies
	client := &todos.TodoClient{Jobs: jobs}
	handlers := &TodoHandlers{Client: client}

	//var staticHtmlPath string
	staticHtmlPath := "/Users/qinshen/git/web-project/redux-learning/redux-async-learning/dist"
	// configure routes
	router := gin.Default()
	router.Static("/static", staticHtmlPath)
	//*****************************************************************************
	//  jwt token handle
	//*****************************************************************************

	//router.Use( CommHeade)

	router.GET("/user/token", JwtGetToken)
	router.POST("/user/balance", JwtCheckToken)

	//*****************************************************************************
	//  action for todos
	//*****************************************************************************

	v1 := router.Group("/v1")
	{
		v1.POST("/todo", handlers.AddTodo)
		v1.GET("/todo", handlers.GetTodos)
		v1.GET("/todo/:id", handlers.GetTodo)
		v1.PUT("/todo/:id", handlers.SaveTodo)
		v1.DELETE("/todo/:id", handlers.DeleteTodo)
	}

	router.GET("/", func(c *gin.Context) {
		c.Redirect(301, "/github")
	})

	//*****************************************************************************
	// test only  end
	//*****************************************************************************

	// start web server
	router.Run(":8080")

	/*
		routerAdmin := gin.Default()
		// start web server
		// debug
		// automatically add routers for net/http/pprof
		// e.g. /debug/pprof, /debug/pprof/heap, etc.
		routerAdmin.GET("/test", func(c *gin.Context) {
			c.Writer.Header().Set("link", nextPageUrl)
			c.Writer.Header().Set("token", token)
			c.Writer.Header().Set("X-GitHub-Media-Type", "github.v3")

			c.Data(200, "application/json; charset=utf-8", jsonData)
		})

		ginpprof.Wrapper(routerAdmin)
		//routerAdmin.Run(":8091")

	*/
}