Here is my directory structure:
my_project
my_api
main.go
util_dir
util.go
I am passing some environment variables in the init function inside the main.go since I want them to be sourced whenever my service starts.
Below is the main.go code snippet:
import (
"net/url"
"net"
)
func init() {
...
data := url.Values{}
data.Add("client_id", os.Getenv("CLIENTID"))
data.Add("client_secret", os.Getenv("CLIENTSECRET"))
}
I want to do something like this inside util.go :
import (
"os"
"github.com/my_project/my_api"
)
func validation() {
data.data.Add("scope", "xyzid")
data.data.Add("another_secret", "SECRET")
client := &http.Client{}
req, err := http.NewRequest("POST", urlStr, bytes.NewBufferString(data.data.Encode()))
}
I am getting an error that import github.com/my_project/my_api is a program, not an importable package.
I want to know what is a work around for this problem?
mainpackage. I'm not sure what you're trying to do, but you if main imports the util package, you would have a circular dependency even if this were possible.