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

     1  package route
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/iron-io/functions/examples/blog/database"
     7  )
     8  
     9  func HandlePostRead(db *database.Database, auth map[string]interface{}) {
    10  	id := os.Getenv("PARAM_ID")
    11  
    12  	if id == "" {
    13  		SendError("Missing post ID")
    14  		return
    15  	}
    16  
    17  	post, err := db.GetPost(id)
    18  	if err != nil {
    19  		SendError("Couldn't retrieve that post")
    20  		return
    21  	}
    22  
    23  	SendResponse(Response{
    24  		"post": post,
    25  	})
    26  }