github.com/iron-io/functions@v0.0.0-20180820112432-d59d7d1c40b2/examples/blog/routes/post_create.go (about)

     1  package route
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"os"
     7  
     8  	"github.com/iron-io/functions/examples/blog/database"
     9  	"github.com/iron-io/functions/examples/blog/models"
    10  )
    11  
    12  func HandlePostCreate(db *database.Database, auth map[string]interface{}) {
    13  	var post *models.Post
    14  
    15  	if err := json.NewDecoder(os.Stdin).Decode(&post); err != nil {
    16  		fmt.Printf("Couldn't decode post JSON: %v\n", err)
    17  		return
    18  	}
    19  
    20  	post, err := db.SavePost(post)
    21  	if err != nil {
    22  		fmt.Println("Couldn't save that post")
    23  		return
    24  	}
    25  
    26  	post.User = auth["user"].(string)
    27  
    28  	SendResponse(Response{
    29  		"post": post,
    30  	})
    31  }