Re: [go-nuts] Re: get the data out of slice of structs

2017-10-26 Thread Jan Mercl
On Thu, Oct 26, 2017 at 12:25 PM Vikram Rawat wrote: > ... my problem is that there are no slice of time.Time. var foo []time.Time // is a slice of time.Time In general, []T is a slice of T. T can by any named type, local or imported or it can be a type literal, like in []struct{i int}, which i

Re: [go-nuts] Re: get the data out of slice of structs

2017-10-26 Thread Vikram Rawat
> > Thank you very much for the reply but my problem is that there are no > slice of time.Time. This is the main reason I chose to get the data this > way by creating a slice of struct. > Can you tell me what is the best way to get this sort of data in a struct of 2 slices. my code is packag

Re: [go-nuts] Re: get the data out of slice of structs

2017-10-26 Thread Jan Mercl
On Thu, Oct 26, 2017 at 11:39 AM Vikram Rawat wrote: > How do a get a slice of DState from got this is my question var a []string for _, v := range got[1:3] { a = append(a, v.DState) } -- -j -- You received this message because you are subscribed to the Google Groups "golang-nuts"

[go-nuts] Re: get the data out of slice of structs

2017-10-26 Thread Vikram Rawat
I was able to get the Data from SQL into got but when I print fmt.Println(got[1:3]) fmt.Println(got[2:3]) fmt.Println(got[1:3]) fmt.Println(got[3:3]) it produces the following result [{2017-09-07 15:25:45.346887 + + HR} {2017-09-07 15:39:44.24207 + + DL}] [{2017-09-07 15:39:

[go-nuts] Re: get the data out of slice of structs

2017-10-26 Thread jra
At this point, variable got is a slice of length 0. If you tried to access got[0], you'd get a panic at runtime for out of bounds access. You could add a State to it like this: got = append(got, State{ DLastmodified: time.Now(), DState: "test" }) and then access it with got[0]. You would probab

[go-nuts] Re: get the data out of slice of structs

2017-10-26 Thread Volker Dobler
On Thursday, 26 October 2017 08:30:29 UTC+2, Vikram Rawat wrote: > > I have created a struct > > type State struct{ > DLastmodified time.Time > DState string > } > > > > and created a slice of struct like > > > got :=[]State{} > > > Now I am unable to get the column data out of this slice. please