Skip to content
Snippets Groups Projects
Commit 9f0e5b76 authored by Francé Wilke's avatar Francé Wilke
Browse files

Refactor reflection functions

parent 10de62da
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,14 @@ import (
"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/logs"
)
func SetPointerTime(field reflect.Value, value *time.Time) {
func SetTimeField(field reflect.Value, value time.Time) {
if field.Kind() == reflect.Ptr {
// Pointer to accountID
setPointerTime(field, &value)
}
}
func setPointerTime(field reflect.Value, value *time.Time) {
if !isFieldValid(field, false) {
return // Field doesn't exist
}
......@@ -19,7 +26,16 @@ func SetPointerTime(field reflect.Value, value *time.Time) {
field.Set(reflect.ValueOf(value))
}
func SetInt64(field reflect.Value, value int64) {
func SetInt64Field(field reflect.Value, value int64) {
if field.Kind() == reflect.Ptr {
// Pointer to accountID
setPointerInt64(field, &value)
} else {
setInt64(field, value)
}
}
func setInt64(field reflect.Value, value int64) {
if !isFieldValid(field, false) {
return // Field doesn't exist
}
......@@ -34,7 +50,7 @@ func SetInt64(field reflect.Value, value int64) {
field.SetInt(value)
}
func SetPointerInt64(field reflect.Value, value *int64) {
func setPointerInt64(field reflect.Value, value *int64) {
if !isFieldValid(field, false) {
return // Field doesn't exist
}
......@@ -47,7 +63,16 @@ func SetPointerInt64(field reflect.Value, value *int64) {
field.Set(reflect.ValueOf(value))
}
func SetString(field reflect.Value, value string) {
func SetStringField(field reflect.Value, value string) {
if field.Kind() == reflect.Ptr {
// Pointer to accountID
setPointerString(field, &value)
} else {
setString(field, value)
}
}
func setString(field reflect.Value, value string) {
if !isFieldValid(field, false) {
return // Field doesn't exist
}
......@@ -57,6 +82,16 @@ func SetString(field reflect.Value, value string) {
field.SetString(value)
}
func setPointerString(field reflect.Value, value *string) {
if !isFieldValid(field, false) {
return // Field doesn't exist
}
if field.Kind() != reflect.Ptr {
return
}
field.Set(reflect.ValueOf(value))
}
func GetStringValue(field reflect.Value) string {
if !isFieldValid(field, true) {
return ""
......@@ -89,13 +124,3 @@ func isFieldValid(field reflect.Value, readonly bool) bool {
return field.IsValid() && field.CanSet()
}
func SetPointerString(field reflect.Value, value *string) {
if !isFieldValid(field, false) {
return // Field doesn't exist
}
if field.Kind() != reflect.Ptr {
return
}
field.Set(reflect.ValueOf(value))
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment