Created
February 26, 2020 13:12
-
-
Save bastianccm/b6bc8276f255ea456868b7890991a329 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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