Error: cannot use Value literal (type Value) as type []Value in field value

5,819 views
Skip to first unread message

je...@ramhorst.eu

unread,
Aug 24, 2016, 10:05:08 AM8/24/16
to golang-nuts
Hello,
I have a problem with structs:

I defined the following structs:

type Value struct {
 
Type string `json:"type"`
 
Unity string `json:"unity"`
 
Data float64 `json:"data"`
}


type
Phase struct {
 
Phase int `json:"phase"`
 
Name string `json:"name"`
 
Values []Value `json:"values"`
}


type
Dataset struct {
 
Time string `json:"time"`
 
Phases []Phase `json:"phases"`
}




type
Measurement struct {
 
Serial string `json:"serial"`
 
Time string `json:"time"`
 
Softwareversion string `json:"softwareversion"`
 
Ipaddress string `json:"ipaddress"`
 
Datasets []Dataset `json:"datasets"`
}


At compiling, I get an error (cannot use Value literal (type Value) as type []Value in field value)  at the following line
Type: "current", Unity: "A", Data: 1.879352},

   
measurement := Measurement{
     
Serial: "SmartPi12345",
     
Time: "0001-01-01T00:00:00Z",
     
Softwareversion: "1.0.1",
     
Ipaddress: "192.168.2.10",
     
Datasets: Dataset{
       
Time: "0001-01-02T00:00:00Z",
       
Phases: Phase{
         
Phase: 1, Name: "phase 1",
         
Values: Value{
           
Type: "current", Unity: "A", Data: 1.879352},
       
},
     
},
   
}


Can someone help me. I don't find an error.

Best regards Jens

Anmol Sethi

unread,
Aug 24, 2016, 10:06:20 AM8/24/16
to je...@ramhorst.eu, golang-nuts
Values is an array. So you need []Values{}
> --
> You received this message because you are subscribed to the Google Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Anmol Sethi

unread,
Aug 24, 2016, 10:06:28 AM8/24/16
to je...@ramhorst.eu, golang-nuts
slice*
> On Aug 24, 2016, at 10:00 AM, je...@ramhorst.eu wrote:
>

Anmol Sethi

unread,
Aug 24, 2016, 10:13:37 AM8/24/16
to je...@ramhorst.eu, golang-nuts
So together it would look like []Values{Value{}}

> On Aug 24, 2016, at 10:00 AM, je...@ramhorst.eu wrote:
>
Reply all
Reply to author
Forward
0 new messages