functions

The Fool guy's FAAS
git clone git://git.lair.cx/functions
Log | Files | Refs | README

commit 1de0e8ffb2ffb58897edfb081e5ac6acc5d2f754
parent c4032e7c5794cef10bdbd6865eb67e0133086a03
Author: Yongbin Kim <iam@yongbin.kim>
Date:   Fri,  8 Sep 2023 20:03:41 +0900

Enable setting 'rootDomain' configuration via environment variables

Signed-off-by: Yongbin Kim <iam@yongbin.kim>

Diffstat:
MREADME | 10+++++++++-
Mcmd/functions/main.go | 11++++++++++-
Mconfigs/configs.go | 10+++++-----
3 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/README b/README @@ -34,7 +34,7 @@ You can use the following URI format to call your function. (Note that wildcard subdomain is required.) ``` -{http|https}://{namespace}.{configs.RootDomain}/{function} +{http|https}://{namespace}.{rootDomain}/{function} ``` This will call `{configs.FuncDir}/$namespace/$function`. @@ -46,6 +46,14 @@ curl --resolve '*:8080:127.0.0.1' http://example.domain.tld:8080/helloworld ``` +Configuration +---------------- + +You can configure the server by editing `configs/config.go`. + +As an exception, `rootDomain` can be set with `ROOT_DOMAIN` environment variable. + + Why you made this? ---------------- diff --git a/cmd/functions/main.go b/cmd/functions/main.go @@ -25,6 +25,15 @@ var ( regexResponseStatusLine = regexp.MustCompile(`^HTTP/1\.[01] ([0-9]{3})`) ) +var rootDomain = func() string { + rootDomain := os.Getenv("ROOT_DOMAIN") + if rootDomain != "" { + return rootDomain + } + + return configs.DefaultRootDomain +}() + func main() { server := &http.Server{ Addr: configs.ServerAddr, @@ -274,7 +283,7 @@ func stripHostSuffix(host, suffix string) (string, bool) { } func readURL(host, path string) (namespace, function string, ok bool) { - namespace, ok = stripHostSuffix(host, configs.RootDomain) + namespace, ok = stripHostSuffix(host, rootDomain) if !ok { return "", "", false } diff --git a/configs/configs.go b/configs/configs.go @@ -3,9 +3,9 @@ package configs import "time" const ( - RootDomain = "functions.dev" - ServerAddr = ":8080" - ReadTimeout = 5 * time.Second - WriteTimeout = 5 * time.Second - ShutdownTimeout = 5 * time.Second + DefaultRootDomain = "fn" + ServerAddr = ":8080" + ReadTimeout = 5 * time.Second + WriteTimeout = 5 * time.Second + ShutdownTimeout = 5 * time.Second )