Closed asmyasnikov closed 3 years ago
Fine for me. Could you also add a test?
Ready)
Hm, I disagree with this one. Stringer is more for defining descriptive strings, TSName()
isn't for descriptive strings, it's specifically to get typescript enum keys. If somebody wants to use the .String()
(s)he can easily just
func (x ...) TSName() { return x.String() }
...without any change in the library.
Hm, I disagree with your disagreement Your idea cannot possible if need to typescriptify external struct, which not belong developer. But external structs can .String() often
Well, relying on a String()
method from an external library sounds even worse to me.
Anyway, note that you don't have to use .TSName()
, you can also define the struct names with:
var AllWeekdays = []struct {
Value Weekday
TSName string
}{
{Sunday, "SUNDAY"},
{Monday, "MONDAY"},
{Tuesday, "TUESDAY"},
{Wednesday, "WEDNESDAY"},
{Thursday, "THURSDAY"},
{Friday, "FRIDAY"},
{Saturday, "SATURDAY"},
}
For typescript codegen need first go-codegen for multiple enums It cannot make usability typescriptify-golang-structs for typescriptify golang structs For example, I want to typescriptify package https://github.com/asmyasnikov/go-mavlink/tree/master/mavlink/dialects/ardupilotmega But it cannot possible because for example https://github.com/asmyasnikov/go-mavlink/blob/master/mavlink/dialects/ardupilotmega/enums.go contains 14000+ lines Or https://github.com/asmyasnikov/go-mavlink/blob/master/mavlink/dialects/ardupilotmega/classes.go contains 16000+ lines By hand write mappings? It is not comfortably As you wish...
PR contains: