如本日主题,今天要来介绍一下Go语言的程序码架构,以下内容摘录自『 The Go Workshop 』。
package main ...................................................Part 1
import (........................................................Part 2
"errors"
"fmt"
"log"
"math/rand"
"strconv"
"time"
)
var helloList = []string{.......................................Part 3
"Hello, world",
"Καλημέρα κόσμε",
"こんにちは世界",
" ایند مالس",
"Привет, мир",
}
func main() {...................................................Part 4
rand.Seed(time.Now().UnixNano())
index := rand.Intn(len(helloList))
msg, err := hello(index)
if err != nil {
log.Fatal(err)
}
fmt.Println(msg)
}
func hello(index int) (string, error) {.........................Part 5
if index < 0 || index > len(helloList)-1 {
return "", errors.New("out of range: " + strconv.Itoa(index))
}
return helloList[index], nil
}
package main
import (
"errors"
"fmt"
"log"
"math/rand"
"strconv"
"time"
)
var helloList = []string{
"Hello, world",
"Καλημέρα κόσμε",
"こんにちは世界",
" ایند مالس",
"Привет, мир",
}
func main() {
rand.Seed(time.Now().UnixNano())
index := rand.Intn(len(helloList))
msg, err := hello(index)
if err != nil {
log.Fatal(err)
}
fmt.Println(msg)
}
func hello(index int) (string, error) {
if index < 0 || index > len(helloList)-1 {
return "", errors.New("out of range: " + strconv.Itoa(index))
}
return helloList[index], nil
}
第 35 天:制造 Deploy to Heroku 按钮 我打开信封,有张明信片在里面。明信片封面...
请问有没有人跟我一样,没有念大学,想成为软件工程师 ...
首先感谢这个技术平台让我分享一些专业的东西,今天我会分享一些Microsoft exam certi...
forloop.counter0 记数器从0开使 forloop.counter 从1开始 divi...
上一篇漏掉了一个主类别的函数: void anotherInstanceStarted (const...