src-d / proteus

Generate .proto files from Go source code.
https://blog.sourced.tech/post/proteus/
MIT License
735 stars 70 forks source link

Example of kallax and Proteus used together ? #104

Closed ghost closed 6 years ago

ghost commented 6 years ago

Since both projects use golang structs as the source I presume that kallax and Proteus are designed to be used together ?

dennwc commented 6 years ago

We haven't tested an interop with other packages like kallax, but it should work reasonably well.

For example, from kallax docs, you need to embed a kallax.Model into your type:

type User struct {
        kallax.Model         `table:"users" pk:"id"`
        ID       kallax.ULID
        Username string
        Email    string
        Password string
}

This will probably cause proteus to generate an undesired model field in the protobuf definition.

But you can fix it by defining two separate types:

//proteus:generate
type User struct {
        ID       uint64
        Username string
        Email    string
        Password string
}

type DBUser struct{
        kallax.Model `table:"users" pk:"id"`
        User  
}

And convert to the DB version of the struct when passing it to kallax: DBUser{User:u}.

Hope this answers your question.

ghost commented 6 years ago

Thanks. It makes sense.

Will try it out.