Skip to content

Commit b0f1a0b

Browse files
committed
lesson10 + 11
1 parent c87c317 commit b0f1a0b

File tree

3 files changed

+423
-0
lines changed

3 files changed

+423
-0
lines changed

lesson10/book/book.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package book
2+
3+
import "errors"
4+
5+
func ShowBookInfo(bookName, authorName string) (string, error) {
6+
if bookName == "" {
7+
return "", errors.New("图书名称不能为空")
8+
}
9+
if authorName == "" {
10+
return "", errors.New("作者名称不能为空")
11+
}
12+
return bookName + ",作者:" + authorName, nil
13+
}

lesson10/main.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"go_basic_edu/lesson10/book"
6+
//"crypto/rand"
7+
//mrand "math/rand"
8+
)
9+
10+
//package packageName
11+
12+
//import path
13+
//import(
14+
// path1
15+
// path2
16+
// ...
17+
//)
18+
19+
func init() {
20+
fmt.Println("init...")
21+
}
22+
23+
func main() {
24+
/*
25+
包的初始化顺序
26+
1 包级别的变量
27+
2 init() 根据编译器解析的顺序进行调用
28+
29+
包的匿名导入
30+
import _ 包名
31+
*/
32+
33+
fmt.Println("《Go语言极简一本通》")
34+
info, _ := book.ShowBookInfo("《Go语言极简一本通》", "欢喜")
35+
fmt.Println(info)
36+
}

0 commit comments

Comments
 (0)