本文整理汇总了Golang中github.com/justintan/wine.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ResponseError
func ResponseError(c wine.Context, err ErrType) {
msg := ""
switch err {
case ErrParm:
msg = "parameter error"
case ErrServer:
msg = "server error"
default:
break
}
c.JSON(gox.M{"error": err, "msg": msg})
}
开发者ID:justintan,项目名称:work_report_server,代码行数:12,代码来源:util.go
示例2: GetDailyReports
func GetDailyReports(c wine.Context) {
date := c.Params().GetStr("date")
users, e := dao.GetAllUsers()
if e != nil {
ResponseError(c, ErrServer)
return
}
reports := make([]*models.DailyReport, len(users))
for i, u := range users {
r, _ := dao.GetUserDailyReport(u.Id, date)
if r == nil {
r = new(models.DailyReport)
r.ModifiedAt = time.Now().Unix()
}
r.User = u
r.UserId = u.Id
reports[i] = r
}
ResponseData(c, gox.M{"reports": reports})
}
开发者ID:justintan,项目名称:work_report_server,代码行数:23,代码来源:get_daily_reports.go
示例3: GetUserDailyReports
func GetUserDailyReports(c wine.Context) {
start := c.Params().GetStr("start")
end := c.Params().GetStr("end")
var st time.Time
var et time.Time
var e error
if st, e = time.Parse("2006-01-02", start); e != nil {
ResponseError(c, ErrParm)
return
}
if et, e = time.Parse("2006-01-02", end); e != nil {
ResponseError(c, ErrParm)
return
}
userId := c.Params().GetInt64("user_id")
user, _ := dao.GetUser(userId)
if user == nil {
ResponseError(c, ErrParm)
return
}
var reports []*models.DailyReport
stt := st.Unix()
ett := et.Unix()
for t := stt; t <= ett; t += 24 * 3600 {
d := time.Unix(t, 0).Format("2006-01-02")
r, _ := dao.GetUserDailyReport(userId, d)
if r == nil {
r = new(models.DailyReport)
r.ModifiedAt = time.Now().Unix()
}
r.User = user
r.UserId = userId
r.Date = d
reports = append(reports, r)
}
ResponseData(c, gox.M{"reports": reports, "user": user})
}
开发者ID:justintan,项目名称:work_report_server,代码行数:43,代码来源:get_user_daily_reports.go
示例4: HandleIndex
func HandleIndex(c wine.Context) {
date := c.Params().GetStr("date")
_, e := time.Parse("2006-01-02", date)
if e != nil {
date = time.Now().In(time.FixedZone("", 8*3600)).Format("2006-01-02")
}
t, _ := time.Parse("2006-01-02", date)
previousDate := t.Add(-24 * 3600 * time.Second).In(time.FixedZone("", 8*3600)).Format("2006-01-02")
nextDate := t.Add(24 * 3600 * time.Second).In(time.FixedZone("", 8*3600)).Format("2006-01-02")
params := gox.M{}
params["previous_date"] = previousDate
params["next_date"] = nextDate
params["date"] = date
params["user_start_date"] = t.Add(-10 * 24 * 3600 * time.Second).In(time.FixedZone("", 8*3600)).Format("2006-01-02")
params["user_end_date"] = date
params["title"] = date + "(" + DaysOfWeek[t.Weekday()] + ")"
//log.Println(params)
resp, _ := http.Get("http://localhost:8001/daily-reports/" + date)
data, _ := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
var respMap map[string]interface{}
if err := json.Unmarshal(data, &respMap); err == nil {
if data, ok := respMap["data"].(map[string]interface{}); ok {
if reports, ok := data["reports"].([]interface{}); ok {
params["reports"] = reports
c.TemplateHTML("index.tmpl", params)
return
}
}
}
log.Println(respMap)
c.TemplateHTML("error.tmpl", nil)
return
}
开发者ID:justintan,项目名称:work_report_web,代码行数:38,代码来源:index.go
示例5: HandleUserDailyReports
func HandleUserDailyReports(c wine.Context) {
start := c.Params().GetStr("start")
end := c.Params().GetStr("end")
var st time.Time
var et time.Time
var e error
if st, e = time.Parse("2006-01-02", start); e != nil {
c.TemplateHTML("error.tmpl", gox.M{"msg": "invalid date"})
return
}
if et, e = time.Parse("2006-01-02", end); e != nil {
c.TemplateHTML("error.tmpl", gox.M{"msg": "invalid date"})
return
}
userId, _ := strconv.ParseInt(c.Params().GetStr("user_id"), 10, 64)
if userId <= 0 {
c.TemplateHTML("error.tmpl", gox.M{"msg": "invalid date"})
return
}
resp, e := http.Get("http://localhost:8001/user/" + c.Params().GetStr("user_id") + "/daily-reports/" + start + "/" + end)
if e != nil {
c.TemplateHTML("error.tmpl", gox.M{"msg": "server error"})
return
}
data, _ := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
params := gox.M{}
previousStart := st.AddDate(0, 0, -10).Format("2006-01-02")
nextEnd := et.AddDate(0, 0, 10).Format("2006-01-02")
params["previous_start"] = previousStart
params["next_end"] = nextEnd
params["start"] = start
params["end"] = end
var respMap map[string]interface{}
if err := json.Unmarshal(data, &respMap); err == nil {
if data, ok := respMap["data"].(map[string]interface{}); ok {
if reports, ok := data["reports"].([]interface{}); ok {
for _, r := range reports {
m := r.(map[string]interface{})
t, _ := time.Parse("2006-01-02", m["date"].(string))
m["date"] = m["date"].(string) + "(" + DaysOfWeek[t.Weekday()] + ")"
}
if user, ok := data["user"].(map[string]interface{}); ok {
params["reports"] = reports
params["user"] = user
c.TemplateHTML("user_daily_reports.tmpl", params)
return
}
}
}
}
log.Println(respMap)
c.TemplateHTML("error.tmpl", gox.M{"msg": "server error"})
}
开发者ID:justintan,项目名称:work_report_web,代码行数:63,代码来源:user_daily_reports.go
示例6: HandlePostDailyReport
func HandlePostDailyReport(c wine.Context) {
var req PostDailyReportRequest
req.UserId = c.Params().GetInt64("user_id")
req.Date = c.Params().GetStr("date")
req.Work = c.Params().GetStr("work")
req.Plan = c.Params().GetStr("plan")
req.Remark = c.Params().GetStr("remark")
if req.UserId < 0 || len(req.Date) == 0 {
c.JSON(gox.M{"error": 1})
return
}
values := url.Values{}
values.Set("user_id", strconv.FormatInt(req.UserId, 10))
values.Set("date", req.Date)
values.Set("work", req.Work)
values.Set("plan", req.Plan)
values.Set("remark", req.Remark)
resp, e := http.DefaultClient.PostForm("http://localhost:8001/daily-report", values)
if e != nil {
c.JSON(gox.M{"error": 2, "msg": "server error"})
return
}
data, _ := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
var respMap map[string]interface{}
if err := json.Unmarshal(data, &respMap); err == nil {
if err, ok := respMap["error"].(float64); ok && int(err) == 0 {
c.JSON(gox.M{"error": 0})
} else {
log.Println(respMap)
c.JSON(gox.M{"error": 1, "msg": "failed to add report"})
}
} else {
log.Println(respMap)
c.JSON(gox.M{"error": 2, "msg": "server error"})
}
}
开发者ID:justintan,项目名称:work_report_web,代码行数:41,代码来源:post_daily_report.go
示例7: ResponseData
func ResponseData(c wine.Context, data interface{}) {
c.JSON(gox.M{"error": ErrNone, "msg": "", "data": data})
}
开发者ID:justintan,项目名称:work_report_server,代码行数:3,代码来源:util.go
注:本文中的github.com/justintan/wine.Context类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论