mirror of
https://github.com/safing/portbase
synced 2025-09-15 09:39:50 +00:00
Finish database queries and subscriptions / Improve Accessor
This commit is contained in:
parent
8c861a1e4f
commit
9ab95b1926
17 changed files with 235 additions and 33 deletions
|
@ -86,6 +86,15 @@ func (sa *StructAccessor) Set(key string, value interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Get returns the value found by the given json key and whether it could be successfully extracted.
|
||||
func (sa *StructAccessor) Get(key string) (value interface{}, ok bool) {
|
||||
field := sa.object.FieldByName(key)
|
||||
if !field.IsValid() || !field.CanInterface() {
|
||||
return nil, false
|
||||
}
|
||||
return field.Interface(), true
|
||||
}
|
||||
|
||||
// GetString returns the string found by the given json key and whether it could be successfully extracted.
|
||||
func (sa *StructAccessor) GetString(key string) (value string, ok bool) {
|
||||
field := sa.object.FieldByName(key)
|
||||
|
@ -95,6 +104,20 @@ func (sa *StructAccessor) GetString(key string) (value string, ok bool) {
|
|||
return field.String(), true
|
||||
}
|
||||
|
||||
// GetStringArray returns the []string found by the given json key and whether it could be successfully extracted.
|
||||
func (sa *StructAccessor) GetStringArray(key string) (value []string, ok bool) {
|
||||
field := sa.object.FieldByName(key)
|
||||
if !field.IsValid() || field.Kind() != reflect.Slice || !field.CanInterface() {
|
||||
return nil, false
|
||||
}
|
||||
v := field.Interface()
|
||||
slice, ok := v.([]string)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
return slice, true
|
||||
}
|
||||
|
||||
// GetInt returns the int found by the given json key and whether it could be successfully extracted.
|
||||
func (sa *StructAccessor) GetInt(key string) (value int64, ok bool) {
|
||||
field := sa.object.FieldByName(key)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue