DEV Community

Caspel26
Caspel26

Posted on

goninja: code-first CRUD generation for Go, no reflection

Been building goninja, a Go framework that generates CRUD REST APIs from annotated structs — routing, validation, OpenAPI, the rest.

It's the Go counterpart to a Python project I already maintain, django-ninja-aio-crud — same idea, define the model once and get the API. Difference here: no runtime reflection, it generates real Go code that lives in your repo, readable like anything you'd write by hand.

hand.

type Book struct {
    ID       string  `gorm:"primaryKey" goninja:"list,retrieve"`
    Title    string  `goninja:"list,retrieve,create,update" validate:"required"`
    AuthorID string  `goninja:"list,retrieve,create,update,filter"`
    Price    float64 `goninja:"list,retrieve,create,update,filter" validate:"min=0"`
}
Enter fullscreen mode Exit fullscreen mode
$ goninja generate -models-import myapp/models
Enter fullscreen mode Exit fullscreen mode

Pre-alpha, API still moving. Feedback welcome: docs github

Top comments (0)