These are chat archives for gin-gonic/gin

30th
Jun 2017
Nikunj Shukla
@shukla2112
Jun 30 2017 08:34
Is there option not to set the defaults for the field of the struct while bindJson is called?
type SiteProduct struct {
    Site                    string     `json:"site" gorm:"index:idx_site_products_site"`
    RawCount                int        `json:"raw_count,omitempty" gorm:"index:idx_site_products_raw_count"`
    RawVariationCount       int        `json:"raw_variation_count,omitempty" gorm:"index:idx_site_products_raw_variation_count"`
    RawActiveCount          int        `json:"raw_active_count,omitempty" gorm:"index:idx_site_products_raw_active_count"`
    RawVariationActiveCount int        `json:"raw_variation_active_count,omitempty" gorm:"index:idx_site_products_raw_variation_active_count"`
    MmCount                 int        `json:"mm_count,omitempty"`
    MmVariationCount        int        `json:"mm_variation_count,omitempty"`
    MmVariationActiveCount  int        `json:"mm_variation_active_count,omitempty"`
    MmActiveCount           int        `json:"mm_active_count,omitempty"`
    OldestCreatedat         time.Time  `json:"oldest_createdat,omitempty" gorm:"index:idx_site_products_oldest_createdat"`
    OldestActiveCreatedat   time.Time  `json:"oldest_active_createdat,omitempty" gorm:"index:idx_site_products_oldest_active_createdat"`
    OldestProductActive     time.Time  `json:"oldest_product_active,omitempty" gorm:"index:idx_site_products_oldest_product_active"`
}

func SetSitesProductsHandler(appC *AppConfig) gin.HandlerFunc {
    return func(c *gin.Context) {                                                                                                                                     var SiteProductStat SiteProduct
        if err := c.BindJSON(&SiteProductStat); err != nil {
            ReturnData(http.StatusInternalServerError, err.Error(), 0, c)
            return                                                                                                                                                    }
        appC.PgSiteDataDb.Create(&SiteProductStat)
        c.JSON(http.StatusOK, gin.H{"status": 1})
    }
}
some of the details while calling the endpoints are not present and those are set to 0 or null and inserted into DB