Build with Go 1.20 and update misc dependencies

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis (OpenFaaS Ltd)
2023-07-06 11:04:06 +01:00
parent 7d073bd64b
commit d0219d6697
179 changed files with 2479 additions and 1257 deletions

View File

@ -78,6 +78,17 @@ func Serve(handlers *types.FaaSHandlers, config *types.FaaSConfig) {
r.HandleFunc("/system/namespaces", hm.InstrumentHandler(handlers.ListNamespaces, "")).Methods(http.MethodGet)
// Only register the mutate namespace handler if it is defined
if handlers.MutateNamespace != nil {
r.HandleFunc("/system/namespace/{namespace:["+NameExpression+"]+}",
hm.InstrumentHandler(handlers.MutateNamespace, "")).Methods(http.MethodPost, http.MethodDelete, http.MethodPut, http.MethodGet)
} else {
r.HandleFunc("/system/namespace/{namespace:["+NameExpression+"]+}",
hm.InstrumentHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Feature not implemented in this version of OpenFaaS", http.StatusNotImplemented)
}), "")).Methods(http.MethodGet)
}
proxyHandler := handlers.FunctionProxy
// Open endpoints

View File

@ -12,8 +12,13 @@ const (
// FaaSHandlers provide handlers for OpenFaaS
type FaaSHandlers struct {
// ListNamespace lists namespaces which are annotated for OpenFaaS
ListNamespaces http.HandlerFunc
// MutateNamespace mutates a namespace to be annotated for OpenFaaS
// each namespace must contain an annotation of "openfaas=1"
MutateNamespace http.HandlerFunc
// FunctionProxy provides the function invocation proxy logic. Use proxy.NewHandlerFunc to
// use the standard OpenFaaS proxy implementation or provide completely custom proxy logic.
FunctionProxy http.HandlerFunc

View File

@ -1,6 +1,7 @@
package types
import (
"errors"
"fmt"
"os"
"strconv"
@ -55,6 +56,26 @@ func ParseIntOrDurationValue(val string, fallback time.Duration) time.Duration {
return duration
}
// ParseIntOrDurationValue interprets a string representing an int or duration and returns
// an int as the number of seconds. An error is returned if val can not be parsed as int or duration.
func ParseIntOrDuration(val string) (int, error) {
i, err := strconv.ParseInt(val, 10, 0)
if err == nil {
return int(i), nil
}
if err != nil && errors.Is(err, strconv.ErrRange) {
return int(i), err
}
d, err := time.ParseDuration(val)
if err != nil {
return 0, err
}
return int(d.Seconds()), nil
}
// ParseBoolValue parses the the boolean in val or, if there is an error, returns the
// specified default value
func ParseBoolValue(val string, fallback bool) bool {

View File

@ -27,3 +27,12 @@ type VersionInfo struct {
SHA string `json:"sha"`
Release string `json:"release"`
}
// FunctionNamespace is required for use with the /system/namespace/NAME endpoint
// for deletions, just pass the namespace field.
type FunctionNamespace struct {
Namespace string `json:"namespace"`
Annotations map[string]string `json:"annotations,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
}