Golang 實現協程池
Go 協程池解決的問題:當需要創建大量的goroutine的時候,如果不限定goroutine的數量,將是對程序的巨大災難 使用完的goroutinue可以複用繼續執行下一個任務(而不是立即銷燬),如果每次都是創建新goroutinue執行任務,頻繁的創建銷燬goroutinue導致利用率低下 項目地址 https://github.com/gofish2020/easygpool 歡 ⌘ Read more
The river was frozen for a few weeks this winter (somehow I even saw folks ice fishing at one point) but melted away again pretty fast. NOAA is saying now it’s probably not going to freeze again this year. Wow.
Using test helpers in Go
1 points posted by Elton Minetto ⌘ Read more
Build code security skills with the GitHub Secure Code Game
Learn to find and fix security issues while having fun with Secure Code Game, now with new challenges focusing on JavaScript, Python, Go, and GitHub Actions!
The post Build code security skills with the GitHub Secure Code Game appeared first on The GitHub Blog. ⌘ Read more
Pinellas County - Easy: 3.13 miles, 00:08:27 average pace, 00:26:24 duration
felt crazy relaxed and easy breathing. i did notice at around the mile and a half point (11:30 in?) my HR jumped. around this time i also noticed i had to switch to more mouth breathing because my nose was running. going to try to take note of this because if it is a fault on the watch side then i can not consider it a reliable measurement.
#running
Research Account
⌘ Read more
Research Account
⌘ Read more
I have a habit of running system updates on my work laptop before going out for coffee. Like some kind of ritual to prepare to go into the world fully patched.
St Petersburg Distance Classic Marathon: 26.41 miles, 00:11:23 average pace, 05:00:39 duration
first marathon down. everything that could go wrong did. honestly i am just proud i did not quit. now i have to look at the run and figure out what i can tweak or add to my training. had a cramp start in my right quad at around mile 15. then around mile 18 both of my calves started to feel odd as if someone was lightly strumming my tendons. then they seized! this continued for the remainder of the marathon where i would walk then try to run and then stop when i had to. then during the entirety of the pace my nose would not stop dripping making it difficult to breathe. ha! also my shorts almost came down twice and i had to re-tie them while carrying my handheld water in my teeth. seriously, so many things i did not expect and had not happened in any previous runs.
really happy to be able to eat spicy food and have some alcoholic beverages again though!
#running #race
MacOS Sonoma 14.3.1 Update Fixes Text Overlap Bug on Macs
iOS 17.3.1 and iPadOS 17.3.1, which fixes the same bug on iPhone and iPad, and watchOS 10.3.1, which resolves the bug on Apple Watch. How to Download & Install MacOS Sonoma 14.3.1 Update Be sure you backup the Mac to Time Machine before beginning any software update. Go to the Apple menu Choose “System … Read More ⌘ Read more
Linux Sucks 2024
“This is going to suck more than anything has sucked before.” ⌘ Read more
Linux Sucks 2024 – Where (and how) to Watch
(This is going to suck more than anything has sucked before.) ⌘ Read more
Go 1.22 is released!
1 points posted by Everton Marques ⌘ Read more
Go Gin 框架中間件中使用 Goroutine 的正確姿勢
在 Go 語言的 Gin 框架中,中間件和處理函數是處理 HTTP 請求的核心。有時候,我們需要在這些函數中啓動新的 Goroutine 來執行併發任務。然而,在 Goroutine 中直接使用 Gin 的上下文(gin.Context)可能會導致競態條件,因爲 Gin 的上下文不是併發安全的。本文將詳細介紹如何在 Gin 中間件或處理函數中正確地使用 Goroutine,並提供示例代碼來說明如何 ⌘ Read more
Go 防止流量過載的利器——限流組件
*一、服務流量限制的重要性隨着業務規模的增長, 服務的流量也會激增, 大流量可能會壓垮服務器, 導致服務癱瘓。因此需對服務的流量進行限制, 確保在大流量的情況下也能正常運行。當流量激增時, 會佔用大量服務器資源和帶寬, 可能會壓垮整個系統。比如流量激增期間數據庫連接用盡, 會導致服務無法訪問數據庫而宕機。用限制流量可以有效防止流量暴增壓垮系統。沒有限流時, 流量激增期間會啓動很多無用的任務佔用服務 ⌘ Read more
Go Gin 項目記錄日誌的最佳實踐
在任何一個複雜的軟件項目中,日誌記錄是必不可少的。無論是調試程序、監控系統狀態,還是統計用戶行爲,日誌都扮演了重要的角色。在 Go 的世界裏,Gin 是一種快速,簡單,靈活,優雅的 Web 框架,同時也提供了豐富的日誌記錄功能。本文將分享在 Gin 項目中如何進行高效的日誌記錄。創建 Gin 實例與中間件使用—————在創建 Gin 實例時,gin.Default()會默認加載 ⌘ Read more
使用 Go 打造百億級文件系統的實踐之旅
JuiceFS 企業版是一款爲雲環境設計的分佈式文件系統,單命名空間內可穩定管理高達百億級數量的文件。構建這個大規模、高性能的文件系統面臨衆多複雜性挑戰,其中最爲關鍵的環節之一就是元數據引擎的設計。JuiceFS 企業版於 2017 年上線,經過幾年的不斷迭代和優化,在單個元數據服務進程使用 30 GiB 內存的情況下,能夠管理約 3 億個文件,並將元數據請求的平均處理時間維持在 100 微秒量級 ⌘ Read more
Go1-22 新特性:增強 http-ServerMux 路由能力,將有更強的表現力!
大家好,我是煎魚。Go1.22 有一個比較重要的新特性,那就是基於提案《net/http: enhanced ServeMux routing[1]》,增強了 http.ServerMux 的路由匹配能力。非常值得大家學習和關注。本次的新特性主要是新增了 HTTP 方法和路徑變量的支持。快速學習—-在 Go 中,可以認爲幾乎所有的路由相關的庫都會基於 net/http 或是兼容其 interf ⌘ Read more
收到請求數據的常用安全驗證方案,go 語言,gin 框架
在使用 Gin 框架處理前端請求數據時,必須關注安全性問題,以防範常見的攻擊。本文將探討 Gin 框架中常見的安全問題,並提供相應的處理方法,以確保應用程序的穩健性和安全性。第一章:概述———-1.1 安全性的重要性處理前端請求數據時,確保應用程序的安全性是至關重要的。常見的攻擊方式包括 SQL 注入、跨站腳本攻擊(XSS)、跨站請求僞造(CSRF)等。下面我們將逐一探討這些問題及其處 ⌘ Read more
Go 語言通知協程退出 -取消- 的幾種方式
在 Go 語言中,控制 goroutine 的退出或取消很重要,這能使資源得到合理利用,避免潛在的內存泄露。如下是一些在 Go 中通知協程退出的常見方式:使用通道(Channel):通過發送特定的信號或關閉通道來通知協程退出。這是最簡單直接的方法。 使用 context 包:context 包提供了一種更標準化的方式來傳遞取消信號、超時、截止時間等控制信息。 使用 sync.Wait ⌘ Read more
@prologic@twtxt.net ahhh! Its the dark reader plugin breaking the page.
Twtxt spec enhancement proposal thread 🧵
Adding attributes to individual twts similar to adding feed attributes in the heading comments.
https://git.mills.io/yarnsocial/go-lextwt/pulls/17
The basic use case would be for multilingual feeds where there is a default language and some twts will be written a different language.
As seen in the wild: https://eapl.mx/twtxt.txt
The attributes are formatted as [key=value]
They can show up in the twt anywhere it is not enclosed by another element such as codeblock or part of a markdown link.
> ?
@sorenpeter@darch.dk this makes sense as a quote twt that references a direct URL. If we go back to how it developed on twitter originally it was RT @nick: original text because it contained the original text the twitter algorithm would boost that text into trending.
i like the format (#hash) @<nick url> > "Quoted text"\nThen a comment
as it preserves the human read able. and has the hash for linking to the yarn. The comment part could be optional for just boosting the twt.
The only issue i think i would have would be that that yarn could then become a mess of repeated quotes. Unless the client knows to interpret them as multiple users have reposted/boosted the thread.
The format is also how iphone does reactions to SMS messages with +number liked: original SMS
Got a Dr checkup and the screw in my hand hasn’t moved. That’s the good news. Bad news is that there seems to be something going on with the internal healing. Nothing to do but wait.
Late fees for public libraries are not fines, they’re extra donations to keep the organisation going.
使用 Go Gin SecureJSON 技術保護你的 JSON 數據
網絡上的安全問題一直是不能小覷的難題,尤其在 web 開發中,JSON 劫持就是其中的一種。這篇文章,我們將聚焦在 Go 框架 Gin 下的 SecureJSON 使用,來保護我們的 JSON 數據。什麼是 JSON 劫持?————JSON 劫持是一種網絡攻擊手段,攻擊者利用 JavaScript 的這個特性獲取到不屬於自己的數據。由於 JSON 數據一般包含非常敏感的個人信息,例 ⌘ Read more
替代 zap,Go 語言官方實現的結構化日誌包
在 Go 1.21 中,引入了一個新的 log 包 – log/slog,這是一個強大的日誌記錄庫,提供了許多用於幫助開發人員更加有效地記錄、管理和理解日誌的工具。無論你是一個初級還是高級的 Go 開發人員,理解和掌控 go 的日誌系統是非常有用的。接下來,讓我們深入研究一下 Go 中的日誌行爲,並通過實例來詳細理解每個主要功能。安裝–在 Go 1.21 中,log/slog 是系統自帶的,無 ⌘ Read more
Wasm on Go
本篇內容,是對極客兔兔: Go WebAssembly (Wasm) 簡明教程 [1] 的實踐與記錄,主體內容來自這篇博客,推薦閱讀原文。 是否需要搭建 wasm 環境? WebAssembly 上手 [2]如果是 C/C++,需要藉助 emcc,將 C 和 C++ 代碼編譯到 WebAssembly 和 JavaScript。在 Mac 上,brew install emscripten然後 ⌘ Read more
Go Web 開發不得不說的請求路由
*1. 請求路由的概念請求路由的定義:請求路由是指將客戶端的請求與服務器上對應的處理程序匹配和映射的過程。它決定了不同的 URL 或 API 請求被映射到哪些處理函數。請求路由的作用:請求路由實現了請求與處理函數之間的解耦,使代碼更加模塊化。同時,它也使得 URL 和 API 更符合 RESTful 設計規範。請求路由還可以實現諸如負載均衡、緩存、日誌記錄、身份驗證等功能。2. net/http ⌘ Read more
使用 Go 發送微信羣消息
背景最近的某個副業需要我寫一個腳本(腳本內容就不說了),需要通知羣成員,儘快地做出響應。所以去找一下 Go 是否有這樣的類庫。在這個腳本里面,我只需要發送信息的能力即可。openwechat在尋找了一會之後發現 https://github.com/eatmoreapple/openwechat 這個庫,這個庫支持以下能力:消息回覆、給指定對象(好友、羣組)發送文本、圖片、文件、emoji 表情等 ⌘ Read more
Go 實現多租戶示例
在 Go 中實現多租戶 (multi-tenancy) 通常涉及到下面幾個關鍵步驟:租戶識別: 你需要一個機制來區分請求是針對哪個租戶的。這可以通過多種策略實現,比如在 HTTP 請求的 URL、Header 或者是 Cookie 中嵌入租戶 ID。 數據隔離: 根據你選擇的數據隔離策略(如數據庫、schema 或者數據表的隔離),你需要確保租戶只能訪問到屬於他們的數據。 中間件 / ⌘ Read more
Go Gin 框架實現優雅地重啓和停止
在 Web 應用程序中,有時候我們需要重啓或停止服務器,無論是因爲更新代碼還是進行例行維護。在這種情景下,我們需要保證應用程序的可用性和數據的一致性。這就需要優雅地關閉和重啓應用程序,即不丟失正在處理的請求和不拒絕新的請求。在本文中,我們將詳解如何在 Go 語言中使用 Gin 這個框架實現優雅的重啓和停止。什麼是優雅重啓和停止———-優雅地重啓或停止一個 Web 服務就是指當我們需要更 ⌘ Read more
史上最詳細的 Gin 中間件使用教程
在本文中,我們將深入討論 Go-Gin 的中間件,詳細瞭解它們呈現如何有效地在任何特定的 Web 應用程序中插播操作。此外,我們還將瀏覽一些示例,幫助大家更好地理解。什麼是中間件?——-在討論 Gin 中間件之前,首先我們需要明確中間件的概念。中間件基本上是一個函數,它在您的應用程序收到請求和發送響應之間插播處理。在實際開發中,中間件被廣泛用於處理如日誌記錄、身份驗證、會話管理等方面。Gi ⌘ Read more
圖文講透 Golang 標準庫 net-http 實現原理 – 服務端
前言今天分享下 Go 語言 net/http 標準庫的內部實現邏輯,文章將從客戶端 (Client)– 服務端(Server) 兩個方向作爲切入點,進而一步步分析 http 標準庫內部是如何運作的。由於會涉及到不少的代碼流程的走讀,寫完後覺得放在一篇文章中會過於長,可能在閱讀感受上會不算很好,因此分爲【Server–Client 兩個篇文章】進行發佈。本文內容是【服務端 Server 部分】, ⌘ Read more
Go 司空見慣的錯誤檢測,原來還有這麼多幹貨-
*一、錯誤處理機制Go 語言以結果多值返回方式處理錯誤, 函數或者方法最後一個返回值作爲錯誤類型。func ReadFile(filename string) ([]byte, error)調用時根據錯誤值判斷是否正常data, err := ReadFile(“abc.txt”)if err != nil { // 處理錯誤} else { // 處理data}error 類型及其意義 ⌘ Read more
ebpf-go 初體驗
前言我們在《用 eBPF/XDP 來替代 LVS》系列、《一張圖感受真實的 TCP 狀態轉移》系列,以及《如何終結已存在的 TCP 連接?》系列文章中,均通過純 C 語言和 libbpf1 這個庫來運用 eBPF。但是很多的場景中(尤其是雲原生場景),我們出於避免重複造輪子、更快的迭代速度、運行時安全等原因,會選擇 go 語言來進行開發,ebpf-go2 這個庫就是當前最好的選擇。今天,我們就對 ⌘ Read more
Pinellas County - Long Run (part I): 11.63 miles, 00:09:54 average pace, 01:55:08 duration
did not really want to run today. but i did it anyways and it felt fin until my dumb ass decided to go over one of the clearwater bridges. took everything out of me after those hills and had a hard time getting the legs moving again.
#running
Go 使用 cmux 實現網絡端口複用
cmux 的作用——– 一般情況下, 每個端口只能爲一個服務所用, 如果複用, 會報 “port is already in use”如果需要複用某個端口, 那麼可以使用 cmux 來實現 (其實大多數情況下必要性不大. 比如我就圖 8888 端口吉利, http/grpc 等服務都用這個端口)cmux[1] 全稱 Connection Mux, 是 Go 生態來複用端口的庫, 可 ⌘ Read more
GitHub Fund 2024 and beyond: Looking to the future
Celebrate the first year of GitHub Fund, our first investments, and a brief look of where we’re going.
The post GitHub Fund 2024 and beyond: Looking to the future appeared first on The GitHub Blog. ⌘ Read more
Go 信號 - 守護進程開發爬坑指南
*一、信號 (signal) 處理信號是 Linux 系統下進程間通信的一種限制式異步通知機制。一個信號可以傳遞一個事件通知給一個進程, 代表一個異步事件。Go 語言內置了對信號的支持, 通過 os/signal 包可以實現 Go 程序對信號的處理。1.1 什麼是信號信號 (Signal) 是 Linux 系統下進程間通信的一種方式。當某個事件發生時, 內核會通知進程一個信號。進程接收到信號後, ⌘ Read more
Go 一文帶你喫透 HTTP 客戶端!
*1. HTTP 請求簡介HTTP(Hypertext Transfer Protocol) 是構建 web 應用通信的基石。HTTP 工作於客戶端 - 服務端架構上。HTTP 客戶端發起請求, 服務器接收請求並返回響應。HTTP 請求主要由請求行、請求頭、請求體組成請求行 GET /search?name=Golang HTTP/1.1請求頭部 Host: www.baidu ⌘ Read more
Go 定時器:Timer 和 Ticker
前言在日常開發中,我們可能會遇到需要延遲執行或週期性地執行一些任務。這個時候就需要用到 Go 語言中的定時器。在 Go 語言中,定時器類型有兩種:time.Timer 一次性定時器和 time.Ticker 週期性定時器。本文將會對這兩種定時器類型進行介紹。準備好了嗎?準備一杯你最喜歡的咖啡或茶,隨着本文一探究竟吧。Timer:一次性定時器Timer 是一個一次性的定時器,用於在未來的某一時刻執行 ⌘ Read more
Discovery Zone – All Dressed Up With Nowhere to Go
Discovery Zone shares another enchanting track + video from her forthcoming LP Quantum Web, coming in March on limited hologram edition LP via RVNG Intl… Continue reading… ⌘ Read more
千萬級高性能長連接 Go 服務架構實踐
作者 | glstr導讀 introduction移動互聯網時代,長連接服務成爲了提升應用實時性和互動性的基礎服務。本文主要介紹了百度系內基於 golang 實現的統一長連接服務。主要從統一長連接功能實現和性能優化等角度,描述了統一長連接服務在設計、開發和維護過程中面臨的問題和挑戰,重點介紹瞭解決相關問題和挑戰的解決方案和實踐經驗。01摘要移動互聯網時代,用戶對服務的實時性、互動性有了更高的要求, ⌘ Read more
Go 語言實戰:構建強大的延遲任務隊列
01 介紹延遲隊列是一種數據結構,用於處理需要在未來某個特定時間執行的任務。這些任務被添加到隊列中,並且指定了一個執行時間,只有到達指定的時間點時才能從隊列中取出並執行。在實際應用中,延遲隊列可以用於處理各種需要延遲處理的任務,例如發送郵件提醒、訂單自動取消、對超時任務的處理等。由於任務的執行是在未來的某個時間點,因此這些任務不會立即執行,而是存儲在隊列中,直到它的預定執行時間纔會被執行。02 S ⌘ Read more
Pinellas County - Long Run: 17.80 miles, 00:08:57 average pace, 02:39:13 duration
practiced a marathon pacing strategy (simulated) of 5km/10mi/10mi/5km. went pretty well even though i was going faster than the paces at each step. but overall i felt good. also scouted out one of the two overpasses i will have to climb during the race. definitely nothing compared to the regular ones. freezing! started at 33F and ended at 45F. pretty lonely out there because the cold kept everyone inside.
#running
Georgie & Joe – Student
East London duo Georgie & Joe go extremely hard out of the gates on their debut single “ Student”, a massive, gleaming escapist anthem that oscillates from straight-up dance-pop banger to ethereal dreamscape and back in just over 3 exhilarating minutes… Continue reading… ⌘ Read more
基於 go 實現 lsm tree 之主幹框架
0 導讀去年 4 月的時候,我和大家分享了一篇文章——初探 rocksDB 之 lsm tree,和大家一起探討了 lsm tree 結構的底層實現原理. 秉着 【基於源碼支撐原理】 的一貫原則,從本期開始,咱們把源碼篇的坑填上.接下來我將開啓一個新的專題——基於 go 語言從零到一實現 lsm tree,本專題共分爲下述四篇內容:• 基於 go 實現 lsm tree 之主幹框架(本篇) ⌘ Read more
Go 語言與 gRPC 的完美結合
*一、gRPC 簡介gRPC(Remote Procedure Call) 是一種遠程過程調用技術, 通過壓縮和序列化數據來優化網絡通信, 可以顯著提高服務調用的性能和效率。gRPC 的概念gRPC 是一個高性能、通用的開源 RPC 框架, 是一個由 Google 主導開發的 RPC 框架。其以 HTTP/2 爲基礎通信協議, 支持多種語言, 通過 protocol buffers 數據格式來實現 ⌘ Read more
Pinellas County - 90’ (part I): 4.53 miles, 00:08:41 average pace, 00:39:21 duration
whoa this run felt great. seemed very fun effort while the heart rate was relatively low with a nice pace. it was very cold out, 42F with a wind chill of 38F, but it didn’t matter once the engine was going. unfortunately, halfway through the run code brown sirens were blaring and had to cut it short.
#running