Skip to main content
1 vote
0 answers
32 views

compare and copy one instance of the same go struct to another updated instance

I have a nested go struct, and i have two instances of it. The original and the new one. I need a way to compare these two instances and copy all the fields (if they are filled and skip the empty one'...
Mohammed Saaduddin Ansari's user avatar
0 votes
1 answer
104 views

Determining the type of an interface {} value returned from a function in Golang

I have a function that returns a value from an enum. The enum definition is as follows: type DataType int64 const ( INT DataType = iota FLOAT STRING BOOL CHAR VOID ERROR ...
luisepa1420's user avatar
0 votes
1 answer
40 views

How create type using reflect having pointer receivers

I've two Task struct, namely ShellTask and CmdTask. Created a TaskExecutor Interface and implemented the methods both in ShellTask and CmdTask Pointer receiver. And creating the Task Executor ...
Karthik Prasad's user avatar
2 votes
1 answer
640 views

Render table in html template where table-data are keys and values of some json data in Golang

In backend I send http request to some third party site and retrieve some json data in response. Keys in the json response are not always same, but I have some idea of what they might be. For example: ...
skylark's user avatar
  • 51
-2 votes
1 answer
126 views

Declare type dynamically in GoLang [duplicate]

I have a field struct type: { Name: "fieldA", Type: "string", } and an array of this filed type: [{ Name: "fieldA" Type: "string" }, { Name: "filedB",...
user1722361's user avatar
2 votes
0 answers
159 views

How to create a new instance of a struct that is read from file

I know this may seem like bad design (and I wish I didn't need to do this), but I need to read a struct that is generated automatically at run time and create a new instance of it. The struct that I ...
Charlie Clarke's user avatar
0 votes
0 answers
332 views

golang. reflect makefunc: how to decorate the origin func?

I'm making a tools that decorte my origin function to test my program. It can inject some specific method to oringin function. Now I'm using reflect to do that: I will define a Handle function to ...
Pkzzz's user avatar
  • 111
1 vote
0 answers
56 views

How to flatten a dynamic value in Go?

I am trying to flatten a dynamic value in Go into a slice of key value pairs. So I define a struct as : type KeyValuePair struct { key string value interface{} } For simple values like x = 10, ...
dragonfly02's user avatar
  • 3,709
1 vote
1 answer
2k views

Can I optimize this Go reflect function so it isn't as slow?

I am working on a project where I need to build out the partial updates for all of the methods that will be supported. Each partial update will require a different struct, with different fields and ...
JDev's user avatar
  • 158
0 votes
1 answer
170 views

Is there a way to set a pointer struct field to a pointer pointing to the Zero value of that pointer type using reflect?

That was a mouthful of a title, let me explain more. Assuming I have a struct of all pointers (don't know of what type) type A struct { S *string I *int } I want to write a function that takes a ...
strikerdude10's user avatar
-1 votes
1 answer
162 views

How can I reach struct member in interface type

I have to keep multi type struct in slice and seed them. I took with variadic parameter of interface type and foreach them. If I call the method of interface it works, but when I trying to reach to ...
icsarisakal's user avatar
1 vote
0 answers
35 views

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' ...
wan9xy's user avatar
  • 11
1 vote
1 answer
1k views

Get pointers to all fields of a struct dynamically using reflection

I'm trying to build a simple orm layer for golang. Which would take a struct and generate the cols [] which can then be passed to sql function rows.Scan(cols...) which takes pointers of fields in the ...
Krittam Kothari's user avatar
2 votes
1 answer
597 views

go reflect: how to dynamically create a pointer to a pointer to ...?

I would like to create a reflect.Value that represents a multiple-level nested pointer to a final value. The nesting level is not known at compile time. How can I create pointers to pointers using ...
TheDiveO's user avatar
  • 2,761
0 votes
2 answers
1k views

Append to golang slice passed as empty interface

How to append to empty interface (that has been verified to be a *[]struct)? func main() { var mySlice []myStruct // myStruct can be any struct (dynamic) decode(&mySlice, "...") } ...
kent-id's user avatar
  • 737

15 30 50 per page
1
2 3 4 5
7