GOLF(Go Light Filter), golf dependents Gorm . golf can help you build model query as fast as,build model query like Django Rest Framework.
type testModel struct {
ID int `json:"id"`
UserID int `json:"user_id"`
Username string `json:"username"`
}
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},
}
}
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
golfQ := golf.NewGolf(globalDB)
var tests testModel
if err := golfQ.Build(&testModel{}, Request.URL.Query()).Find(&tests).Error; err != nil {
log.Println("find failed", err)
}