-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors05.go
More file actions
38 lines (29 loc) · 1.02 KB
/
errors05.go
File metadata and controls
38 lines (29 loc) · 1.02 KB
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
/* Alta3 Research | RZFeeser
Errors - Throwing out results with _ */
package main
import (
"errors"
"fmt"
)
func obiwan(name string) (string, error) {
if name == "" {
return "", errors.New("no name provided") // best practice all lower case
}
return (name + ", now that is a name I haven't heard in a long time."), nil
}
func main() {
var name string // define a string variable (for tracking user name)
fmt.Print("What was the name? (Just press enter)")
fmt.Scanf("%s", &name) // %s - string, and a pointer to "name"
// (otherwise we'll make a copy of name
// and change the copy)
// run the obiwan function
// use of the "_" means "throw out these results"
_, err := obiwan(name)
// without capturing the results of obiwan()
// all we can do is error check
if err != nil {
fmt.Println("Could not run the obiwan function:", err)
return
}
}