Last active
April 18, 2017 03:42
-
-
Save shihanng/93d3b90a93b69410a80f8d7fd72db93d 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 main | |
import ( | |
"github.com/goadesign/goa" | |
"github.com/shihanng/simple-goa-demo/app" | |
) | |
type user struct { | |
name string | |
email string | |
} | |
// Simple DB | |
var users = make(map[string]user) | |
// UsersController implements the Users resource. | |
type UsersController struct { | |
*goa.Controller | |
} | |
// NewUsersController creates a Users controller. | |
func NewUsersController(service *goa.Service) *UsersController { | |
return &UsersController{Controller: service.NewController("UsersController")} | |
} | |
// Add runs the add action. | |
func (c *UsersController) Add(ctx *app.AddUsersContext) error { | |
u := user{ | |
name: ctx.Payload.Name, | |
email: ctx.Payload.Email, | |
} | |
users[u.name] = u | |
return ctx.Created() | |
} | |
// List runs the list action. | |
func (c *UsersController) List(ctx *app.ListUsersContext) error { | |
var res app.MyUserCollection | |
for _, u := range users { | |
res = append(res, &app.MyUser{ | |
Name: &u.name, | |
Email: &u.email, | |
}) | |
} | |
return ctx.OK(res) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment