Uh oh!
There was an error while loading. Please reload this page.
forked from github-release/github-release
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
Latest commit
42 lines (34 loc) · 891 Bytes
/
Copy patherror.go
File metadata and controls
42 lines (34 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"encoding/json"
"fmt"
"io"
"strings"
)
/* usually when something goes wrong, github sends something like this back */
typeMessagestruct {
Messagestring`json:"message"`
Errors []GithubError`json:"errors"`
}
typeGithubErrorstruct {
Resourcestring`json:"resource"`
Codestring`json:"code"`
Fieldstring`json:"field"`
}
/* transforms a stream into a Message, if it's valid json */
funcToMessage(r io.Reader) (*Message, error) {
varmsgMessage
iferr:=json.NewDecoder(r).Decode(&msg); err!=nil {
returnnil, err
}
return&msg, nil
}
func (m*Message) String() string {
str:=fmt.Sprintf("msg: %v, errors: ", m.Message)
errstr:=make([]string, len(m.Errors))
foridx, err:=rangem.Errors {
errstr[idx] =fmt.Sprintf("[field: %v, code: %v]",
err.Field, err.Code)
}
returnstr+strings.Join(errstr, ", ")
}