Skip to content

Commit

Permalink
Changed build script to make file, handled file.Close() error
Browse files Browse the repository at this point in the history
  • Loading branch information
IfeSunmola committed Apr 15, 2023
1 parent 0daf0ff commit d291f1d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 19 deletions.
30 changes: 30 additions & 0 deletions grade-tracker/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
BIN_DIR = ./builds/
BIN_NAME = grade-tracker
SRC = grade-tracker.go

all: linux-amd64 linux-arm64 windows-amd64 windows-arm64 mac-amd64 mac-arm64

linux: linux-amd64 linux-arm64

windows: windows-amd64 windows-arm64

mac: mac-amd64 mac-arm64

linux-amd64:
env GOOS=linux GOARCH=amd64 go build -o $(BIN_DIR)$(BIN_NAME)-linux-amd64 $(SRC)

linux-arm64:
env GOOS=linux GOARCH=arm64 go build -o $(BIN_DIR)$(BIN_NAME)-linux-arm64 $(SRC)

windows-amd64:
env GOOS=windows GOARCH=amd64 go build -o $(BIN_DIR)$(BIN_NAME)-win-amd64.exe $(SRC)

windows-arm64:
env GOOS=windows GOARCH=arm64 go build -o $(BIN_DIR)$(BIN_NAME)-win-arm64.exe $(SRC)

mac-amd64:
env GOOS=darwin GOARCH=amd64 go build -o $(BIN_DIR)$(BIN_NAME)-mac-amd64 $(SRC)

mac-arm64:
env GOOS=darwin GOARCH=arm64 go build -o $(BIN_DIR)$(BIN_NAME)-mac-arm64 $(SRC)

13 changes: 0 additions & 13 deletions grade-tracker/build-all.sh

This file was deleted.

17 changes: 11 additions & 6 deletions grade-tracker/tracker.go → grade-tracker/grade-tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func usage(msg string) {
fmt.Println(" ", os.Args[0], " <file_name>")
}

func check(e error) {
func checkError(e error) {
if e != nil {
fmt.Println(e)
os.Exit(1)
Expand All @@ -28,8 +28,13 @@ func main() {
}

file, err := os.Open(os.Args[1])
check(err)
defer file.Close()
checkError(err)
defer func(file *os.File) {
err := file.Close()
if err != nil {
fmt.Println(err)
}
}(file)

fmt.Println("Starting report for", os.Args[1])
fmt.Println("========================================================")
Expand Down Expand Up @@ -64,13 +69,13 @@ func main() {
name := strings.TrimSpace(fields[0])

achieved, err := strconv.ParseFloat(strings.TrimSpace(fields[1]), 32)
check(err)
checkError(err)

possible, err := strconv.ParseFloat(strings.TrimSpace(fields[2]), 32)
check(err)
checkError(err)

final, err := strconv.ParseFloat(strings.TrimSpace(fields[3]), 32)
check(err)
checkError(err)

if achieved > possible {
fmt.Println("Achieved is greater than possible for", name)
Expand Down

0 comments on commit d291f1d

Please sign in to comment.