My goal is to automatically generate Golang declaration files based on .json data. While with TypeScript I can consolidate types/declarations in one file using namespaces, it seems more complex to achieve the same with Golang packages and namespacing.
In TypeScript, I can structure my declarations like this:
export namespace Entities {
export namespace Foo {
export namespace GET {
export namespace Basic {
export interface Req { }
export interface Res { }
}
}
export namespace PUT {
export namespace Basic {
export interface Req { }
export interface Res { }
}
}
}
}
So my question is - can I achieve something similar in Golang? Or do I have to resort to separate files and folders for different namespaces?
The only approach I know of in Golang involves placing types in separate files:
entities/
foo/
get/
put/
post/
delete/
And then within each folder, something like:
package get
type Basic struct {
Req struct {}
Res struct {}
}
Unfortunately, this method doesn't allow me to directly reference types like Basic.Req or Basic.Res.