/
types.go
62 lines (51 loc) · 1.06 KB
/
types.go
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package goplay
import (
"errors"
"time"
)
// Snippet represents shared snippet
type Snippet struct {
FileName string
Contents string
}
// FmtResponse is the response returned from
// upstream play.golang.org/fmt request
type FmtResponse struct {
Body string
Error string
}
// HasError returns error if any occurred
func (r *FmtResponse) HasError() error {
if r.Error == "" {
return nil
}
return CompileFailedError{msg: r.Error}
}
// CompileEvent represents individual
// event record in CompileResponse
type CompileEvent struct {
Message string
Kind string
Delay time.Duration
}
// CompileResponse is the response returned from
// upstream play.golang.org/compile request
type CompileResponse struct {
Body *string
Events []*CompileEvent
Errors string
}
// GetBody returns response body
func (cr CompileResponse) GetBody() string {
if cr.Body == nil {
return ""
}
return *cr.Body
}
// HasError returns error if any occurred
func (cr *CompileResponse) HasError() error {
if cr.Errors == "" {
return nil
}
return errors.New(cr.Errors)
}