mirror of
https://github.com/openfaas/faasd.git
synced 2025-06-10 00:46:47 +00:00
By moving to a reference instead of a value type, this patch means the annotations are not leaked into other objects in the result of ListFunctions. Tested on x86 with a Linux host and I could no longer reproduce the issue in #128 Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
44 lines
973 B
Go
44 lines
973 B
Go
package handlers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"log"
|
|
"net/http"
|
|
|
|
"github.com/containerd/containerd"
|
|
"github.com/openfaas/faas-provider/types"
|
|
)
|
|
|
|
func MakeReadHandler(client *containerd.Client) func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
res := []types.FunctionStatus{}
|
|
fns, err := ListFunctions(client)
|
|
if err != nil {
|
|
log.Printf("[Read] error listing functions. Error: %s\n", err)
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
for _, fn := range fns {
|
|
annotations := &fn.annotations
|
|
labels := &fn.labels
|
|
res = append(res, types.FunctionStatus{
|
|
Name: fn.name,
|
|
Image: fn.image,
|
|
Replicas: uint64(fn.replicas),
|
|
Namespace: fn.namespace,
|
|
Labels: labels,
|
|
Annotations: annotations,
|
|
})
|
|
}
|
|
|
|
body, _ := json.Marshal(res)
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(http.StatusOK)
|
|
w.Write(body)
|
|
|
|
}
|
|
}
|