flutter-go-bridge
flutter-go-bridge copied to clipboard
type selectors not supported
trafficstars
I'm trying to implement a bridge to the go etcd client library, but I cannot do it beacause your library doesn't support type selectors, which is pretty much mandatory to use any library.
I'm trying to generate the following code, this is just a simple starting point:
package etcd
import (
"time"
clientv3 "go.etcd.io/etcd/client/v3"
)
func Connect(endpoints []string) (*clientv3.Client, error) {
cli, err := clientv3.New(clientv3.Config{
Endpoints: endpoints,
DialTimeout: 5 * time.Second,
})
if err != nil {
return nil, err
}
return cli, nil
}
And I get the following error:
2024/10/29 11:12:56 Processing
2024/10/29 11:12:56 - Func Connect
2024/10/29 11:12:56 ast contained unsupported data: type selectors not supported: clientv3.Client
If I use a dot import:
package etcd
import (
"time"
. "go.etcd.io/etcd/client/v3"
)
func Connect(endpoints []string) (*Client, error) {
cli, err := New(Config{
Endpoints: endpoints,
DialTimeout: 5 * time.Second,
})
if err != nil {
return nil, err
}
defer cli.Close()
return cli, nil
}
I get the following error:
2024/10/29 11:25:57 Processing
2024/10/29 11:25:57 - Func Connect
2024/10/29 11:25:57 ast contained unexpected data: unexpected type *parser.ArrayType
Which is fine, arrays may not be supported, I can work around that by just joining the strings with a comma:
package etcd
import (
"strings"
"time"
. "go.etcd.io/etcd/client/v3"
)
func Connect(endpoints string) (*Client, error) {
cli, err := New(Config{
Endpoints: strings.Split(endpoints, ","),
DialTimeout: 5 * time.Second,
})
if err != nil {
return nil, err
}
defer cli.Close()
return cli, nil
}
But now it doesn't know what the type even is, complaining that it doesn't exist (it does.):
2024/10/29 11:26:18 Processing
2024/10/29 11:26:18 - Func Connect
2024/10/29 11:26:18 ast contained unexpected data: type is not defined: Client
How should I resolve this? Is there even a way to do this? What's even the point of this package if you can't write wrappers for libraries?