github.com/drone/runner-go@v1.12.0/handler/render.go (about)

     1  // Copyright 2019 Drone.IO Inc. All rights reserved.
     2  // Use of this source code is governed by the Polyform License
     3  // that can be found in the LICENSE file.
     4  
     5  package handler
     6  
     7  import (
     8  	"encoding/json"
     9  	"net/http"
    10  
    11  	"github.com/drone/runner-go/handler/template"
    12  )
    13  
    14  // renderJSON writes the json-encoded representation of v to
    15  // the response body.
    16  func renderJSON(w http.ResponseWriter, v interface{}) {
    17  	for k, v := range noCacheHeaders {
    18  		w.Header().Set(k, v)
    19  	}
    20  	w.Header().Set("Content-Type", "application/json")
    21  	enc := json.NewEncoder(w)
    22  	enc.SetIndent("", "  ")
    23  	enc.Encode(v)
    24  }
    25  
    26  // render writes the template to the response body.
    27  func render(w http.ResponseWriter, t string, v interface{}) {
    28  	w.Header().Set("Content-Type", "text/html")
    29  	template.T.ExecuteTemplate(w, t, v)
    30  }