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 }
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) }
func htmlError(ctx *gin.Context, err error) { ctx.Error(err) ctx.HTML(http.StatusInternalServerError, "error.html", err.Error()) }