B
B
bodrich2019-09-07 15:02:04
SQL
bodrich, 2019-09-07 15:02:04

How to create a slice from a structure so that it can be read into with slqx Select?

There is such a code. I need to somehow create a slice from this structure so that I can do something like sm.Select(MakeSlice(base)). Tried like this - didn't work

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav, 2019-09-08
@ghostiam

var v []Personal
db.Select(&v,...)

I don’t understand, why complicate the creation of an interface variable, and then write a normal structure into it?
If you want the structure to implement the interface, then you just need to implement the methods of the structure.
type MyInterface interface{
   MyMethod()
}

type Personals []Personal 
func (p Personals) MyMethod() {}

func get() MyInterface {
    var v Personals // equal []Personal 
    db.Select(&v,...)
    return v
}

You cannot create an array/slice of interfaces in Go.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question