Exemple #1
0
func main() {
	s := wine.Default()
	s.Get("login", func(c wine.Context) {
		username := c.Params().GetStr("username")
		password := c.Params().GetStr("password")
		if len(username) == 0 || len(password) == 0 {
			c.JSON(types.M{"code": 1, "msg": "login error"})
			return
		}
		u := &User{}
		u.ID = 1
		u.Name = "guest"
		u.CreatedAt = time.Now().Unix()
		c.JSON(types.M{"code": 0, "msg": "success", "data": u})
	})

	s.Post("topic", func(c wine.Context) {
		title := c.Params().GetStr("title")
		if len(title) == 0 {
			c.JSON(types.M{"code": 1, "msg": "no title"})
			return
		}
		t := &Topic{}
		t.ID = 2
		t.User = &User{ID: 1, Name: "guest", CreatedAt: time.Now().Unix()}
		t.CreatedAt = time.Now().Unix()
		c.JSON(types.M{"code": 2, "msg": "success", "data": t})
	})

	go func() {
		log.Println(http.ListenAndServe("localhost:6060", nil))
	}()

	s.Run(":8000")
}
Exemple #2
0
func main() {
	publicFilePath := "/Users/qiyu/gocode/src/work_report_web/public"
	viewFilePath := "views"
	r := wine.Default()
	r.StaticFS("/report/public", http.Dir(publicFilePath))
	r.AddGlobTemplate(viewFilePath + "/*")
	//	r.GET("/", func(c wine.Context) {
	//		controllers.HandleIndex(c)
	//	})

	r.Get("/report", func(c wine.Context) {
		controllers.HandleIndex(c)
	})

	//	r.GET("/user/:user_id/daily-reports/:start/:end", func(c wine.Context) {
	//		controllers.HandleUserDailyReports(c)
	//	})

	r.Get("/report/user/:user_id/daily-reports/:start/:end", func(c wine.Context) {
		controllers.HandleUserDailyReports(c)
	})

	//	r.POST("/daily-report", func(c wine.Context) {
	//		controllers.HandlePostDailyReport(c)
	//	})

	r.Post("/report/daily-report", func(c wine.Context) {
		controllers.HandlePostDailyReport(c)
	})

	r.Run(":8000")
}
Exemple #3
0
func main() {
	s := wine.Default()
	s.RegisterContext(&MyContext{})
	s.Get("time", func(c wine.Context) {
		ctx := c.(*MyContext)
		ctx.SendResponse(0, "", time.Now().Unix())
	})
	s.Run(":8000")
}
Exemple #4
0
func main() {
	s := wine.Default()
	s.Get("/", func(c wine.Context) {
		c.Text("root")
	})

	s.Get("hi", func(c wine.Context) {
		c.Text("hi")
	})

	s.Group("hi").Get("/", func(c wine.Context) {
		c.Text("hi")
	})

	s.Get("hello", func(c wine.Context) {
		c.Text("Hello, wine!")
	})

	s.Get("docs/create", func(c wine.Context) {
		c.Text("Create doc")
	})

	s.Get("docs/:s/a", func(c wine.Context) {
		c.Text("Create doc: " + c.Params().GetStr("s"))
	})

	s.Get("docs/:doc_id", func(c wine.Context) {
		c.Text("doc id is " + c.Params().GetStr("doc_id"))
	})

	s.Get("sum/:a,:b", func(c wine.Context) {
		r := c.Params().GetInt("a") + c.Params().GetInt("b")
		c.Text(fmt.Sprint(r))
	})

	s.Get("sum/:a,:b/hehe", func(c wine.Context) {
		r := c.Params().GetInt("a") * c.Params().GetInt("b")
		c.Text(fmt.Sprint(r))
	})

	s.Get("sum/:a,:b,:c", func(c wine.Context) {
		r := c.Params().GetInt("a") + c.Params().GetInt("b") + c.Params().GetInt("c")
		c.Text(fmt.Sprint(r))
	})

	s.StaticDir("hello/*", "../../websites/hello/html")

	s.Run(":8000")
}
Exemple #5
0
func main() {
	//	dao.InitDAO("/Users/qiyu/gocode/src/work_report_server/test.db")
	dao.InitDAO("work_report.db")
	r := wine.Default()

	r.Post("/user", func(c wine.Context) {
		services.AddUser(c)
	})

	r.Post("/daily-report", func(c wine.Context) {
		services.AddDailyReport(c)
	})

	r.Get("/daily-reports/:date", func(c wine.Context) {
		services.GetDailyReports(c)
	})

	r.Get("/user/:user_id/daily-reports/:start/:end", func(c wine.Context) {
		services.GetUserDailyReports(c)
	})

	r.Run(":8001")
}
Exemple #6
0
func main() {
	s := wine.Default()
	s.StaticDir("/", "./html")
	s.Run(":8000")
}