2016-08-16 3 views
-1

이 Go 프로그램을 실행하는 동안 다음 오류가 발생합니다. 내가 무엇을 놓치고 있는지 확실하지 않다. "누락 된 복합 리터럴 형식"오류

Go Playground

package main 

import (
    "fmt" 
) 

type LI struct { 
    Id int `json:"id"` 
} 

type TP struct { 
    Name string `json:"name"` 
    Value string `json:"value"` 
} 

type LTI struct { 
    Leads []LI `json:"leads"` 
    Tokens []TP `json:"tokens,omitempty"` 
} 

type RCR struct { 
    Input LTI `json:"input"` 
} 

func main() { 
    fmt.Println("Hello, playground") 
    leadIdInput := LI{Id: 55213} 
    leadTokensInput := LTI{{[]LI{leadIdInput}, nil}} 
    rCR := RCR{Input: leadTokensInput} 
    fmt.Println("rCR is '%+v'", rCR.Input.Leads[0]) 
} 

.\m.go:28: missing type in composite literal 
.\m.go:28: too few values in struct initializer 

이 도와주세요.

답변

2

사용

LTI{Leads: []LI{leadIdInput}} 

fmt.Printf("rCR is '%+v' \n", rCR.Input.Leads[0]) 

The Go Playground에보십시오 :

package main 

import (
    "fmt" 
) 

type LI struct { 
    Id int `json:"id"` 
} 

type TP struct { 
    Name string `json:"name"` 
    Value string `json:"value"` 
} 

type LTI struct { 
    Leads []LI `json:"leads"` 
    Tokens []TP `json:"tokens,omitempty"` 
} 

type RCR struct { 
    Input LTI `json:"input"` 
} 

func main() { 
    fmt.Println("Hello, playground") 
    leadIdInput := LI{Id: 55213} 
    leadTokensInput := LTI{Leads: []LI{leadIdInput}} 
    rCR := RCR{Input: leadTokensInput} 
    fmt.Printf("rCR is '%+v' \n", rCR.Input.Leads[0]) 
} 

출력 :

Hello, playground 
rCR is '{Id:55213}' 
+0

@skm이게 도움이되기를 바랍니다. –