Searching We.Love.Privacy.Club

Twts matching #go
Sort by: Newest, Oldest, Most Relevant

golang 面試官:for select 時,如果通道已經關閉會怎麼樣?如果只有一個 case 呢?
今天咱們聊點技術性的東西,具體說一下 Go 語言中的 for select 語句,特別是在面試中經常被問到的兩個問題。題目 1:for select 語句中,如果通道已經關閉了,會怎麼樣?這道題乍一聽簡單,但其實是面試官最喜歡用來考察你是否真正理解 Go 中通道機制的題目之一。假設你在寫一個需要從通道讀取數據的程序,然後突然有人關了通道,你會怎麼處理?程序會怎麼樣?如果你把這個問題想得很簡單,你可 ⌘ Read more

⤋ Read More

在 go 語言裏用 Redis 如何實現延時任務隊列,如何延時?
在 Go 語言中,使用 Redis 實現延時任務隊列可以通過 Sorted Set(ZSet) 結合 輪詢機制 或 Pub/Sub 實現。以下是詳細實現方案,以及延時任務與定時任務的區別和應用場景分析。一、延時任務隊列的實現(Go + Redis)核心思路存儲結構:使用 Redis 的 Sorted Set(ZSet),以任務的 執行時間戳 作爲分數(Score),任務內容作爲成員(Member) ⌘ Read more

⤋ Read More

理解 Go 語言中的 Graceful Shutdown 機制
當使用 Go 開發 Web 服務時,實現正確的關機處理對於維護系統可靠性和數據完整性至關重要。優雅關機能確保服務在終止前完成現有操作,而不是突然停止導致任務未完成。核心概念解析——優雅關機需要協調終止信號接收、進行中的操作和資源清理。在 Go 中,通常通過信號處理、goroutine 和基於上下文的取消機制來實現。以下是最小化實現示例:package mainimport (    ”co ⌘ Read more

⤋ Read More

Go 1-24 的 omitzero:JSON 處理的福音
使用 omitempty 忽略 JSON 中的可選字段 (Go 1.24 之前)——————————————當你有一個要轉換爲 JSON 的結構體時,你可能有一些字段是可選的。例如,我們採用以下結構體:type Response struct { ID        string    json:“id” // 其他字段省略 UpdatedA ⌘ Read more

⤋ Read More

用 Go 語言手撕 DNS 協議:從理論到 gothdns 的工程實踐
在互聯網基礎設施的基石中,DNS(域名系統)堪稱最優雅的分佈式系統設計典範。這個將域名轉換爲 IP 地址的魔法系統,每秒處理着數以億計的查詢請求。Go 語言憑藉其簡潔的併發模型和高效的網絡編程能力,成爲實現 DNS 協議的絕佳選擇。理解 DNS 協議需要把握三個核心要素:分層樹狀結構的域名空間 UDP/TCP 雙協議支持 資源記錄(RR)的二進制編碼規範 Go 語言標準庫中的ne ⌘ Read more

⤋ Read More

Go 語言反向代理實戰:零壓力承載百萬流量
在現代分佈式系統中,反向代理扮演着數字交通警察的角色。它不僅是客戶端與服務端之間的智能中介,更是系統架構中不可或缺的流量調度中心。典型的應用場景包括:負載均衡:智能分配請求到後端服務器集羣 安全防護:作爲安全邊界過濾惡意請求 協議轉換:統一處理不同通信協議 緩存加速:對靜態資源進行邊緣緩存 服務聚合:整合多個微服務的響應結果 Go 語言憑藉其獨特的併發模型和卓越的性能 ⌘ Read more

⤋ Read More

Go 語言中如何高效地處理集合
在 Go 語言中,處理集合(如切片、映射等)時,可以通過多種方式提高效率。以下是一些常見的高效處理集合的方法,結合詳細的代碼例子進行講解。1. 使用切片(Slice)代替數組切片是 Go 中常用的集合類型,它比數組更靈活,因爲切片的長度是可變的。package mainimport “fmt”func main() { // 創建一個切片 numbers := []int{1, 2, ⌘ Read more

⤋ Read More

告別 WebSocket?探索 SSE 爲 Go 應用帶來的全新可能
在現代 Web 應用開發中,實時通信一直是一個重要的需求。傳統上,WebSocket 是實現實時雙向通信的首選方案。然而,隨着技術的發展,Server-Sent Events (SSE) 這一輕量級的單向實時通信技術正在獲得越來越多的關注。本文將深入探討 SSE 技術,並通過實例說明爲什麼在某些場景下它可能比 WebSocket 更適合您的 Go 應用。SSE 是什麼?——–Server ⌘ Read more

⤋ Read More

10 Unbelievable Advertising Fiascoes
For various reasons, product advertisements sometimes go awry in a big way. A case in point: Budweiser Light’s ad campaign featuring transgender influencer Dylan Mulvaney resulted in a boycott that cost the company almost 1.5 billion dollars, as customers switched from Bud Light to competitors’ brands. As Harvard Business Review points out, companies learned that […]

The post [10 Unbelievable Advertising Fiascoes](https://listverse.com/2025/02/12/10-unbeliev … ⌘ Read more

⤋ Read More

Go 併發控制:sync-Map 詳解
我們知道,Go 中的 map 類型是非併發安全的,所以 Go 就在 sync 包中提供了 map 的併發原語 sync.Map,允許併發操作,本文就帶大家詳細解讀下 sync.Map 的原理。使用示例sync.Map 提供了基礎類型 map 的常用功能,使用示例如下:package mainimport (“fmt”“sync”)func main() {var s sync.Map// 存儲鍵值 ⌘ Read more

⤋ Read More

Notary Project announces Notation v1.3.0 and tspclient-go v1.0.0!
The Notary Project maintainers are thrilled to announce the latest releases, including notation v1.3.0, notation-go v1.3.0, notation-core-go v1.2.0 and tspclient-go v1.0.0! These new versions are production ready and have successfully completed a comprehensive security audit. Check… ⌘ Read more

⤋ Read More

Oasis: a small, statically-linked Linux system
You might think the world of Linux distributions is a rather boring, settled affair, but there’s actually a ton of interesting experimentation going on in the Linux world. From things like NixOS with its unique packaging framework, to the various immutable distributions out there like the Fedora Atomic editions, there’s enough uniqueness to go around to find a lid for every pot. Oasis Linux surely falls into this category. One of its main … ⌘ Read more

⤋ Read More

Go 併發控制 Wait - Cancel
Wait 和 Cancel 兩種併發控制方式,在使用 Go 開發服務的時候到處都有體現,只要使用了併發就會用到這兩種模式。在 Go 語言中,分別有 sync.WaitGroup 和 context.Context 來實現這兩種模式。sync.WaitGroup 等待多個線程完成對於要等待 n 個線程完成後再進行下一步的同步操作的做法,使用 sync.WaitGroup 來等待一組事件:func m ⌘ Read more

⤋ Read More

Holly Hill - Long run: 12.06 miles, 00:09:43 average pace, 01:57:15 duration
did not sleep last night. the bed was not too comfortable and i was burning up for some reason. the run went well. it was a decent temperature and i kept the pace pretty moderate (mainly around a 9:30). hit two bridges going back-and-forth between daytona. i did walk a bit around mile ten to recollect myself but a good run nonetheless.

my daughter got first all-around in her gymnastic meet and did really well on all events, too!
#running

⤋ Read More

From finding to fixing: GitHub Advanced Security integrates Endor Labs SCA
The partnership between GitHub and Endor Labs enables application security engineers and developers to drastically reduce time spent on open source vulnerabilities, and gives them the tools to go from finding to fixing.

The post [From finding to fixing: GitHub Advanced Security integrates Endor Labs SCA](https://github.blog/security/from-finding-to-fixing-github-advanced-security-integrates … ⌘ Read more

⤋ Read More

(#ydmhcsa) @lyse@lyse @bender@bender The funny thing is, this person, is still trying to convince me to go to this thing. I don’t …
@lyse @lyse.isobeef.org @bender @twtxt.net The funny thing is, this person, is still trying to convince me to go to this thing. I don’t even know wut da fuq it is?! Do they smoke peace pipes or something? Is it a hooker joint or something?! I have no idea 🤷 ⌘ Read more

⤋ Read More

Go 併發 Bug 殺手鐧:如何正確處理 Goroutines 中的錯誤?
📌 引言—–你是否遇到過這樣的情況:明明 Goroutine 已經執行,但程序結果卻異常? 錯誤似乎消失了,日誌中卻找不到任何線索? Goroutine 發生 panic,主程序卻沒有任何反應? 這些問題的根本原因通常是 Goroutines 中的錯誤處理缺失。如果沒有正確捕獲和處理錯誤,Go 的併發機制可能會讓 Bug 變得難以察覺,甚至導致程序崩潰。本文將深入剖析 G ⌘ Read more

⤋ Read More

golang 每日一庫之 spf13-viper
spf13/viper 是一個非常流行的 Go 語言庫,主要用於處理應用程序的配置文件。它提供了一種靈活且強大的方式來讀取、解析和管理不同來源的配置數據,比如文件、環境變量、命令行參數等。Viper 以其簡潔、易用以及高度的可定製性在 Go 生態中廣受歡迎。1. Viper 的核心功能Viper 主要用於配置管理,它支持從不同來源加載配置、處理複雜的數據結構、以及提供對配置項的靈活訪問。以下是 V ⌘ Read more

⤋ Read More

在 Go 中如何將 [][]byte 轉爲 io-Reader ?
起因:在春節前的某一天,我在 ekit 項目的交流羣裏看到大明老師發了這樣一條消息: 各位大佬,問個小問題,有咩有誰用過 byte 轉爲 io.Reader 的東西?我以前搞過一次,但是我忘了是我手搓了一個實現,還是用的開源的,還是 SDK 自帶的並且大明老師還爲此開了一個 issue。看到這條消息,我想起了我在對 Go 還不太熟悉時,曾寫過一個 io.MultiReader 的實現(當時寫完了 ⌘ Read more

⤋ Read More

解密 Go 語言中的雙生函數:main– 與 init– 的隱祕世界
在 Go 語言的開發實踐中,main()和init()這兩個看似簡單的函數,承載着程序生命週期的核心邏輯。它們如同程序世界的守門人,一個負責搭建舞臺,另一個負責拉開帷幕。本文將通過深度剖析二者的差異,揭示它們在 Go 運行時系統中的運作機制,並提供多個完整代碼示例幫助開發者掌握正確使用姿勢。 函數本質與定位差異———main():程序的唯一入口main()函數是每個可執行 Go 程序的 ⌘ Read more

⤋ Read More

Go 項目裏的 API 對接,這樣做 Mock 測試才舒服
我們在開發項目的過程中總會遇到要調用依賴方接口的情況,如果依賴方的 API 接口還沒有開發好,通常我們會先約定好 API 接口的請求參數、響應結構和各類錯誤對應的響應碼,再按照約定好請求和響應進行開發。除了上面說的情況外,還有一種就是當你開發的功能需要與微信支付類的 API 進行對接時,因爲各種訂單、簽名、證書等的限制你在開發階段也不能直接去調用支付的 API 來驗證自己開發的程序是否能成功完成對 ⌘ Read more

⤋ Read More

Golang Option 模式看這一篇就夠了
在 Go 語言中,我們經常需要定義結構體,並通過構造函數初始化它們。然而,Go 不支持默認參數,如果一個結構體有很多可選參數,我們會面臨以下問題:構造函數參數過長,調用時不夠直觀。 需要維護多個 NewXXX 函數,擴展性較差。 代碼可讀性降低。 爲了解決這個問題,Golang 社區廣泛採用 Option 模式,讓我們可以優雅地管理可選參數。本文將詳細講解 Option 模式的 ⌘ Read more

⤋ Read More

基於 Go 語言構建高性能併發鍵值存儲
在分佈式系統和高併發場景中,鍵值存儲(Key-Value Store)作爲基礎組件扮演着至關重要的角色。本文將通過 Go 語言實現一個線程安全的併發鍵值存儲系統,深入探討其設計原理、性能優化策略以及實際應用場景。 爲什麼選擇 Go 語言?————Go 語言憑藉其原生的併發模型(goroutine 和 channel)、高效的內存管理以及簡潔的語法,成爲構建高性能併發系統的理想選擇。 ⌘ Read more

⤋ Read More

Go channel 計數信號量
Go 併發設計的一個慣用法就是將帶緩衝 channel 用作計數信號量(counting semaphore)。帶緩衝 channel 中的當前數據個數代表的是當前同時處於活動狀態(處理業務)的 goroutine 的數量,而帶緩衝 channel 的容量(capacity)就代表了允許同時處於活動狀態的 goroutine 的最大數量。向帶緩衝 channel 的一個發送操作表示獲取一個信號量, ⌘ Read more

⤋ Read More

在 Go 中實現 TOTP 認證:實踐指南
時間性一次性密碼(TOTP)已成爲現代應用中實現雙因素認證(2FA)的標準。在本指南中,我們將探討如何在 Go 中使用流行的 github.com/pquerna/otp 庫實現 TOTP。 什麼是 TOTP?———TOTP 生成臨時密碼,這些密碼在短時間內(通常是 30 秒)有效。這項技術是 Google Authenticator、Authy 等認證器應用背後的核心技術。TOTP ⌘ Read more

⤋ Read More

Go 語言流式編程,實現高效數據處理!
在 Go 語言開發中,傳統的數據處理方式往往採用for循環配合切片操作的模式。但隨着業務複雜度提升,這種模式逐漸暴露出內存佔用高、代碼可讀性差、擴展性弱等問題。流式編程(Stream Processing)作爲一種聲明式編程範式,通過構建數據處理管道(Pipeline),爲這些問題提供了優雅的解決方案。流式編程的核心在於將數據處理過程分解爲多個獨立的操作階段,每個階段專注於單一職責。這種模式具有以 ⌘ Read more

⤋ Read More

10 Strange Yet True Historical Events
History is full of weird and wild things that most people go their entire lives without reading about. Stories about cat-related military operations or entire wars fought over pigs and emu. Here are 10 strange yet true historical events that are stranger than fiction. Related: 10 Bizarre Events in the Age of Reason That Defied […]

The post 10 Strange Yet True Historical Events appea … ⌘ Read more

⤋ Read More

@lyse@lyse.isobeef.org Thanks for sharing. I really enjoyed it. The beginning part about the history of life on Earth was fun to watch having just read Dawkin’s old book The Selfish Geene, and now I want to read more about archaea. The end of the talk about what might be going on on Mars made me a bit hopeful someone will find some good evidence.

⤋ Read More

**Seriously?! 😳 Transscript

if I had a Go struct such as the following:

Here’s how the complete interface would look:

type B ...**
Seriously?! 😳 [Transscript](https://gist.mills.io/prologic/fe6bb412dcc245a69b4cbad22f38dcd2)

> if I had a Go struct such as the following:

…

> Here’s how the complete interface would look:

type Bar interface {

Read(t *Bar, b []byte) (int, error)

}

”`

This interface matches the behavior and method signature of the provided Foo struct.

This is total garbage 🗑️ ⌘ Read more”`

⤋ Read More

Finally I’ll also be setting up CubeFS (finally mature enough to give it a serious go) and slowly migrating workloads to use it as Persistent …
Finally I’ll also be setting up CubeFS ( finally mature enough to give it a serious go) and slowly migrating workloads to use it as Persistent storage across the 3 Hypervisor nodes ( which will run KVM + CubeFS) – Thank goodness this thing ( CubeFS) doesn’t need to run on Kubernetes 😂 ⌘ Read more

⤋ Read More

(#ondf3bq) @lyse@lyse I have no problems with the ternary operator either. If it were added to Go I Wouldn’t mind. C has it right? I …
@lyse @lyse.isobeef.org I have no problems with the ternary operator either. If it were added to Go I Wouldn’t mind. C has it right? I’d also by happy with if expressions, e.g: if foo ... else bah, but probably doesn’t fit the styoe of the Go grammer.

What I absolutely hate is this proposal. Making ? to mag … ⌘ Read more

⤋ Read More

@lyse@lyse.isobeef.org The one in question is more like the javascript version for unwrapping errors when accessing methods.

 const value = some?.deeply?.nested?.object?.value

but for handling errors returned by methods. So if you wanted to chain a bunch of function calls together and if any error return immediately. It would be something like this:

b:= SomeAPIWithErrorsInAllCalls()
b.DoThing1() ?
b.DoThing2() ?

// Though its not in the threads I assume one could do like this to chain.
b.Chain1()?.Chain2()?.End()?

I am however infavor of having a sort of ternary ? in go.

PS. @prologic@twtxt.net for some reason this is eating my response without throwing an error :( I assume it has something to do with the CSRF. Can i not have multiple tabs open with yarn?

⤋ Read More

**I want to propose my own counter-proposal to the discussion that’s ongoing with Go and error handling.

Here it is:

It’s very rough and needs …**
I want to propose my own counter-proposal to the discussion that’s ongoing with Go and error handling.

Here it is: https://docs.mills.io/ix4qDHMnQUSPxZ5tXz12Vg?view

It’s very rough and needs much more work, but essentially I want to propose the following change to the language’s grammar:

”`
f := os.Open(“foo.txt”) or (e error) {

lo ... ⌘ [Read more](https://twtxt.net/twt/spvh6fa)```

⤋ Read More

i upgraded my pc from lubuntu 22.04 to 24.04 yesterday and i was like “surely there is no way this will go smoothly” but no it somehow did. like i didn’t take a backup i just said fuck it and upgraded and it WORKED?!?! i mean i had some driver issues but it wasn’t too bad to fix. wild

⤋ Read More

Ten Stomach-Turning Facts That We Wish Weren’t True
We’re going to go ahead and get this out there right now: You probably shouldn’t read on from here if you’ve got a queasy gut. Some of the stomach-turning facts we’re about to drop on this list are not for the faint of heart. (Or, uh, the faint of digestive tract.) But for those of […]

The post [Ten Stomach-Turning Facts That We Wish Weren’t True](https://listverse.com/2025/01/28/ten-stomach-turning-facts-that-we-wish-werent-true … ⌘ Read more

⤋ Read More

@andros@twtxt.andros.dev Sweeeeet! Just gave it a try, you’ve done a wonderful work 🫡 I wanted to replay from there but couldn’t go past the first page of the feed. It kept freezing on me and complaining about some bad Url (as mentioned on the test twt), so I’ll have to dig through my follow list and see where I effed up this time. 😅

⤋ Read More