GOLF(Go Light Filter), golf dependents Gorm
and Gin. golf can help you build model query as fast as´╝îbuild model query like
Django Rest Framework.


define model

type testModel struct {
    ID       int    `json:"id"`
    UserID   int    `json:"user_id"`
    Username string `json:"username"`

implement Golf Query

use golf must implement this interface , map key is go struct member name

func (m *testModel) Field() map[string][]golf.Filter {
    return map[string][]golf.Filter{
        "ID":       {golf.Equal},
        "UserID":   {golf.Equal, golf.Gte},
        "Username": {golf.Equal, golf.Like},

use with Gin

TODO you can read the example

// URL path /ping?eq_id=1&like_username=test
// sql log should be  SELECT * FROM "test_model" WHERE username LIKE 'test' AND id = 1 LIMIT 10


View Github