Questions tagged [reflect]
123 questions
2
votes
1 answer
Eslint not recognizing Reflect
I'm using Reflect in my code. Problem is Eslint thinks its an undeclared variable. I'm getting this error:
eslint --config ./.eslintrc.json src
30:25 error 'Reflect' is not defined no-undef
32:9 error 'Reflect' is not defined no-undef
39:21 …

Robert Biggs
- 333
- 2
- 8
1
vote
0 answers
How to get a single struct with a struct array in reflect
type Foo struct {
Bar interface{}
Nothing string
}
type A struct {
...
}
type B struct {
...
}
var car Foo
In the program, car.Bar maybe []A or []B.
I don't know what is real 'Foo' before the program running, when I use…

wan9xy
- 11
- 1
1
vote
1 answer
GO: how can i use go reflect to set the value of pointer of struct
package main
import (
"fmt"
"reflect"
)
type Config struct {
App *AppConfig
}
type AppConfig struct {
Name string
}
func (a *AppConfig) Parse() {
a.Name = "111"
}
var (
config = &Config{
App: &AppConfig{},
…

tyloafer
- 123
- 7
1
vote
0 answers
How to assign a value to another of the same type when both are passed as interface{}?
In other words - how to write the body of the function assignInterfaceTo, so that the test passes?
type testreq struct {
V int32
}
func assignInterfaceTo(x, y interface{}) {}
func TestAssignInterfaceTo(t *testing.T) {
x := &testreq{V: 1}
…

xakepp35
- 2,878
- 7
- 26
- 54
1
vote
0 answers
What are the prerequisites of sqlalchemy reflection?
I recently migrated the project and databases to another server. Both servers are ubuntu 20.04.
About the new database(MySql), I created the databse first and then loads the dumped file from the old databse. So basically the databses are the…

sean k
- 11
- 2
1
vote
1 answer
Is there a way to reflect all variables of one package in go?
I defined some global variables of error code in one packages.Their types are user-defined structs in a package exception. (Go does not support const of structs so I use var)
var (
ErrorCodeSuccess = Error{Code: 0, ErrDetail: "success"} //…

JaskeyLam
- 15,405
- 21
- 114
- 149
1
vote
1 answer
golang reflect cannot recognize tag from map members
I want to extract struct's map members' tag with reflect, while I found if retrieve member's value from MapIndex, the type of it will be recognized as "*interface{}" and hence all type information are lost, no mention reflect can extract detail…

Mento Chan
- 21
- 2
1
vote
0 answers
How do I set a Field to null using reflection in java?
This might seem like a stupid question at first, just do field.set(obj, null). But if the field is not an object, but a primitive, this will return an error. What I want is that it "resets" the value, no matter if it is an object, or a primitive…

weird guy
- 157
- 1
- 9
1
vote
1 answer
Determine with reflect if struct field is incomplete Cgo type
I have some generic code that uses reflection to handle struct fields. These fields may or may not include C types, referenced through Cgo.
One problem I encountered was that those aforementioned C types may be "incomplete structs", for instance:…

robbieperry22
- 1,753
- 1
- 18
- 49
1
vote
1 answer
how to using reflect to create parametric entity
package main
import (
"fmt"
"reflect"
)
type Aservice struct {
}
type Adata struct {
msg string
}
type Bdata struct {
more string
}
var amap map[string]interface{} = make(map[string]interface{}, 1024)
func (aser *Aservice)…

AM031447
- 475
- 1
- 8
- 21
1
vote
0 answers
Go Reflection - Dynamic Type with Methods
Using Go's reflect package, you can create dynamic struct types using reflect.StructOf():
typ := reflect.StructOf([]reflect.StructField{
{
Name: "Height",
Type: reflect.TypeOf(float64(0)),
Tag: …

Jordan
- 3,998
- 9
- 45
- 81
1
vote
1 answer
reflect.DeepEqual() is returning false but slices are same
I am comparing two slices, both of type []int. One is coming in to API in the form of json and parsed as go struct. In the struct, it is intialized as empty []int{}. Second is saved in the database (MongoDb) and is fetched and mapped to same struct…

Amandeep kaur
- 985
- 3
- 15
- 35
1
vote
1 answer
Get value of pointer of a struct field using reflect
package main
import (
"fmt"
"reflect"
)
type PetDetails struct {
Name *string
}
type Student struct {
Fname string
Lname string
City string
Mobile *int
Pet *PetDetails
}
func main() {
i := 7777777777
…

nanakondor
- 615
- 11
- 25
1
vote
1 answer
How to realistically reflect a 3d sphere in Unity with C#
I've been trying to realistically reflect a 3d sphere on the walls of a box for a while now in Unity. For some reason, the reflection is generally correct, but when the ball hits a wall in certain directions, the reflection is incorrect.
To…

BugDoctor1
- 13
- 4
1
vote
1 answer
Reflection struct field.Set with a Flag pointer value
I have a bunch of flags parsed, and I'm then trying to assign those values to fields in a struct, but I'm struggling to get a parsed flag value set into the struct because I can't type assert it or cast it.
Here is a snippet of the code I have. It's…

Integralist
- 5,899
- 5
- 25
- 42