added blog example

This commit is contained in:
Pedro Nasser
2016-08-30 16:47:34 -03:00
parent b95e88bfdf
commit c9de0428aa
14 changed files with 597 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
package route
import (
"encoding/json"
"fmt"
"os"
"github.com/iron-io/functions/examples/blog/database"
"github.com/iron-io/functions/examples/blog/models"
)
func HandlePostCreate(db *database.Database, auth map[string]interface{}) {
var post *models.Post
err := json.Unmarshal([]byte(os.Getenv("PAYLOAD")), &post)
if err != nil {
fmt.Println("Invalid post")
return
}
post, err = db.SavePost(post)
if err != nil {
fmt.Println("Couldn't save that post")
return
}
SendResponse(Response{
"post": post,
})
}