github.com/louisevanderlith/droxolite@v1.20.2/mix/page.go (about)

     1  package mix
     2  
     3  import (
     4  	"bytes"
     5  	"html/template"
     6  	"io"
     7  )
     8  
     9  //Page provides a io.Reader for serving html pages
    10  type pge struct {
    11  	template    *template.Template
    12  	title       string
    13  	name        string
    14  	model       map[string]interface{}
    15  }
    16  
    17  func (r *pge) Headers() map[string]string {
    18  	result := make(map[string]string)
    19  
    20  	result["X-Frame-Options"] = "SAMEORIGIN"
    21  	result["X-XSS-Protection"] = "1; mode=block"
    22  	result["Strict-Transport-Security"] = "max-age=31536000; includeSubDomains"
    23  	result["Access-Control-Allow-Credentials"] = "true"
    24  	result["Server"] = "kettle"
    25  	result["X-Content-Type-Options"] = "nosniff"
    26  
    27  	return result
    28  }
    29  
    30  //Reader configures the response for reading
    31  func (r *pge) Reader() io.Reader {
    32  
    33  	pageBuff := bytes.Buffer{}
    34  	err := r.template.ExecuteTemplate(&pageBuff, r.name, r.model)
    35  
    36  	if err != nil {
    37  		panic(err)
    38  	}
    39  
    40  	return &pageBuff
    41  }