Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GORM Library with sheriff package #27

Closed
sandeepchowdary7 opened this issue Oct 24, 2020 · 0 comments
Closed

Use GORM Library with sheriff package #27

sandeepchowdary7 opened this issue Oct 24, 2020 · 0 comments

Comments

@sandeepchowdary7
Copy link

I'm trying to use the Golang Sheriff package with GORM Library somehow I'm getting an empty response. Tried a couple of ways no luck. Is it possible? Any help that would be great. TIA

//STRUCT
    type Book struct {
    ID        uint `json:"id" gorm:"primary_key" groups:"not_detail,detail"`
    Realname      string `json:"real_name" groups:"not_detail,detail"`
    LanguageId int `json:"language_id" groups:"not_detail,detail"`
    Language   Language `json:"Language" groups:"detail"`
    CreatedAt time.Time `json:"created_at" groups:"not_detail,detail"`
    UpdatedAt time.Time `json:"updated_at" groups:"not_detail,detail"`
}
//CONTROLLER LOGIC
func FindBooks(c *gin.Context)  {
    db := c.MustGet("db").(*gorm.DB)
    var books []models.Book
    result := db.Find(&books)

    o := sheriff.Options{
        Groups: []string{"not_detail"},
    }

    d, err := sheriff.Marshal(&o, result)
    if err != nil {
        panic(err)
    }

    c.JSON(http.StatusOK, gin.H{"data":d})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant