forked from ardanlabs/gotraining
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example1.go
42 lines (33 loc) · 854 Bytes
/
example1.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
// All material is licensed under the Apache License Version 2.0, January 2004
// http://www.apache.org/licenses/LICENSE-2.0
// Sample program to show how the default error type is implemented.
package main
import "fmt"
// http://golang.org/pkg/builtin/#error
type error interface {
Error() string
}
// http://golang.org/src/pkg/errors/errors.go
type errorString struct {
s string
}
// http://golang.org/src/pkg/errors/errors.go
func (e *errorString) Error() string {
return e.s
}
// http://golang.org/src/pkg/errors/errors.go
// New returns an error that formats as the given text.
func New(text string) error {
return &errorString{text}
}
func main() {
if err := webCall(); err != nil {
fmt.Println(err)
return
}
fmt.Println("Life is good")
}
// webCall performs a web operation.
func webCall() error {
return New("Bad Request")
}