Files
fn-serverless/examples/blog/routes/post_create.go
2017-04-19 09:49:12 -06:00

32 lines
582 B
Go

package route
import (
"encoding/json"
"fmt"
"os"
"github.com/kumokit/functions/examples/blog/database"
"github.com/kumokit/functions/examples/blog/models"
)
func HandlePostCreate(db *database.Database, auth map[string]interface{}) {
var post *models.Post
if err := json.NewDecoder(os.Stdin).Decode(&post); err != nil {
fmt.Printf("Couldn't decode post JSON: %v\n", err)
return
}
post, err := db.SavePost(post)
if err != nil {
fmt.Println("Couldn't save that post")
return
}
post.User = auth["user"].(string)
SendResponse(Response{
"post": post,
})
}