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