openfaas / golang-http-template

Golang templates for OpenFaaS using HTTP extensions
https://www.openfaas.com/
MIT License
106 stars 57 forks source link

Allow static files to be published into final image for Go template #72

Closed alexellis closed 2 years ago

alexellis commented 2 years ago

Signed-off-by: Alex Ellis (OpenFaaS Ltd) alexellis2@gmail.com

Description

Allow static files to be published into final image for Go template

How Has This Been Tested?

package function

import (
    "io/ioutil"
    "net/http"
)

func Handle(w http.ResponseWriter, r *http.Request) {

    data, err := ioutil.ReadFile("./static/file.txt")

    if err != nil {
        http.Error(w, err.Error(), http.StatusInternalServerError)
    }

    w.Write(data)
}

How are existing users impacted? What migration steps/scripts do we need?

This is a breaking change for existing users who rely on folder names such as templates or dataset.json within their published image.

Now, put these files into the static folder and read them from ./static/templates/index.html and so forth.

Checklist:

A note will be published in the openfaas docs repo for this new change.