func (c *UserController) GetUserByID(ctx *context.Context, userID int64) { user, err := models.GetUserByID(userID) if err != nil { ctx.RenderWithErr("User not found", http.StatusNotFound) return } ctx.Data["User"] = user ctx.HTML(http.StatusOK, "user") }
func (c *RepoController) CreateTag(ctx *context.Context) { tagName := strings.TrimSpace(ctx.Query("tag")) if tagName == "" { ctx.RenderWithErr("Tag name cannot be empty", http.StatusBadRequest) return } // Create tag code ctx.Redirect(fmt.Sprintf("/%s/src/%s/%s/refs", user.Name, repo.Name)) }In this example, if the tag name is empty, the RenderWithErr function is used to render a bad request error page with the message "Tag name cannot be empty".