5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-08 22:01:29 +08:00
wails/v3/internal/generator/testcases/complex_json/main.go
Fabio Massaioli 9988b7eca8
[v3] Binding generator tests for Go 1.24 features (#4068)
* Enable go1.24 tests

This reverts commit e38684e7885c9c7b5ad3f704ad500c39bbce7715.

* Testdata for go1.24

This reverts commit 7ed397dc452f420551dfdd05dfe0c6a7646b3ba4.

* Require go 1.24

* Update changelog

* Add test for omitzero

---------

Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
2025-02-28 07:21:51 +11:00

125 lines
2.8 KiB
Go

package main
import (
_ "embed"
"log"
"github.com/wailsapp/wails/v3/pkg/application"
)
// Title is a title
type Title string
const (
// Mister is a title
Mister Title = "Mr"
Miss Title = "Miss"
Ms Title = "Ms"
Mrs Title = "Mrs"
Dr Title = "Dr"
)
// GreetService is great
type GreetService struct{}
type Embedded1 struct {
// Friends should be shadowed in Person by a field of lesser depth
Friends int
// Vanish should be omitted from Person because there is another field with same depth and no tag
Vanish float32
// StillThere should be shadowed in Person by other field with same depth and a json tag
StillThere string
// embedded4 should effectively appear as an embedded field
embedded4
// unexported should be invisible
unexported bool
}
type Embedded2 struct {
// Vanish should be omitted from Person because there is another field with same depth and no tag
Vanish bool
// StillThereButRenamed should shadow in Person the other field with same depth and no json tag
StillThereButRenamed *Embedded3 `json:"StillThere"`
}
type Embedded3 string
// Person represents a person
type Person struct {
// Titles is optional in JSON
Titles []Title `json:",omitzero"`
// Names has a
// multiline comment
Names []string
// Partner has a custom and complex JSON key
Partner *Person `json:"the person's partner ❤️"`
Friends []*Person
Embedded1
Embedded2
// UselessMap is invisible to JSON
UselessMap map[int]bool `json:"-"`
// StrangeNumber maps to "-"
StrangeNumber float32 `json:"-,"`
// Embedded3 should appear with key "Embedded3"
Embedded3
// StrangerNumber is serialized as a string
StrangerNumber int `json:",string"`
// StrangestString is optional and serialized as a JSON string
StrangestString string `json:",omitempty,string"`
// StringStrangest is serialized as a JSON string and optional
StringStrangest string `json:",string,omitempty"`
// unexportedToo should be invisible even with a json tag
unexportedToo bool `json:"Unexported"`
// embedded4 should be optional and appear with key "emb4"
embedded4 `json:"emb4,omitempty"`
}
type embedded4 struct {
// NamingThingsIsHard is a law of programming
NamingThingsIsHard bool `json:",string"`
// Friends should not be shadowed in Person as embedded4 is not embedded
// from encoding/json's point of view;
// however, it should be shadowed in Embedded1
Friends bool
// Embedded string should be invisible because it's unexported
string
}
// Greet does XYZ
func (*GreetService) Greet(person Person, emb Embedded1) string {
return ""
}
func main() {
app := application.New(application.Options{
Services: []application.Service{
application.NewService(&GreetService{}),
},
})
app.NewWebviewWindow()
err := app.Run()
if err != nil {
log.Fatal(err)
}
}