💥 Falling from starts
- Leave a Star if you were here!
go get github.com/praslar/lib@latest
notiConfig := NotificationClient.Config{}
rawData, err := ioutil.ReadFile("./conf/notification.conf")
err = json.Unmarshal(rawData, ¬iConfig)
if err != nil {
log.Println("Error when read notification config >>> remove file")
return nil
}
notiClient := NotificationClient.NewNotificationHelperFCM(notiConfig)
Sync add only changed values to object. Usually use when updating fields of record.
type UpdateUserRequest struct {
Name *string
}
type User struct {
ID string
Name string
Age int
School string
...
}
func UpdateUser(req UpdateUserRequest, id string) (res User) {
user := model.GetUser(iD)
common.Sync(req,&user)
// user will have new value of req.Name and keep others values unchange
_ = model.Update(user)
...
}
Valid struct and return error if there is any.
type User struct {
Name string `valid:"Required"`
Age int `valid:"Required"`
}
req := User{}
if err := common.CheckRequireValid(req); err != nil {
return nil, err
}
// this will return error that required Age and Name value in req object
Map value in map[string]string to struct
type variable struct {
ID string
}
vars := mux.Vars(r)
if err := common.MapStruct(vars, variable); err != nil {
return err
}