mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
added blog example
This commit is contained in:
30
examples/blog/routes/post_create.go
Normal file
30
examples/blog/routes/post_create.go
Normal 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,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user