-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chapter 09 initialized
- Loading branch information
Showing
8 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.DEFAULT_GOAL := run | ||
|
||
fmt: | ||
go fmt ./... | ||
.PHONY: fmt | ||
|
||
lint: fmt | ||
golint ./... | ||
.PHONY: lint | ||
|
||
vet: fmt | ||
go vet ./... | ||
.PHONY: vet | ||
|
||
build: vet | ||
go build panic_recover_example.go | ||
.PHONY: build | ||
|
||
run: vet | ||
go run panic_recover_example.go | ||
.PHONY: run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
) | ||
|
||
func fileChecker(name string) error { | ||
f, err := os.Open(name) | ||
if err != nil { | ||
return fmt.Errorf("in fileChecker: %w", err) | ||
} | ||
f.Close() | ||
return nil | ||
} | ||
|
||
func bckp_main() { | ||
err := fileChecker("not_here.txt") | ||
if err != nil { | ||
if errors.Is(err, os.ErrNotExist) { | ||
fmt.Println("That file doesn't exist") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module main | ||
|
||
go 1.20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package main | ||
|
||
import "os" | ||
|
||
func doPanic(msg string) { | ||
panic(msg) | ||
} | ||
|
||
func bis_bckp_main() { | ||
doPanic(os.Args[0]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package main | ||
|
||
func div60(i int) { | ||
defer func() { | ||
if v := recover(); v != nil { | ||
println("recovered:", v) | ||
} | ||
}() | ||
println(60 / i) | ||
} | ||
|
||
func main() { | ||
for _, val := range []int{1, 2, 0, 3} { | ||
div60(val) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# 09_modules_packages_imports | ||
|
||
### Intro | ||
* repositories | ||
* modules | ||
* packages | ||
* 1 or more packages per module | ||
* 1 module per 1 repository | ||
|
||
### Modules | ||
* `go.mod` file is necessary (and needs to be correct of course) | ||
* `go.mod` file contains: | ||
- module name | ||
- go version | ||
- dependencies | ||
- version of dependencies | ||
- (optional) replace | ||
- (optional) exclude |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters