Importing a constants file in go

Viewed 38

I have this package structure in my go module, and I am adding commands using cobra-cli:

.
├── LICENSE
├── cmd
│   ├── constants.go
│   ├── root.go
│   └── tools
│       └── tools.go
├── go.mod
├── go.sum
└── main.go

In tools.go, I want to import constants.go which I want to define for globally used constants across all files in my module, and is simple go file:

package cmd

const (
    FOO = "https://a.b.c"
    BAR = "https://p.q.r"
)

How do I import this? Also is there a better way of doing this?

1 Answers

import cycle not allowed when you used constant.go inside tools.go and used tools.go inside constant.go, and create a cycle call each other, please check you code import cycle not allowed when you used constant.go inside tools.go and used tools.go inside constant.go, and create a cycle call each other, please check you code

Related