[v3] MUCH Improved parser for bound structs

This commit is contained in:
Lea Anthony
2023-02-19 20:59:03 +11:00
parent 93aa8345dc
commit 95bb15eef4
7 changed files with 450 additions and 341 deletions
+1 -5
View File
@@ -4,6 +4,7 @@ go 1.19
require ( require (
github.com/go-task/task/v3 v3.20.0 github.com/go-task/task/v3 v3.20.0
github.com/google/go-cmp v0.5.9
github.com/jackmordaunt/icns/v2 v2.2.1 github.com/jackmordaunt/icns/v2 v2.2.1
github.com/json-iterator/go v1.1.12 github.com/json-iterator/go v1.1.12
github.com/leaanthony/clir v1.6.0 github.com/leaanthony/clir v1.6.0
@@ -12,17 +13,14 @@ require (
github.com/matryer/is v1.4.0 github.com/matryer/is v1.4.0
github.com/pterm/pterm v0.12.51 github.com/pterm/pterm v0.12.51
github.com/samber/lo v1.37.0 github.com/samber/lo v1.37.0
github.com/stretchr/testify v1.8.1
github.com/tc-hib/winres v0.1.6 github.com/tc-hib/winres v0.1.6
github.com/wailsapp/wails/v2 v2.3.2-0.20230117193915-45c3a501d9e6 github.com/wailsapp/wails/v2 v2.3.2-0.20230117193915-45c3a501d9e6
golang.org/x/tools v0.1.12
) )
require ( require (
atomicgo.dev/cursor v0.1.1 // indirect atomicgo.dev/cursor v0.1.1 // indirect
atomicgo.dev/keyboard v0.2.8 // indirect atomicgo.dev/keyboard v0.2.8 // indirect
github.com/containerd/console v1.0.3 // indirect github.com/containerd/console v1.0.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.13.0 // indirect github.com/fatih/color v1.13.0 // indirect
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/gookit/color v1.5.2 // indirect github.com/gookit/color v1.5.2 // indirect
@@ -39,7 +37,6 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/radovskyb/watcher v1.0.7 // indirect github.com/radovskyb/watcher v1.0.7 // indirect
github.com/rivo/uniseg v0.2.0 // indirect github.com/rivo/uniseg v0.2.0 // indirect
github.com/sajari/fuzzy v1.0.0 // indirect github.com/sajari/fuzzy v1.0.0 // indirect
@@ -47,7 +44,6 @@ require (
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
golang.org/x/exp v0.0.0-20220930202632-ec3f01382ef9 // indirect golang.org/x/exp v0.0.0-20220930202632-ec3f01382ef9 // indirect
golang.org/x/image v0.0.0-20201208152932-35266b937fa6 // indirect golang.org/x/image v0.0.0-20201208152932-35266b937fa6 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/sync v0.1.0 // indirect golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.3.0 // indirect golang.org/x/sys v0.3.0 // indirect
+1 -6
View File
@@ -26,6 +26,7 @@ github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg78
github.com/go-task/task/v3 v3.20.0 h1:pTavuhP+AiEpKLzh5I6Lja9Ux7ypYO5QMsEPTbhYEDc= github.com/go-task/task/v3 v3.20.0 h1:pTavuhP+AiEpKLzh5I6Lja9Ux7ypYO5QMsEPTbhYEDc=
github.com/go-task/task/v3 v3.20.0/go.mod h1:y7rWakbLR5gFElGgo6rA2dyr6vU/zNIDVfn3S4Of6OI= github.com/go-task/task/v3 v3.20.0/go.mod h1:y7rWakbLR5gFElGgo6rA2dyr6vU/zNIDVfn3S4Of6OI=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ= github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ=
github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl7wAo= github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl7wAo=
@@ -113,7 +114,6 @@ github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
@@ -122,7 +122,6 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/tc-hib/winres v0.1.6 h1:qgsYHze+BxQPEYilxIz/KCQGaClvI2+yLBAZs+3+0B8= github.com/tc-hib/winres v0.1.6 h1:qgsYHze+BxQPEYilxIz/KCQGaClvI2+yLBAZs+3+0B8=
github.com/tc-hib/winres v0.1.6/go.mod h1:pe6dOR40VOrGz8PkzreVKNvEKnlE8t4yR8A8naL+t7A= github.com/tc-hib/winres v0.1.6/go.mod h1:pe6dOR40VOrGz8PkzreVKNvEKnlE8t4yR8A8naL+t7A=
github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs= github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs=
@@ -136,8 +135,6 @@ golang.org/x/exp v0.0.0-20220930202632-ec3f01382ef9/go.mod h1:cyybsKvd6eL0RnXn6p
golang.org/x/image v0.0.0-20200430140353-33d19683fad8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.0.0-20200430140353-33d19683fad8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20201208152932-35266b937fa6 h1:nfeHNc1nAqecKCy2FCy4HY+soOOe5sDLJ/gZLbx6GYI= golang.org/x/image v0.0.0-20201208152932-35266b937fa6 h1:nfeHNc1nAqecKCy2FCy4HY+soOOe5sDLJ/gZLbx6GYI=
golang.org/x/image v0.0.0-20201208152932-35266b937fa6/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.0.0-20201208152932-35266b937fa6/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20210505024714-0287a6fb4125/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210505024714-0287a6fb4125/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0= golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0=
@@ -172,8 +169,6 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg= golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
File diff suppressed because it is too large Load Diff
+198 -43
View File
@@ -3,60 +3,215 @@ package parser
import ( import (
"testing" "testing"
"github.com/samber/lo" "github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/require"
) )
func TestParseDirectory(t *testing.T) { func TestParseDirectory(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
dir string dir string
want []string wantBoundMethods map[string]map[string][]*BoundMethod
wantErr bool wantErr bool
}{ }{
{ {
name: "should find single bound service", name: "should find single bound service",
dir: "testdata/struct_literal_single", dir: "testdata/struct_literal_single",
want: []string{"main.GreetService"}, //wantModels: []string{"main.GreetService"},
wantErr: false, wantBoundMethods: map[string]map[string][]*BoundMethod{
}, "main": {
{ "GreetService": {
name: "should find multiple bound services", {
dir: "testdata/struct_literal_multiple", Name: "Greet",
want: []string{"main.GreetService", "main.OtherService"}, DocComment: "Greet someone\n",
wantErr: false, Inputs: []*Parameter{
}, {
{ Name: "name",
name: "should find multiple bound services over multiple files", Type: "string",
dir: "testdata/struct_literal_multiple_files", IsStruct: false,
want: []string{"main.GreetService", "main.OtherService"}, IsSlice: false,
wantErr: false, },
}, },
{ Outputs: []*Parameter{
name: "should find multiple bound services over multiple packages", {
dir: "testdata/struct_literal_multiple_other", Name: "",
want: []string{"main.GreetService", "services.OtherService"}, Type: "string",
IsStruct: false,
IsSlice: false,
},
},
},
{
Name: "NoInputsStringOut",
DocComment: "",
Inputs: nil,
Outputs: []*Parameter{
{
Name: "",
Type: "string",
IsStruct: false,
IsSlice: false,
},
},
},
{
Name: "StringArrayInputStringOut",
Inputs: []*Parameter{
{
Name: "in",
Type: "string",
IsSlice: true,
},
},
Outputs: []*Parameter{
{
Type: "string",
},
},
},
{
Name: "StringArrayInputStringArrayOut",
Inputs: []*Parameter{
{
Name: "in",
Type: "string",
IsSlice: true,
},
},
Outputs: []*Parameter{
{
Type: "string",
IsSlice: true,
},
},
},
{
Name: "StringArrayInputNamedOutput",
Inputs: []*Parameter{
{
Name: "in",
Type: "string",
IsSlice: true,
},
},
Outputs: []*Parameter{
{
Name: "output",
Type: "string",
IsSlice: true,
},
},
},
{
Name: "StringArrayInputNamedOutputs",
Inputs: []*Parameter{
{
Name: "in",
Type: "string",
IsSlice: true,
},
},
Outputs: []*Parameter{
{
Name: "output",
Type: "string",
IsSlice: true,
},
{
Name: "err",
Type: "error",
},
},
},
{
Name: "IntPointerInputNamedOutputs",
Inputs: []*Parameter{
{
Name: "in",
Type: "int",
IsPointer: true,
},
},
Outputs: []*Parameter{
{
Name: "output",
Type: "int",
IsPointer: true,
},
{
Name: "err",
Type: "error",
},
},
},
{
Name: "StructPointerInputErrorOutput",
Inputs: []*Parameter{
{
Name: "in",
Type: "Person",
IsStruct: true,
IsPointer: true,
},
},
Outputs: []*Parameter{
{
Type: "error",
},
},
},
{
Name: "StructPointerInputStructPointerOutput",
Inputs: []*Parameter{
{
Name: "in",
Type: "Person",
IsStruct: true,
IsPointer: true,
},
},
Outputs: []*Parameter{
{
Type: "Person",
IsPointer: true,
IsStruct: true,
},
},
},
},
},
},
wantErr: false, wantErr: false,
}, },
//{
// name: "should find multiple bound services",
// dir: "testdata/struct_literal_multiple",
// //wantModels: []string{"main.GreetService", "main.OtherService"},
// wantErr: false,
//},
//{
// name: "should find multiple bound services over multiple files",
// dir: "testdata/struct_literal_multiple_files",
// //wantModels: []string{"main.GreetService", "main.OtherService"},
// wantErr: false,
//},
//{
// name: "should find multiple bound services over multiple packages",
// dir: "testdata/struct_literal_multiple_other",
// //wantModels: []string{"main.GreetService", "services.OtherService", "main.Person"},
// wantErr: false,
//},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
Debug = true got, err := ParseProject(tt.dir)
got, err := ParseDirectory(tt.dir)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("ParseDirectory() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("ParseDirectory() error = %v, wantErr %v", err, tt.wantErr)
return return
} }
for name, pkg := range got.packages { if diff := cmp.Diff(tt.wantBoundMethods, got.BoundMethods); diff != "" {
for structName, structType := range pkg.boundStructs { t.Errorf("ParseDirectory() failed:\n" + diff)
require.NotNil(t, structType)
require.True(t, lo.Contains(tt.want, name+"."+structName))
tt.want = lo.Without(tt.want, name+"."+structName)
}
} }
require.Empty(t, tt.want)
}) })
} }
@@ -66,13 +221,13 @@ func TestParseDirectory(t *testing.T) {
// tests := []struct { // tests := []struct {
// name string // name string
// dir string // dir string
// want string // wantModels string
// wantErr bool // wantErr bool
// }{ // }{
// { // {
// name: "should find single bound service", // name: "should find single bound service",
// dir: "testdata/struct_literal_single", // dir: "testdata/struct_literal_single",
// want: `namespace main { // wantModels: `namespace main {
// class GreetService { // class GreetService {
// SomeVariable: number; // SomeVariable: number;
// } // }
@@ -83,7 +238,7 @@ func TestParseDirectory(t *testing.T) {
// { // {
// name: "should find multiple bound services", // name: "should find multiple bound services",
// dir: "testdata/struct_literal_multiple", // dir: "testdata/struct_literal_multiple",
// want: `namespace main { // wantModels: `namespace main {
// class GreetService { // class GreetService {
// SomeVariable: number; // SomeVariable: number;
// } // }
@@ -96,7 +251,7 @@ func TestParseDirectory(t *testing.T) {
// { // {
// name: "should find multiple bound services over multiple files", // name: "should find multiple bound services over multiple files",
// dir: "testdata/struct_literal_multiple_files", // dir: "testdata/struct_literal_multiple_files",
// want: `namespace main { // wantModels: `namespace main {
// class GreetService { // class GreetService {
// SomeVariable: number; // SomeVariable: number;
// } // }
@@ -109,7 +264,7 @@ func TestParseDirectory(t *testing.T) {
// { // {
// name: "should find bound services from other packages", // name: "should find bound services from other packages",
// dir: "../../examples/binding", // dir: "../../examples/binding",
// want: `namespace main { // wantModels: `namespace main {
// class localStruct { // class localStruct {
// } // }
//} //}
@@ -139,7 +294,7 @@ func TestParseDirectory(t *testing.T) {
// //
// ts, err := GenerateModels(context) // ts, err := GenerateModels(context)
// require.NoError(t, err) // require.NoError(t, err)
// require.Equal(t, tt.want, string(ts)) // require.Equal(t, tt.wantModels, string(ts))
// //
// }) // })
// } // }
@@ -12,6 +12,11 @@ import (
type GreetService struct { type GreetService struct {
SomeVariable int SomeVariable int
lowerCase string lowerCase string
target *Person
}
type Person struct {
Name string
} }
// Greet does XYZ // Greet does XYZ
@@ -19,6 +24,11 @@ func (*GreetService) Greet(name string) string {
return "Hello " + name return "Hello " + name
} }
// NewPerson creates a new person
func (*GreetService) NewPerson(name string) *Person {
return &Person{Name: name}
}
func main() { func main() {
app := application.New(application.Options{ app := application.New(application.Options{
Bind: []interface{}{ Bind: []interface{}{
@@ -7,6 +7,6 @@ type OtherService struct {
} }
// Yay does this and that // Yay does this and that
func (o *OtherService) Yay() { func (o *OtherService) Yay() []int {
return []int{0, 1, 2}
} }
@@ -3,19 +3,58 @@ package main
import ( import (
_ "embed" _ "embed"
"log" "log"
"strings"
"github.com/wailsapp/wails/v3/pkg/application" "github.com/wailsapp/wails/v3/pkg/application"
) )
type Person struct {
Name string
}
// GreetService is great
type GreetService struct { type GreetService struct {
SomeVariable int SomeVariable int
lowerCase string lowerCase string
} }
// Greet someone
func (*GreetService) Greet(name string) string { func (*GreetService) Greet(name string) string {
return "Hello " + name return "Hello " + name
} }
func (*GreetService) NoInputsStringOut() string {
return "Hello"
}
func (*GreetService) StringArrayInputStringOut(in []string) string {
return strings.Join(in, ",")
}
func (*GreetService) StringArrayInputStringArrayOut(in []string) []string {
return in
}
func (*GreetService) StringArrayInputNamedOutput(in []string) (output []string) {
return in
}
func (*GreetService) StringArrayInputNamedOutputs(in []string) (output []string, err error) {
return in, nil
}
func (*GreetService) IntPointerInputNamedOutputs(in *int) (output *int, err error) {
return in, nil
}
func (*GreetService) StructPointerInputErrorOutput(in *Person) error {
return nil
}
func (*GreetService) StructPointerInputStructPointerOutput(in *Person) *Person {
return in
}
func main() { func main() {
app := application.New(application.Options{ app := application.New(application.Options{
Bind: []interface{}{ Bind: []interface{}{