本文介绍了 Go 语言(Golang)的基本特性及其在现代软件开发中的应用,强调了 Go 的简洁性、高效性和并发处理能力。文中还概述了 Go 语言的结构(如数组、切片、结构体)、通道、并发控制等关键概念,以及相关的开发工具和框架。资料来源包括多个外部链接和参考文献,辅助读者更深入了解 Go 语言及其生态系统。
18. #include <stdio.h>
#include <stdlib.h>
int main() {
int *arr;
int i;
arr = malloc( 10 * sizeof(int) );
for (i = 0; i < 10; i++) {
arr[i] = i;
}
for (i = 0; i < 10; i++) {
printf("%d ", arr[i]);
}
free(arr);
return 0;
}
package main
import "fmt"
func main() {
var arr [10]int
for i := 0; i < 10; i++ {
arr[i] = i
}
for i := 0; i < 10; i++ {
fmt.Printf("%d ", arr[i])
}
}
Golang C
Array(陣列)
20. for 搭配 range
package main
import "fmt"
func main() {
var arr = []int{46, 15, 73, 16, 66, 35}
for index, value := range arr {
fmt.Printf("%d ", index, value)
}
}
41. func distributedSum(numOfWorkers int, from int, to int) int {
wg := &sync.WaitGroup{}
wg.Add(numOfWorkers)
in := make(chan int, (to-from)-1)
out := make(chan int, numOfWorkers)
res := make(chan int, 1)
for i := 0; i < numOfWorkers; i++ {
go sumWorker(in, out, wg)
}
go compilationWorker(out, res)
for i := 0; i <= to; i++ {
in <- i // 塞資料給各個 sumWorkers
}
close(in) // 關閉資料窗⼝ (通知各個 sumWorkers 停⽌讀值)
wg.Wait() // 等待所有 workers 結束
close(out) // 關閉資料窗⼝ (通知 compilationWorker 停⽌讀值)
return <-res
}
42. func sumWorker(in chan int, out chan int, wg *sync.WaitGroup) {
defer wg.Done()
num := 0
for n := range in { // 讀取通道直到通道被關閉
num += n
time.Sleep(time.Millisecond * 30)
}
fmt.Printf("partial sum: %dn", num)
out <- num
}
func compilationWorker(in chan int, out chan int) {
sum := 0
for i := range in { // 讀取通道直到通道被關閉
sum += i
}
out <- sum
}
43. •完全⾃學!Go 語⾔ (Golang) 實戰聖經
(The Go Workshop: Learn to write clean, efficient code and build high-performance applications with Go)
https://www.tenlong.com.tw/products/9789863126706
•下班加減學點 Golang 與 Docker
https://ithelp.ithome.com.tw/users/20104930/ironman/2647
•被選召的 Gopher 們,從零開始探索 Golang, Istio, K8s 數碼微服務世界
https://ithelp.ithome.com.tw/articles/10240228
•PJCHENder 未整理筆記
https://pjchender.dev/golang/go-getting-started/
參考資料
44. Mobile
API
CRUD
Login / Logout
Token (Session) JWT
/
Clean Architecture
Unit Test
Docker
Kubernetes (k8s)
Load Balancer
Database
Cache
Queue
Swagger
channel
mutex lock
CI / CD
MongoDB
RDBMS
MySQL
PostgreSQL
Memcached
Redis
RabbitMQ
grafana + prometheus
Pod
Service
Ingress
SOLID 5
OOP 3
goroutine
Backup
DRP (Disaster Recovery Plan)
Logs
BCP (Business Continuity Plan)
Git
Logger
45. obile
API
CRUD
Login / Logout
Token (Session) JWT
/
Clean Architecture
Unit Test
Docker
Kubernetes (k8s)
Swagger
channel
mutex lock
Pod
Service
Ingress
SOLID 5
OOP 3
goroutine
46. Mobile
Token (Session) JWT
Docker
Kubernetes (k8s)
Load Balancer
Database
Cache
Queue
Swagger
MongoDB
RDBMS
MySQL
PostgreSQL
Memcached
Redis
RabbitMQ
Pod
Service
Ingress
Logger
47. Mobile
CI / CD
grafana + prometheus
Backup
DRP (Disaster Recovery Plan)
Logs
BCP (Business Continuity Plan)
Git