Skip to content

Instantly share code, notes, and snippets.

@bastianccm
Created February 26, 2020 13:12
Show Gist options
  • Save bastianccm/b6bc8276f255ea456868b7890991a329 to your computer and use it in GitHub Desktop.
Save bastianccm/b6bc8276f255ea456868b7890991a329 to your computer and use it in GitHub Desktop.
package polls
import (
"context"
"fmt"
"net/http"
"strconv"
"strings"
"flamingo.me/flamingo/v3/framework/web"
)
type controller struct {
responder *web.Responder
}
func (c *controller) Inject(responder *web.Responder) {
c.responder = responder
}
func (c *controller) index(ctx context.Context, request *web.Request) web.Result {
return c.responder.HTTP(http.StatusOK, strings.NewReader("Hello, world. You're at the polls index."))
}
func (c *controller) detail(ctx context.Context, request *web.Request) web.Result {
questionID, err := strconv.Atoi(request.Params["question_id"])
if err != nil {
return c.responder.ServerError(err)
}
return c.responder.HTTP(http.StatusOK, strings.NewReader(fmt.Sprintf("You're looking at question %d.", questionID)))
}
func (c *controller) results(ctx context.Context, request *web.Request) web.Result {
questionID, err := strconv.Atoi(request.Params["question_id"])
if err != nil {
return c.responder.ServerError(err)
}
return c.responder.HTTP(http.StatusOK, strings.NewReader(fmt.Sprintf("You're looking at question %d.", questionID)))
}
func (c *controller) vote(ctx context.Context, request *web.Request) web.Result {
questionID, err := strconv.Atoi(request.Params["question_id"])
if err != nil {
return c.responder.ServerError(err)
}
return c.responder.HTTP(http.StatusOK, strings.NewReader(fmt.Sprintf("You're looking at question %d.", questionID)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment