2020年12月30日

[掘竅] Golang - 使用 slice of pointers 或 slice of structs

TL;DR; 如果這個 slice 或 slice 中的元素有可能會被操作修改,那麼就用 slice of pointers;如果這個 slice 單純只是拿來讀取,那麼就用 slice of structs;或者也可以無腦的使用 slice of pointers 以避免後續不小心而產生的 bug。 為什麼會看到 slice of pointers 的用法 在 Golang 中常會看到 slice 中存放的是 slice of pointers,使用 slice of pointers 或 slice of structs 有幾個很重要的差別。先來看看下面的程式碼。 假設我們先定義一個名為...

2020年12月20日

[Mobile] Android Samsung Note 10 vs. Apple iPhone mini 12 使用心得

我是一個對智慧型手機莫名有興趣的人,曾經在 hTC 打工時寫過幾篇開箱文、去年也寫過 Samsung S10+ 和 Note 10 的簡單比較,從智慧型手機出到現在,曾經用過 Micrsoft Lumia 620、LG G 系列、小米 Mix2S、小米 Mi 9、Google Pixel 3XL、Samsung S 系列,一直到現在用的 Samsung Note 10。 雖然換過許多不同的裝置,手邊用 Mac 和 iPad,耳機使用的是 AirPods Pro,但就是從來都沒有實際用過 iPhone。從去年的 iPhone 11 到今年年初推出的 iPhone SE...

2020年11月16日

[go-pkg] context package

此篇為各筆記之整理,非原創內容,資料來源可見下方連結與文後參考資料: Understanding the context package @ rungo pkg/context @ pkg.go.dev context package 最重要的就是處理多個 goroutine 的情況,特別是用來送出取消或結束的 signal。 我們可以在一個 goroutine 中建立 Context 物件後,傳入另一個 goroutine;另一個 goroutine 即可以透過 Done()...

[go-pkg] time/rate package

time/rate @ go.pkg Golang 標準庫限流器 time/rate 使用介紹 Golang time/rate 限速器 @ 簡書 重要概念 在 Golang 中使用 Limiter 來控制在特定頻率內,某個事件是否允許被執行。這個 Limiter 是實作 Token Bucket 的方式來達到限流的目的,也就是會先設定: ...