I want to put all my models in a shared Common
lib.
So, I made a new repo: gitlab.com/xxx/common
Inside I put a package: models
Here is the definition of an object:
type Meter struct {
ID string
OperationID string
Type ConsoProd
Unit string
Timestep time.Duration
Measures []Measure
FetchMethod AcquisitionMethod
Metadata interface{}
}
Now, I want to use it in an external project, I do:
go get gitlab.com/xxx/common
And Go Modules will download it.
I import use it like that:
import "gitlab.com/xxx/common/models"
//String transparent method
func (meter models.Meter) String() string {
var stringifyMeter string
stringifyMeter += "Meter " + meter.ID + " is a " + meter.Type.String() + " and compute in operation #" + meter.OperationID + "."
return stringifyMeter
}
But Goland will not resolve it, and when I compile, I get:
cannot define new methods on non-local type models.Meter
Why is it happening and what can I do to fix it ?