示例#1
0
文件: web.go 项目: peter-edge/days
func parseInput(ctx *gin.Context) (*days.Input, error) {
	daysFromTodayStr := ctx.Query("days_from_today")
	var daysFromToday int64
	var err error
	if daysFromTodayStr != "" {
		daysFromToday, err = strconv.ParseInt(daysFromTodayStr, 10, 32)
		if err != nil {
			return nil, err
		}
	}
	return &days.Input{
		DaysFromToday: int32(daysFromToday),
	}, nil
}
示例#2
0
文件: web.go 项目: peter-edge/days
func calculate(ctx *gin.Context, apiClient days.APIClient) {
	input, err := parseInput(ctx)
	if err != nil {
		htmlError(ctx, err)
		return
	}
	protolion.Info(input)
	output, err := apiClient.Calculate(context.Background(), input)
	if err != nil {
		htmlError(ctx, err)
		return
	}
	protolion.Info(output)
	ctx.HTML(http.StatusOK, "calculate.html", output)
}
示例#3
0
文件: web.go 项目: peter-edge/days
func htmlError(ctx *gin.Context, err error) {
	ctx.Error(err)
	ctx.HTML(http.StatusInternalServerError, "error.html", err.Error())
}