I have a struct which I initiate in some process like following, and this is working as expected.
This is specific runner
type TestRunner struct {
path string
name string
}
func NewRunner(p string, n string) *TestRunner {
return &TestRunner{
path: p,
name: n,
}
}
Now I want in the same package to create another runner so I do it like this e.g.
Also specific runner
type TestRunner2 struct {
path string
name string
}
func NewRunner(p string, n string) *TestRunner2 {
return &TestRunner2{
path: p,
name: n,
}
}
Now I get error that the func NewRunner
is exist
I have another file (in the same package) which include the interface
This is generic implementation (different file in the same package)
type Runner interface {
Run(path string) error
ChangePath(newPath string)
}
So maybe the NewRunner should be there, where its recommended to put the new object ?
obviously I can create NewRunner1
and NewRunner2
method in the file but im not sure if it’s recommended