mirror of
https://github.com/rancher/steve.git
synced 2025-09-06 18:01:04 +00:00
[v0.4] Move lasso SQL cache in Steve (#473)
* Copy pkg/cache/sql from lasso to pkg/sqlcache * Rename import from github.com/rancher/lasso/pkg/cache/sql to github.com/rancher/steve/pkg/sqlcache * go mod tidy * Fix lint errors * Remove lasso SQL cache mentions * Fix more CI lint errors * fix goimports Signed-off-by: Silvio Moioli <silvio@moioli.net> * Fix imports * Fix more linting errors --------- Signed-off-by: Silvio Moioli <silvio@moioli.net> Co-authored-by: Silvio Moioli <silvio@moioli.net>
This commit is contained in:
22
pkg/sqlcache/informer/shared_informer_hack.go
Normal file
22
pkg/sqlcache/informer/shared_informer_hack.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package informer
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// UnsafeSet replaces the passed object's field value with the passed value.
|
||||
func UnsafeSet(object any, field string, value any) {
|
||||
rs := reflect.ValueOf(object).Elem()
|
||||
rf := rs.FieldByName(field)
|
||||
wrf := reflect.NewAt(rf.Type(), unsafe.Pointer(rf.UnsafeAddr())).Elem()
|
||||
wrf.Set(reflect.ValueOf(value))
|
||||
}
|
||||
|
||||
// UnsafeGet returns the value of the passed object's for the passed field.
|
||||
func UnsafeGet(object any, field string) any {
|
||||
rs := reflect.ValueOf(object).Elem()
|
||||
rf := rs.FieldByName(field)
|
||||
wrf := reflect.NewAt(rf.Type(), unsafe.Pointer(rf.UnsafeAddr())).Elem()
|
||||
return wrf.Interface()
|
||||
}
|
Reference in New Issue
Block a user