add UsersSelfSettingsGET and POST
This commit is contained in:
32
common/update.go
Normal file
32
common/update.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// UpdateQuery is simply an SQL update query,
|
||||
// that can be built upon passed parameters.
|
||||
type UpdateQuery struct {
|
||||
fields []string
|
||||
Parameters []interface{}
|
||||
}
|
||||
|
||||
// Add adds a new field with correspective value to UpdateQuery
|
||||
func (u *UpdateQuery) Add(field string, value interface{}) *UpdateQuery {
|
||||
val := reflect.ValueOf(value)
|
||||
if val.Kind() == reflect.Ptr && val.IsNil() {
|
||||
return u
|
||||
}
|
||||
if s, ok := value.(string); ok && s == "" {
|
||||
return u
|
||||
}
|
||||
u.fields = append(u.fields, field+" = ?")
|
||||
u.Parameters = append(u.Parameters, value)
|
||||
return u
|
||||
}
|
||||
|
||||
// Fields retrieves the fields joined by a comma.
|
||||
func (u *UpdateQuery) Fields() string {
|
||||
return strings.Join(u.fields, ", ")
|
||||
}
|
Reference in New Issue
Block a user