'Can you access the cancelFunc() property of a context declared in a different package?

Hopefully this makes sense. I have a program I'm writing, which is all but finished and ready for testing, with one minor (major issue). In the Model package, the context is declared perfectly well, and the cancelFunc is accessible and can be called with a defer as normal:

CTX, cancel := context.WithTimeout(context.Background(), 10*time.Second)
    defer cancel()

However, when I try to call and use CTX from the main function, cancel is apparently an unresolved reference. CTX can be used perfectly well by calling Model.CTX, but I'm not sure what I'm doing wrong. This is the code that doesn't work:

Model.CTX, cancel = context.WithTimeout(context.Background(), 10*time.Second)
    cancel()

Apologies if this is a bad question, as always I'm open to suggestions to improve the quality of my questions.

Thankyou

go


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source