Skip to content

NeverTeaser/golf

Repository files navigation

GOLF (WIP)

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

usage

define model

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

implement GolfQuery interface

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 request url

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)
}

About

go light filter

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages