Skip to content

How to handle function initialization? #36

Open
@drriguz

Description

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions