Show HN: Kanna – Go generators for DI, queries, internationalization and more

mickamy1 pts0 comments

I kept writing constructor wiring up, domain types and API types conversions, test fixtures, DB row scans, bra-bra-brah by my hands. I know that libraries those use reflections may help, but they fails on runtime and we cannot see what is happening without reading code. So I decided to create a project in oposite hand. Generate code and put it in our repository. The code is ordinary Go code, so that we can review, watch diffs and also debug it.For instance, when we have the following code,```func NewDB() DB { return DB{} } func NewUser(db DB) User { return User{db: db} }type Container struct { User User `di: ` }```it generates...```func NewContainer() *Container { db := NewDB() user := NewUser(db) return Container{User: user} }```No providers, just scan packages and find them.There are 5 generators.1. DI2. Struct to struct mapping (for protubf and so on)3. Test fixtures (from model to them)4. SQL queries (like an sqlc but without SQL and more like GORM)5. Type safe i18nAll we need is just a struct and tags.Project is just started and just hit v0.0.1. Any feedbacks are very welcome.

user code struct func return container

Related Articles