Go 1-22 提供的更加強大的 Tracing 能力
本文是由 Go Team 的 Michael Knyszek 在 2024 年 3 月 14 日發表於 go official blog,原文地址:https://go.dev/blog/execution-traces-2024runtime/trace packageruntime/trace[1] package 包含了理解並排查 Go 程序的強大工具。其功能可以生成每個 gorouti ⌘ Read more
Go 設計模式:責任鏈和函數選項,讓你的代碼更優雅!
最近接觸到越來越多有歷史 “沉澱” 的 Go 項目,深感設計模式和及時干預的重要性。近期會分享一些設計模式,一起學習代碼設計!今天的分享的設計模式是:責任鏈和函數選項模式。在日常程序裏是比較常用的。很多開源庫中也有使用。責任鏈模式—–責任鏈模式(Chain of Responsibility Pattern)是一種行爲設計模式,它允許對象將請求沿處理程序鏈進行傳遞。程序鏈既可以處理請求,也可 ⌘ Read more
@bmallred@staystrong.run overall this was pretty good and the run-walk intervals kept my heart rate low.
at around 0400 a car came racing (90-100 mph) down gulf blvd towards my direction. it turned its headlights off and actually lost traction at point and skidded a bit. okay, kids. then a bit later i hear the car coming back behind me… so i got as far to the right as i could in case the car skids again. as it passed me i looked over my shoulder and saw a police vehicle a bit back w/o lights on yet. then looking in front another cop and then they blocked the lanes to get the driver to stop. driver decided he wasn’t stopping and tried to swerve around the police and ended up ping-ponging between sides of the road. enough of that…
took a wrong turn after going over the first bridge, but luckily it went in a loop. didn’t really know exactly where i was going anyways and was just winging it from the get-go.
the rest of the run was pretty uneventful and just a fun experience. crazy idea accomplished.
Why you do not want a visualization of your Infrastructure as Code
Originally published on the appCD blog by Asif Awan You’ve been working on a new application for your company. It is going to address business requirements needed to delight customers. But while you are ready to ship your… ⌘ Read more
Golang Context 內部原理一覽
context[1] 包是每個 Go 語言程序員在編程生涯中都會使用到的, 但你們真的瞭解它的內部工作原理嗎 (因爲據說真正的美麗都藏在內在)? 如果你對此感興趣, 可以查看我之前關於 sync.WaitGroup 內部工作原理的博文 鏈接 [2] 。本文旨在簡要概覽內部工作原理, 因此我會適當簡化一些細節。如果你想查看全部的實現細節, 或者你更喜歡直接閱讀源代碼而不是博客, 可以 點擊這裏 ⌘ Read more
go 語言調用 shell 命令有這麼兩種方式,都用過了?
阻塞方式 (需要執行結果) 主要用於執行shell命令,並且返回shell的標準輸出適用於執行普通非阻塞 shell 命令,且需要 shell 標準輸出的//阻塞式的執行外部shell命令的函數,等待執行完畢並返回標準輸出func execshell(s string) (string, error){ //函數返回一個Cmd,用於使用給出的參數執行name指定的程序 cmd := ⌘ Read more
10 個提高生產力的 Go 小技巧
最近 Phuong Le 大佬針對日常開發 Go 項目時,總結了一些好用的 Go 小技巧。看了後,感覺對於剛入門 Go 的同學有一定的學習價值。可以挑好的學。應用到自己項目裏。以下內容分享給大家。在開發 Go 生產項目時,我發現自己經常重複編寫代碼和使用某些技術,直到後來回顧自己的工作時才意識到這一點。下面是從總結經驗中挑選的一些有用的代碼片段,希望對大家有所幫助。計時技巧——-如果你對跟 ⌘ Read more
Enjoy the Lovely Trillium Lake Reflected in Mt Hood Apple Vision Pro Wallpaper
Apple often picks really beautiful wallpapers and imagery to go with their products, and while the iPhone, iPad, and Mac have tended recently towards more abstract wallpapers and product imagery, the Apple Vision Pro has some really gorgeous landscapes in the “Environments” feature of the spatial computing headset. The Apple Vision Pro has not been … [Read More](https://osxdail … ⌘ Read more
Why your next laptop will be the smartest of the lot
In the 1980s, the best laptop let you edit documents on the go. Today they can produce their own documents and images on demand, and process anything they see and hear. ⌘ Read more
PocketBase:一體化的開源 Go 語言實時後端
PocketBase 是一個開源的實時後端解決方案,採用單一文件的形式進行分發。它由嵌入式數據庫 (SQLite) 和實時訂閱功能組成,提供了開箱即用的文件和用戶管理功能、方便的管理儀表板 UI 以及簡單的 REST 風格 API。本文將深入探討 PocketBase 的功能、安裝、示例代碼和一些高級的應用技巧。主要特性—-嵌入式數據庫PocketBase 內嵌 SQLite 數據庫,這意味着 ⌘ Read more
Go: 使用依賴注入實現 Gin 框架路由處理函數的解耦
在 Go 語言開發中,Gin 是一個非常流行的 Web 框架。其輕量級、高性能的特點,使其成爲許多開發者的首選。然而,在實際項目中,隨着業務邏輯的複雜化,我們往往會遇到代碼耦合嚴重、測試困難等問題。依賴注入(Dependency Injection, DI)是一種有效的解耦手段,能夠幫助我們實現代碼的高內聚、低耦合,從而提升代碼的可維護性和可測試性。本文將探討如何在 Gin 框架中使用依賴注入來解 ⌘ Read more
Go:執行跟蹤變得更加強大
簡介Go 語言的 runtime/trace 包含一個強大的工具,用於理解和排查 Go 程序。其中的功能允許跟蹤每個 goroutine 在一段時間內的執行情況。然後,使用 go tool trace 命令(或優秀的開源工具 gotraceui)可以可視化和探索這些跟蹤中的數據。跟蹤的魔力在於,它可以輕鬆地揭示程序中其他方式難以看到的東西。例如,在 CPU 概要文件中很難看到併發瓶頸,因爲沒有要採 ⌘ Read more
Go singlefight 源碼詳解
寫在前面 通俗的來說就是 singleflight 將相同的併發請求合併成一個請求,進而減少對下層服務的壓力,通常用於解決緩存擊穿的問題。詳解基礎結構—-golang.org/x/sync/singleflight singleflight 結構體:type call struct { wg sync.WaitGroup // 這些字段在 WaitGroup 結束前寫入一次 // 只有在 W ⌘ Read more
Go:標準庫 bufio 包詳解
引言在日常開發中,對文件或輸入輸出流進行讀寫操作是非常常見的任務。Go 語言標準庫中的bufio包提供了數據的緩衝讀寫功能,使得讀寫操作更加高效。本文將詳細介紹bufio包的主要功能及其在實際編程中的應用場景。bufio 包概述bufio包主要提供了緩衝讀寫的能力,通過包裝一個io.Reader或io.Writer對象,創建一個帶緩衝的(buffered)讀寫器。使用緩衝可以減少對底層 IO 資源 ⌘ Read more
在 Go 中如何讓結構體不可比較?
最近我在使用 Go 官方出品的結構化日誌包 slog 時,看到 slog.Value 源碼中有一個比較好玩的小 Tips,可以限制兩個結構體之間的相等性比較,本文就來跟大家分享下。在 Go 中結構體可以比較嗎?在 Go 中結構體可以比較嗎?這其實是我曾經面試過的一個問題,我們來做一個實驗:定義如下結構體:type Normal struct { a string B int}使用這個結構體分別聲明 ⌘ Read more
Unfortunately not on that front. Still the same 404 posting errors and oddly occasional login errors.
That’s why I was wondering if using Go 1.22.4 could be an issue. I don’t know how exactly. Only way to test is to rebuild it with an older version I guess, which is why I did the make clean in the first place. Old habits die hard lol.
@prologic@twtxt.net Righteo, so rookie error - I obviously had some untracked, rather important files for starting my pod and I ran a make clean. Why I originally had them in the git directory is anyone’s guess. Anyway it blew away those files including the database so that’s that. So your good self and @bender@twtxt.net etc - apologies but your profiles got nuked as well (as did my own but easily recreated).
Another thing I noticed which was the reason I ran make clean in the first place. I noticed my pod was being built with Go 1.22.4. Could this be a problem @prologic? preflight.sh actually errors out about it…
Go 實現可複用的通用內存緩存
本文介紹瞭如何在 Go 語言中創建一個可重用的內存通用緩存,並提供了具體的實現代碼和使用示例。Prerequisites安裝 Go go-cache package[1] 實現首先,創建一個 cache package,它包含我們正在構建的緩存的代碼。package cacheimport ( ”time” ”github.com/patrickmn/go-cache”)使用泛型實現一 ⌘ Read more
Go:log 庫的全面指南與使用技巧
引言–在 Go 語言的標準庫中,log包提供了簡單而強大的日誌功能。日誌記錄是軟件開發中不可或缺的一部分,它不僅幫助開發人員調試和排查問題,還在系統運行中提供了寶貴的運行時信息。本文將詳細講解 Go 語言log庫的各種功能及其使用技巧,幫助開發者更好地掌握和應用這一重要工具。log 包簡介——-log包是 Go 語言標準庫的一部分,提供了基本的日誌記錄功能。它支持日誌消息的格式化、日誌輸 ⌘ Read more
Go 實現雙 buffer id 生成器
本文通過 Go 實現一個 Leaf——美團點評分佈式 ID 生成系統 雙 buffer 的 id 獲取器。一. 主流程———-主流程看圖似乎步驟非常多,但實際上總結起來就以下三個步驟:客戶端發起請求 id 獲取器從緩存中獲取 如果 id 已經被消耗超過閾值,則重新加載新的號段到內存中 接下來我們來具體看一下 Go 代碼是如何實現的二. 代碼實現——-2.1 S ⌘ Read more
Go:For-Select-Done 併發設計模式應用
引言Go 語言支持的併發模型是其一大亮點,它內建的 Goroutine 機制爲構建高性能併發應用提供了基礎。在這種環境下,使用 For-Select-Done 設計模式可以優雅地處理併發任務和通道(Channel)的交互,從而實現高效的數據處理和狀態管理。For-Select-Done 設計模式概述For-Select-Done 模式是一種結構化的方式來處理 Go 中的多個通道讀寫操作,使代碼更加 ⌘ Read more
10 分鐘瞭解 Golang 泛型
泛型是 Golang 在 1.18 版本引入的強大工具,能夠幫助我們在合適的場合實現簡潔、可讀、可維護的代碼。原文: Go Generics: Everything You Need To Know[1]導言可能有人會覺得 Go 泛型很難,因此想要借鑑其他語言(比如 Java、NodeJS)的泛型實踐。事實上 Go 泛型很容易學,本文希望能幫助讀者更好的理解 Go 泛型。 👉注:本文不會將 ⌘ Read more
Base: 7.00 miles, 00:09:48 average pace, 01:08:37 duration
really easy. i was “suppose” to go for 90 minutes but my son kept coming in and really i need to keep my mileage down this week anyways.
#running #treadmill
cassowary: 現代跨平臺的 Go 語言 HTTP 負載測試工具
在現代互聯網應用程序中,性能和響應速度是決定用戶體驗的關鍵因素。負載測試是確保我們的應用程序在高併發下仍能穩定運行的一種重要手段。本文將帶你瞭解一個現代的跨平臺 HTTP 負載測試工具——cassowary,並展示其安裝和使用方法。什麼是 cassowary?————–cassowary 是一個用 Go 語言編寫的現代跨平臺 HTTP 負載測試工具。它設計簡潔、易於使用,支持高併 ⌘ Read more
在 Go 中如何優雅的使用 wire 依賴注入工具提高開發效率?上篇
如果你做過 Java 開發,那麼想必一定聽說或使用過依賴注入。依賴注入是一種軟件設計模式,它允許將組件的依賴項外部化,從而使組件本身更加模塊化和可測試。在 Java 中,依賴注入廣泛應用於各種框架中,幫助開發者解耦代碼和提高應用的靈活性。本文就來介紹下什麼是依賴注入,以及在 Go 語言中如何實踐依賴注入,提高 Go 項目的開發效率和可維護性。什麼是依賴注入?正如前文所述,依賴注入(dependen ⌘ Read more
Go: 深入探究 uintptr 類型
Go 語言作爲一種靜態類型、編譯型語言,其獨特的類型系統爲編程提供了強大的支持。在衆多類型中,uintptr 是一個較爲特殊的類型,它用於存儲指針值的整數表示。本文將詳細介紹 uintptr 的概念、使用場景及其與普通指針類型的區別。uintptr 的定義與特性在 Go 語言中,uintptr 是一個無符號整數類型,其大小足以存儲任意指針的位模式。具體來說,uintptr 的定義如下:type u ⌘ Read more
Burial – Phoneglow
Taken from Burial’s new split 12” with Kode9, out now on Hyperdub.
Phoneglow / Eyes Go Blank by Burial, Kode9
It’s Apple v Microsoft as tech titans battle for AI supremacy
Apple Intelligence will go head-to-head with Microsoft’s Copilot+ PCs, which are being launched this week. ⌘ Read more
Go is more than a language; Go is a platform!
1 points posted by Elton Minetto ⌘ Read more
Pinellas County - Long Run: 12.00 miles, 00:11:00 average pace, 02:11:59 duration
took it easy. for each overpass or for each mile i walked a tenth of a mile just to ensure i hydrated and kept my HR down. head has been murder recently and i knew the weekend was going to be filled with activities.
#running
Go 事件驅動編程:實現一個簡單的事件總線
前言在當今微服務和分佈式系統盛行的背景下,事件驅動架構(Event-Driven Architecture,EDA)扮演着一個至關重要的角色,此架構的設計使得服務間可以通過事件進行同步或異步通信,替代了傳統的直接接口調用。基於事件的交互方式,促進了服務之間的松耦合,提高系統的可擴展性。發佈 - 訂閱模式是實現事件驅動架構的模式之一,它允許系統的不同組件或服務發佈事件,而其他組件或服務可以訂閱這些事 ⌘ Read more
yq:基於 Go 實現處理 YAML、JSON、XML、CSV、TOML 的命令行工具
在現代開發和運維的世界中,處理和轉換不同格式的數據文件如 YAML、JSON、XML、CSV 等是日常任務。文件格式的多樣性和複雜性常常給開發者帶來不小的挑戰。在這種情況下,強大的命令行工具能夠極大地簡化工作流程。本文將深入探討一個強大的多功能工具——go yq,它能夠便捷地處理 YAML、JSON、XML、CSV、TOML 以及屬性文件。安裝 go yq——–首先,我們需要安裝 go ⌘ Read more
Live website updates go sse htmx
1 points posted by m110 ⌘ Read more
GO 語言學習筆記: 垃圾回收機制剖析
一、引言—-(一)垃圾回收 概述垃圾回收(Garbage Collection,GC) 是 Go 語言的核心特性之一,是實現內存自動管理的一種形式。golang 的自動垃圾回收屏蔽了複雜且容易出錯的內存操作,讓開發變得更加簡單、高效。在 Go 語言中,從實現機制上來說,垃圾回收可能是最複雜的模塊了。瞭解垃圾回收的機制,有助於更好地理解 Go 語言的內存管理機制,從而更好的使用 Go 語言進行開 ⌘ Read more
Go 命令模式實戰
隨着分佈式應用越來越廣泛,數據操作的一致性需要由業務方來保證,兩個操作不在同一個事務操作失敗時,無法依靠數據庫事務直接回滾,這時需要業務方手動進行回滾。通過命令模式提供新舊數據初始化後,如果執行後有後續操作失敗,業務方可以通過調用 Undo方法進行回滾,無需再編寫數據庫操作代碼優點是減少了回滾代碼的重複編寫,只要提供新舊數據,通過 Do和 UnDo就可以完成對應操作。並且有些時候可能 Undo 方 ⌘ Read more
Go 中空結構體的用法,我幫你總結全了!
在 Go 語言中,空結構體 struct{} 是一個非常特殊的類型,它不包含任何字段並且不佔用任何內存空間。雖然聽起來似乎沒什麼用,但空結構體在 Go 編程中實際上有着廣泛的應用。本文將詳細探討空結構體的幾種典型用法,並解釋爲何它們在特定場景下非常有用。空結構體不佔用內存空間首先我們來驗證下空結構體是否佔用內存空間:type Empty struct{}var s1 struct{}s2 := E ⌘ Read more
快速喫透 Golang Channels 使用技巧
Golang 可以通過啓動 goroutines 來併發執行任務。它們可以通過一種名爲 “通道” 的通信媒介相互通信。話不多說,下面我列舉了幾種不同情況下 channel 的使用以及其適用條件,最後總結出一張 channel table,能夠幫助你快速喫透 channel 的所有要點。Let’t go!Nil Channels如果你像創建普通變量一樣創建一個通道,通道將被初始化爲零值。這裏要提到的 ⌘ Read more
如何將圖片編碼成 base64?
圖片的 base64 編碼在多種上下文中都很有用。當需要通過旨在處理文本數據的媒體存儲或傳輸圖片時,它通常會被使用,比如嵌入到網頁或者通過 API 上傳圖片。這篇文章將介紹如何使用 Go 標準庫得到任何圖片的 base64 編碼的值。在 Go 中將圖片轉換爲其 base64 表示很容易。所有你需要做的是將文件讀取爲字節 slice 並使用包 encoding/base64 對其進行編碼。處理本地圖 ⌘ Read more
Go:深入理解互斥鎖,實現與應用
在併發編程中,互斥鎖是一種基本的同步機制,用於保護共享資源不被多個線程或進程同時訪問,從而避免數據競爭和保證數據的一致性。本文將深入探討互斥鎖的概念、工作原理,並通過 Go 語言的具體實現來展示互斥鎖在實際編程中的應用。互斥鎖的基本概念互斥鎖(Mutex)是最簡單的一種鎖形式,它僅允許一個線程在同一時刻訪問某個資源。當一段代碼被定義爲臨界區時,任何線程在進入該區域前必須先獲得互斥鎖的授權,並在離開 ⌘ Read more
利用 Go 語言加速 Redis 操作:掌握 go-redis 包的高效應用技巧
一、golang 操作 redis 1、安裝初始化文件夾 c:\aaa mkdir testredisc:\aaa\testredis go mod init testredis安裝 go get github.com/go-redis/redis/v82、基本使用 package mainimport ( “context” “fmt” “github.com/go-r ⌘ Read more
End of ‘go-to’ harvest trail farm labour program a big loss, farmers say
Backpackers fear a rise in exploitation on Australian farms after the government axed a 26-year-old jobs program, which farmers fear will also increase costs and threaten harvests. ⌘ Read more
It’s nice to see a cloud provider lower prices, which seems very uncommon, as all the prices (cloud, domains, …) usually go up all the time. And it’s also my provider of choice, which means I will have to pay less for my virtual server in the future! 😄 ⌘ Read more
Go:標準庫 Arena 的內存管理優化解析
引言–在 Go 語言的衆多標準庫中,arena庫是一個相對較新且不爲人知的部分,還處於試驗階段。這個庫提供了一種管理內存分配的有效方式,尤其適用於處理大量小型對象,能夠顯著減少內存碎片和提高內存使用效率。本文將深入探討arena庫的設計理念、使用方法以及它如何優化 Go 語言程序的內存管理。arena庫概述———-arena庫的核心思想是提供一個連續的內存塊,讓開發者可以在其中快速分 ⌘ Read more
Go:雙向鏈表實現,container-list 包探討
引言在 Go 語言的標準庫中,container/list包提供了雙向鏈表的實現。鏈表是一種常見的數據結構,它通過節點的序列實現,每個節點都包含數據及對前一個節點和後一個節點的引用。Go 語言的container/list包提供了操作鏈表的多種方法,如插入、刪除、搜索和移動元素等。本文將深入探討container/list包,解析其實現的內部機制,並通過示例展示如何在 Go 程序中有效地使用此包。 ⌘ Read more
Can I Keep My MacBook Pro/Air Plugged in All The Time?
Many MacBook Pro and MacBook Air owners use their laptops in dual use scenarios, functioning as a laptop computer when on the go, and a desktop computer when not. This leads some to wonder if it’s bad for the MacBook battery to leave the computer charging or plugged in, even if it’s not in use. … Read More ⌘ Read more
基於 Go 語言實現的 Ollama 大語言模型框架
大語言模型在現代人工智能領域中扮演着重要角色。Ollama 作爲一個輕量級且可擴展的框架,幫助開發者在本地機器上構建和運行這些模型。Ollama 簡介———Ollama 是一個簡單、可擴展的框架,旨在幫助開發者構建和運行大語言模型。它提供了一個簡潔的 API,用於創建、運行和管理模型。此外,Ollama 附帶了豐富的預構建模型庫,供開發者在各種應用中輕鬆使用。Ollama 的特性包括: ⌘ Read more
Go 項目中的 Goroutine 泄露及其防範措施
Goroutine 是 Go 語言中實現併發的重要機制。它們輕量且高效,極大地提升了 Go 程序的併發能力。然而,在實際編程中,我們容易遇到 Goroutine 泄露的問題。這篇文章將詳細探討 Goroutine 泄露的概念、原因、檢測方法及其防範措施。什麼是 Goroutine 泄露?—————–Goroutine 泄露類似於內存泄露,是指程序中創建的 Goroutine ⌘ Read more
Kubernetes Go 週期執行器的實現
週期執行器主要用在同步網絡規則,如 iptables proixer、nettables proixer 中,一旦有新的網絡規則需要增加,就會週期性執行。我們通過一張圖來快速瞭解一下 BoundedFrequencyRunner 的執行流程BoundedFrequencyRunner用於週期性的執行同步方法,並且提供了執行失敗進行重試,內部封裝了運行的限流器type BoundedFrequenc ⌘ Read more
We’re going to pay more for OJ in the near future, and we might need grape growers to juice things up
Citrus Australia estimates international orange concentrate imports halved this year as the result of a huge global shortage, and it might see mandarin and even disgruntled grape growers step up. ⌘ Read more
使用 Go 語言實現定時任務:輕鬆掌握 Cron 表達式
一、cron 基本使用1、使用舉例package mainimport ( “fmt” “github.com/robfig/cron”)//主函數func main() { cron2 := cron.New() //創建一個cron實例 //執行定時任務(每5秒執行一次) err:= cron2.AddFunc(“/5 “, print5) if err!=nil{ ⌘ Read more