Hi,
I'm using Go template in Knative Functions. Since there's only a Handle function to handle income requests, is there any recommendation about application initialization?
For example, we need to load some secret from the environment:
// handle.go
var (
token string
)
func init {
token := os.Getenv("SOME_API_TOKEN")
if(token == "") {
panic("API TOKEN not configured")
}
}
func Handle() {
// result = DoRequest(token)
// return result
}
However, it seems that use init to load environment is not a good approach, it's not test friendly anyway, see here.
So the problems is that, how to correctly add additional initialization steps?
Hi, I'm using Go template in Knative Functions. Since there's only a
Handle
function to handle income requests, is there any recommendation about application initialization?For example, we need to load some secret from the environment:
However, it seems that use
init
to load environment is not a good approach, it's not test friendly anyway, see here.So the problems is that, how to correctly add additional initialization steps?