Open DAT4 opened 1 year ago
I'm not sure I fully understand the issue or what you're trying to do here. Maybe @hyangah knows?
The error message is not very comprehensive (I suspect the gomobile/gobind didn't stop early when it observed unsupported types so the go command instead produced this error later while compiling incompletely generated glue code).
https://pkg.go.dev/golang.org/x/mobile/cmd/gobind#hdr-Type_restrictions has the set of types gobind (gomobile bind) supports. I guess use of slice in ChatStateHandler
can be problematic, and, even though I don't know what's entity.Token
but that can be also an issue. You can verify to see what's generated by running the gobind
command directly. (golang.org/x/mobile/bind).
I figured out that interfaces that are injected into constructors exposed to Android cannot have methods receiving or returning types that are not defined inside the same package that gomobile compiles.
entity.Token
is a simple struct defined in another package
type Token struct {
AccessToken string
RefreshToken string
}
func NewToken(accessToken, refreshToken string) *Token {
return &Token{
AccessToken: accessToken,
RefreshToken: refreshToken,
}
}
I can solve the problem by defining a Token
inside the mobile
package and the map the entity.Token
internally to mobile.Token
It would be nice to have the ability to use models from external packages as arguments and return values in methods of interfaces. So that I can return the model directly from the internal/entity package instead of redefining every model in the mobile package.
├── internal
│ ├── constants.go
│ ├── entity
│ │ └── models.go
│ ├── interfaces
│ │ ├── auth.go
│ │ ├── chat.go
│ │ └── utils.go
│ └── repository
│ ├── grpc
│ │ ├── authrepo
│ │ └── chatrepo
│ └── http
│ ├── authrepo
│ └── chatrepo
├── mobile
│ ├── auth.go
│ ├── authstatehandler.go
│ ├── chat.go
│ ├── chatstatehandler.go
│ └── messagereceiver.go
I am trying to use go to make a client library that should be able to used by all the things (mobiles, wasm ...)
Each thing handles state different. So I am trying to inject "state handlers" into the application. I tried with a client version - and it works fine. But when I try with gomobile I get some errors that I don't understand.
I have got similar errors before when injection interfaces in gomobile applications - and I managed to resolve it by moving the interface definition into the same package as where it was called from. That didn't work with the new interfaces.