-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (37 loc) · 900 Bytes
/
main.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
package main
import (
"flag"
"fmt"
)
//error messages
//I have not decided to use logging packages for simplicity purposes
const (
NotThreeSidesErrorMsg = `3 sides are not provided as input`
ParsingErrorMsg = `There is a parsing error of the value`
)
const (
SuccessOutput = "Current triangle is %s\n"
)
func main() {
// prepare to parse arguments
flag.Usage = usage
verboseGoErr := flag.Bool("v", false, "-v parameter to verbose low level error messages")
flag.Parse()
args := flag.Args()
// if there are no three values in the input
if len(args) != 3 {
exitWithError(NotThreeSidesErrorMsg)
}
sides, err := parseArgs(args)
if err != nil {
if *verboseGoErr {
printErr(err.Error())
}
exitWithError(ParsingErrorMsg)
}
triangleType, err := CategorizeTriangle(sides)
if err != nil {
exitWithError(err.Error())
}
fmt.Printf(SuccessOutput, triangleType)
}