Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle function initialization? #36

Open
drriguz opened this issue Mar 4, 2024 · 0 comments
Open

How to handle function initialization? #36

drriguz opened this issue Mar 4, 2024 · 0 comments

Comments

@drriguz
Copy link

drriguz commented Mar 4, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant