github.com/AlpineAIO/wails/v2@v2.0.0-beta.32.0.20240505041856-1047a8fa5fef/internal/binding/binding_test/binding_emptystruct_test.go (about) 1 package binding_test 2 3 type EmptyStruct struct { 4 Empty struct{} `json:"empty"` 5 } 6 7 func (s EmptyStruct) Get() EmptyStruct { 8 return s 9 } 10 11 var EmptyStructTest = BindingTest{ 12 name: "EmptyStruct", 13 structs: []interface{}{ 14 &EmptyStruct{}, 15 }, 16 exemptions: nil, 17 shouldError: false, 18 want: ` 19 export namespace binding_test { 20 export class EmptyStruct { 21 // Go type: struct {} 22 23 empty: any; 24 25 static createFrom(source: any = {}) { 26 return new EmptyStruct(source); 27 } 28 constructor(source: any = {}) { 29 if ('string' === typeof source) source = JSON.parse(source); 30 this.empty = this.convertValues(source["empty"], Object); 31 } 32 convertValues(a: any, classs: any, asMap: boolean = false): any { 33 if (!a) { 34 return a; 35 } 36 37 if (a.slice) { 38 return (a as any[]).map(elem => this.convertValues(elem, classs)); 39 } else if ("object" === typeof a) { 40 if (asMap) { 41 for (const key of Object.keys(a)) { 42 a[key] = new classs(a[key]); 43 } 44 return a; 45 } 46 return new classs(a); 47 } 48 return a; 49 } 50 } 51 } 52 `, 53 }