Skip to content

Instantly share code, notes, and snippets.

@shihanng
Last active April 18, 2017 03:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shihanng/93d3b90a93b69410a80f8d7fd72db93d to your computer and use it in GitHub Desktop.
Save shihanng/93d3b90a93b69410a80f8d7fd72db93d to your computer and use it in GitHub Desktop.
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