github api create issue返回状态422

I'm trying to create an GitHub issue through their API but it returns status 422. The code works when i try it with the hard coded values, but as soon as i try it with input from the stdin i get the following response

{ "message":"Validation Failed", "errors":[{"resource":"Label", "field":"name", "code":"missing_field" }], "documentation_url":"https://developer.github.com/v3/issues/#create-an-issue" }

Note that i would like to use marshaling since i'm doing asignments from a book i'm working on.

Thank you!

func main() {
    var issue githubissues.IssueReq
    issue = userInput()
    //Hardcoded testvalues that work
    var jsonStr = []byte(`{
            "title": "Found a bug",
            "body": "I'm having a problem with this.",
            "assignees": [
            "AssigneNR1"
            ],
            "milestone": 1,
            "labels": [
            "bug"
            ]
        }`)

    issueMars, err := json.Marshal(issue)
    if err != nil {
        fmt.Println("Marshal Error", err)
    }
    req, err := http.NewRequest("POST", url, bytes.NewBuffer(issueMars))
    req.Header.Set("X-Custom-Header", "myvalue")
    req.Header.Set("Content-Type", "application/json")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    fmt.Println("Response Status:", resp.Status)
    fmt.Println("Response Headers:", resp.Header)
    body, _ := ioutil.ReadAll(resp.Body)
    fmt.Println("Response body", string(body))
}

func userInput() githubissues.IssueReq {
    var issue githubissues.IssueReq
    reader := bufio.NewReader(os.Stdin)
    fmt.Print("Issue Title:")
    issue.Title, _ = reader.ReadString('
')
    fmt.Print("Body:")
    issue.Body, _ = reader.ReadString('
')
    fmt.Print("Assignee:")
    issue.Assignees = make([]string, 4)
    assigne, _ := reader.ReadString('
')
    issue.Assignees = append(issue.Assignees, stripSpaces(assigne))
    fmt.Print("Milestone:")
    issue.Milestone, _ = reader.ReadString('
')
    issue.Milestone = strings.TrimSuffix(issue.Milestone, "
")
    fmt.Print("Label:")
    issue.Labels = make([]string, 4)
    label, _ := reader.ReadString('
')
    issue.Labels = append(issue.Labels, stripSpaces(label))
    return issue

}

func stripSpaces(str string) string {
    return strings.Map(func(r rune) rune {
        if unicode.IsSpace(r) {
            return -1
        }
        return r
    }, str)
}

Based on the validation message:

{
  "message": "Validation Failed",
  "errors": [{
    "resource": "Label",
    "field": "name",
    "code": "missing_field"
  }],
  "documentation_url": "https://developer.github.com/v3/issues/#create-an-issue"
}

It looks to be a problem with the labels that you are attempting to attach to the issue.

Try removing this section of the create issue body:

 "labels": [
    "bug"
  ]

Or create a label with name "bug": https://developer.github.com/v3/issues/labels/#create-a-label