Searching txt.sour.is

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

GVM: Golang 多版本管理利器
本文介紹了 Go Version Manager 的功能和使用方法,介紹瞭如何通過 GVM 在系統上安裝和管理多個 Go 語言版本。原文: GVM: Go Version Manager, for Golang manage multiple versions[1]Go 版本管理器(GVM,Go Version Manager)是一款功能強大的工具,旨在簡化系統中 Go 編程語言不同版本的管理 ⌘ Read more

⤋ Read More

Go 語言 API 文檔利器:絲襪哥(Swagger)保姆級使用指南大揭祕!
咱們都知道在 API 開發中,文檔是必不可少的一環。swaggo/swag 是一個用於 Go 語言的自動化生成 API 文檔的工具,它可以將代碼註釋轉換爲 Swagger 文檔,方便開發者和用戶理解 API 的使用方法。本文將詳細介紹 swaggo/swag 的使用方式以及它的特性。1. 安裝 Swaggo/Swag先在你的 Go 項目中安裝 swag 命令行工具和 gin-swagger 依賴: ⌘ Read more

⤋ Read More

構建由大型語言模型(LLM)驅動的 Go 應用程序
隨着過去一年大型語言模型(LLM)及其相關工具(如嵌入模型)的能力顯著增長,越來越多的開發者開始考慮將 LLM 集成到他們的應用程序中。由 於 LLM 通常需要專用硬件和大量的計算資源,它們最常見的形式是作爲提供 API 訪問的網絡服務。這就是領先的 LLM 如 OpenAI 或 Google Gemini 的 API 的工作方式;即使是運行你自己的 LLM 工具,如 Ollama[1],也會將 ⌘ Read more

⤋ Read More

Go 語言實現 systemctl 管理系統服務
在 Linux 系統中,systemd 已然成爲主流的初始化系統和服務管理器,而 systemctl 命令則是我們與之交互的橋樑。對於 Go 開發者而言,直接使用 Shell 調用 systemctl 固然可行,但難免顯得不夠優雅,並且需要編寫額外的代碼來解析命令輸出。爲解決這一問題,taigrr/systemctl 庫應運而生。它爲 Go 開發者提供了符合習慣用法的 systemctl  綁定, ⌘ Read more

⤋ Read More

Go 構建一個簡單的負載均衡器
Go–負載均衡器在現代軟件開發中至關重要。作爲開發者你肯定好奇過請求是如何在多個服務器之間分配的,或者爲什麼某些網站即使在高流量時也感覺更快,這就是負載均衡器的作用。沒有負載均衡器在這篇文章中,我們將使用 Go 語言構建一個簡單的應用程序負載均衡器,使用輪詢算法(Round Robin)。這篇文章的目的是一步步理解負載均衡器的內部工作原理。什麼是負載均衡器?負載均衡器是一個系統,它將傳入的網絡流 ⌘ Read more

⤋ Read More
In-reply-to » @bender I should put the template that is used by default as a file in the repo. Look at the source for now and you'll see 😅

@aelaraji@aelaraji.com this is my change on main.go (but it can be done on a template now, so no reason to touch the code):

                                 <time class="dt-published" datetime="{{ $twt.Created | date "2006-01-02T15:04:05Z07:00" }}">
                                        {{ $twt.Created | date "2006-01-02 15:04:05 MST" }}
                                  </time>

See https://ferengi.one. I am going to further customise things, but that’s a start.

⤋ Read More
In-reply-to » Now WTF!? Suddenly, @falsifian's feed renders broken in my tt Python implementation. Exactly what I had with my Go rewrite. I haven't touched the Python stuff in ages, though. Also, tt and tt2 do not share any data at all.

@lyse@lyse.isobeef.org Sorry, I don’t think I ever had charset=utf8. I just noticed that a few days ago. OpenBSD’s httpd might not support including a parameter with the mime type, unfortunately. I’m going to look into it.

⤋ Read More
In-reply-to » @movq Non-ASCII characters were broken. Like U+2028, degrees (°), etc.

Now WTF!? Suddenly, @falsifian@www.falsifian.org’s feed renders broken in my tt Python implementation. Exactly what I had with my Go rewrite. I haven’t touched the Python stuff in ages, though. Also, tt and tt2 do not share any data at all.

By any chance, did you remove the ; charset=utf-8 from your Content-Type: text/plain header, falsifian?

Image

⤋ Read More
In-reply-to » Hmmmm, I somehow run into an encoding problem where my inserted data end up mangled in the database. But, both SQLite and Go use UTF-8. What's happening here? :-?

@movq@www.uninformativ.de Non-ASCII characters were broken. Like U+2028, degrees (°), etc.

Turns out I used a silly library to detect the encoding and transform to UTF-8 if needed. When there is no Content-Type header, like for local files, it looks at the first 1024 bytes. Since it only saw ASCII in that region, the damn thing assumed the data to be in Windows-1252 (which for web pages kinda makes sense):

// TODO: change default depending on user's locale?
return charmap.Windows1252, "windows-1252", false

https://cs.opensource.google/go/x/net/+/master:html/charset/charset.go;l=102

This default is hardcoded and cannot be changed.

Trying to be smart and adding automatic support for other encodings turned out to be a bad move on my end. At least I can reduce my dependency list again. :-)

I now just reject everything that explicitly specifies something different than text/plain and an optional charset other than utf-8 (ignoring casing). Otherwise I assume it’s in UTF-8 (just like the twtxt file format specification mandates) and hope for the best.

⤋ Read More
In-reply-to » (#o) @prologic this was your first twtxt. Cool! :-P

@movq@www.uninformativ.de I figured it will be something like this, yet, you were able to reply just fine, and I wasn’t. Looking at your twtxt.txt I see this line:

2024-09-16T17:37:14+00:00	(#o6dsrga) @<prologic https://twtxt.net/user/prologic/twtxt.txt>

@<quark https://ferengi.one/twtxt.txt> This is what I get. 🤔

Which is using the right hash. Mine, on the other hand, when I replied to the original, old style message (Message-Id: <o6dsrga>), looks like this:

2024-09-16T16:42:27+00:00	(#o) @<prologic https://twtxt.net/user/prologic/twtxt.txt> this was your first twtxt. Cool! :-P

What did you do to make yours work? I simply went to the oldest @prologic@twtxt.net’s entry on my Maildir, and replied to it (jenny set the reply-to hash to #o, even though the Message-Id is o6dsrga). Since jenny can’t fetch archived twtxts, how could I go to re-fetch everything? And, most importantly, would re-fetching fix the Message-Id:?

⤋ Read More

Apple Releases tvOS 18 With InSight, New Screen Savers and More
Apple today released tvOS 18, the newest version of the tvOS operating system that runs on the Apple TV 4K and ‌Apple TV‌ HD models.

Image

tvOS 18 can be downloaded using the Settings app on the ‌‌Apple TV‌‌. Open up Settings and go to System > Software Update to get the new software. ‌‌Apple TV‌‌ owners who have automatic softwa … ⌘ Read more

⤋ Read More

Something odd just happened to my twtxt timeline… A bunch of twts dissapered, others were marked to be deleted in mutt. so I nuked my whole twtxt Maildir and deleted my ~/.cache/jenny in order to start with a fresh Pull. I pulled feed as usual. Now like HALF the twts aren’t there 😂 even my my last replay. WTF IS GOING ON? 🤣🤣🤣

⤋ Read More

使用 Go 語言生成樣式美觀的 PDF 文件
在當今數字化時代,PDF 已成爲一種不可或缺的文檔格式,它能夠在各種平臺上保持一致的顯示效果。然而,使用傳統的編程語言生成 PDF 文件往往是一項繁瑣而複雜的任務。Maroto 的出現爲 Go 語言開發者帶來了福音,它提供了一種簡潔優雅的方式來創建結構清晰、樣式美觀的 PDF 文檔。Maroto 簡介———Maroto 是一個基於 Go 語言的 PDF 生成庫,其靈感來源於 Boots ⌘ Read more

⤋ Read More

探索 Goja: 一個 Golang JavaScript 運行時
本文探討了 Golang 生態系統中的 JavaScript 運行時庫  Goja[1] 。Goja 作爲一個在 Go 應用程序中嵌入 JavaScript 的強大工具脫穎而出, 在操作數據和提供無需 go build 步驟的 SDK 方面具有獨特優勢。背景: 爲什麼需要 Goja在我的項目中, 在查詢和操作大型數據集時遇到了挑戰。最初, 所有內容都是用 Go 編寫的, 這很高效, 但在處理複雜的 ⌘ Read more

⤋ Read More

開源免費定時任務管理系統 Gocron
概覽–Gocron 是一個開源免費的定時任務管理系統。它使用 Go 語言開發,是一個輕量級定時任務集中調度和管理系統,用於替代 Linux-crontab,旨在爲開發者及運維人員提供一個高效、輕量級且用戶友好的任務調度解決方案。作爲 Linux-crontab 的現代化替代品,Gocron 不僅繼承了傳統定時任務管理的靈活性,還融入了強大的 Web 界面管理功能,使得任務配置、監控與維護變得前所 ⌘ Read more

⤋ Read More

Go1-23 新特性:再開後門,可以記錄未捕獲的 panic 和 throw 日誌了!
大家好,我是煎魚。今天繼續給大家分享 Go1.23 的新特性,這一輪裏還是有不小有意思的驚喜的。其中不得不評本文中的這個新變化。必須得來一篇獨立話題來提一下這個事!過去學習寫 Go 時,初學者入門的教程教一定會提到在使用 panic 時,強烈建議要使用 recover。否則在 goroutine 的場景下很容易出問題,也會導致記不來日誌。新版本後,終於有兜底 Go 程序崩潰的日誌記錄方法了!過於感 ⌘ Read more

⤋ Read More

Things to do in Salt Lake City
With KubeCon + CloudNativeCon North America 2024 just a few months away we thought it would be fun to ask our ambassadors and other locals about where to go and what to do while we’re all in Salt… ⌘ Read more

⤋ Read More

函數類型的 Range - Go 編程語言
簡介 —–這是我在 2024 年 GopherCon 大會上演講的博客文章版本。函數類型的 range 是 Go 1.23 版本中的一個新語言特性。這篇博文將解釋爲什麼我們要添加這個新特性, 它究竟是什麼, 以及如何使用它。爲什麼?—-自 Go 1.18 以來, 我們已經能夠在 Go 中編寫新的泛型容器類型。例如, 讓我們考慮這個非常簡單的Set類型, 一個基於 map 實現的泛型類型 ⌘ Read more

⤋ Read More
In-reply-to » On the Subject of Feed Identities; I propose the following:

So this is a great thread. I have been thinking about this too.. and what if we are coming at it from the wrong direction? Identity being tied to a given URL has always been a pain point. If i get a new URL its almost as if i have a new identity because not only am I serving at a new location but all my previous communications are broken because the hashes are all wrong.

What if instead we used this idea of signatures to thread the URLs together into one identity? We keep the URL to Hash in place. Changing that now is basically a no go. But we can create a signature chain that can link identities together. So if i move to a new URL i update the chain hosted by my primary identity to include the new URL. If i have an archived feed that the old URL is now dead, we can point to where it is now hosted and use the current convention of hashing based on the first url:

The signature chain can also be used to rotate to new keys over time. Just sign in a new key or revoke an old one. The prior signatures remain valid within the scope of time the signatures were made and the keys were active.

The signature file can be hosted anywhere as long as it can be fetched by a reasonable protocol. So say we could use a webfinger that directs to the signature file? you have an identity like frank@beans.co that will discover a feed at some URL and a signature chain at another URL. Maybe even include the most recent signing key?

From there the client can auto discover old feeds to link them together into one complete timeline. And the signatures can validate that its all correct.

I like the idea of maybe putting the chain in the feed preamble and keeping the single self contained file.. but wonder if that would cause lots of clutter? The signature chain would be something like a log with what is changing (new key, revoke, add url) and a signature of the change + the previous signature.

# chain: ADDKEY kex14zwrx68cfkg28kjdstvcw4pslazwtgyeueqlg6z7y3f85h29crjsgfmu0w 
# sig: BEGIN SALTPACK SIGNED MESSAGE. ... 
# chain: ADDURL https://txt.sour.is/user/xuu
# sig: BEGIN SALTPACK SIGNED MESSAGE. ...
# chain: REVKEY kex14zwrx68cfkg28kjdstvcw4pslazwtgyeueqlg6z7y3f85h29crjsgfmu0w
# sig: ...

⤋ Read More
In-reply-to » On the Subject of Feed Identities; I propose the following:

@mckinley@twtxt.net To answer some of your questions:

Are SSH signatures standardized and are there robust software libraries that can handle them? We’ll need a library in at least Python and Go to provide verified feed support with the currently used clients.

We already have this. Ed25519 libraries exist for all major languages. Aside from using ssh-keygen -Y sign and ssh-keygen -Y verify, you can also use the salty CLI itself (https://git.mills.io/prologic/salty), and I’m sure there are other command-line tools that could be used too.

If we all implemented this, every twt hash would suddenly change and every conversation thread we’ve ever had would at least lose its opening post.

Yes. This would happen, so we’d have to make a decision around this, either a) a cut-off point or b) some way to progressively transition.

⤋ Read More
In-reply-to » On the Subject of Feed Identities; I propose the following:

@prologic@twtxt.net Some criticisms and a possible alternative direction:

  1. Key rotation. I’m not a security person, but my understanding is that it’s good to be able to give keys an expiry date and replace them with new ones periodically.

  2. It makes maintaining a feed more complicated. Now instead of just needing to put a file on a web server (and scan the logs for user agents) I also need to do this. What brought me to twtxt was its radical simplicity.

Instead, maybe we should think about a way to allow old urls to be rotated out? Like, my metadata could somehow say that X used to be my primary URL, but going forward from date D onward my primary url is Y. (Or, if you really want to use public key cryptography, maybe something similar could be used for key rotation there.)

It’s nice that your scheme would add a way to verify the twts you download, but https is supposed to do that anyway. If you don’t trust https to do that (maybe you don’t like relying on root CAs?) then maybe your preferred solution should be reflected by your primary feed url. E.g. if you prefer the security offered by IPFS, then maybe an IPNS url would do the trick. The fact that feed locations are URLs gives some flexibility. (But then rotation is still an issue, if I understand ipns right.)

⤋ Read More

如何實現限制用戶 1 分鐘內最多請求 1000 次?
在高併發場景下,如何保護你的服務不被海量請求壓垮?限流器是你的不二之選。本文將帶你使用 Go 語言,實現一個高效的限流器,限制每分鐘內用戶的最大請求次數。限流算法的選擇——-常見的限流算法有很多,例如:計數器算法: 設定一個時間窗口,在窗口內對請求進行計數,超過閾值則拒絕請求。 漏桶算法: 將請求想象成水滴,漏桶以固定速率漏水,溢出則拒絕請求。 令牌桶算法: 以固定速率生成令牌 ⌘ Read more

⤋ Read More
In-reply-to » When we passed a few horses in the forest, there was really strong soup odor in the air. It didn't smell like horse at all, but soup. Maybe they've been soup horses, chickens were out of stock.

@lyse@lyse.isobeef.org 31°C here, feels like 33°C, with a lovely 75% of humidity. It has been raining, on and off (to make matter “better”) the whole day until now. No horses here, but if you go outside you will smell the same smell of farm animals (like goats, or pigs). That’s because two or three kilometres from here there are private farms, and when the wind blows in such way, well, we are reminded of their existence.

I haven’t left the house, so it feels well under air conditioning. In two more hours I will call it quits from the work day, and will have to dash to the grocery to get supplies for tonight’s meal (arroz con gandules). I will let you know how it truly feels out there then. :-D

For those swollen fingers, nothing better than a mildly cold shower! Oh, and paws off the keyboard! :-P

⤋ Read More

When we passed a few horses in the forest, there was really strong soup odor in the air. It didn’t smell like horse at all, but soup. Maybe they’ve been soup horses, chickens were out of stock.

29°C, zero wind, extremely humid, luckily the sun was behind the clouds. I’m soaking wet, sweat ran down in streams and dripped in my eyes, it burned a bit. The sky is getting a little dark, I hope the thunderstorm and rain are really arriving here later. Rain had always been finally cancelled the couple last days.

I’m gotta go cool off my fingers now, they’re swollen from the heat.

⤋ Read More
In-reply-to » Serious open (for anyone) question: what makes you follow someone on twtxt? Will you just follow anyone that you come across, simply because that someone using the "decentralised, minimalist microblogging service for hackers" microblog?

@bender@twtxt.net On twtxt, I follow all feeds that I can find (there are some exceptions, of course). There’s so little going on in general, it hardly matters. 😅

And I just realized: Mutt’s layout helps a lot. Skimming over new twts is really easy and it’s not a big loss if there are a couple of shitposts™ in my “timeline”. This is very different from Mastodon (both the default web UI and all clients I’ve tried), where the timeline is always huge. Posts take up a lot of space on screen. Makes me think twice if I want to follow someone or not. 😅

(I mostly only follow Hashtags on Mastodon anyway. It’s more interesting that way.)

⤋ Read More

橋接 Rust 和原生 Go
你好,大家好,我是 yuchanns!最近我做了一些有趣的事情,想和你分享:介紹 OpenDAL 作爲 Go 語言的原生綁定。 TLDR;  我將向你展示一種可行的方法,利用 purego 和 libffi 的魔力,從 Rust 和 C 組件構建原生 Go 綁定。什麼是 OpenDAL?————Apache OpenDAL[1] 是一個 Rust 庫,提供了統一的數據訪問層。它爲 ⌘ Read more

⤋ Read More

Golang - 使用 GoFakeIt 生成 Mock 數據
介紹–在軟件開發中,測試至關重要,以確保代碼能夠按預期工作。然而出於隱私考慮、數據可用性以及收集和清理數據,使用真實數據進行測試是不合理的。我們需要生成 Mock 數據來進行測試。在 Go 編程語言中,用於生成假數據的最流行庫之一是 GoFakeIt[1]。什麼是 GoFakeIt?————-GoFakeIt 是一個強大的庫,允許開發人員爲測試目的生成各種隨機數據。它支持創建名字 ⌘ Read more

⤋ Read More

用 Go 語言構建輕量級 ChatGPT 網頁版
近年來,大型語言模型(LLM)的快速發展徹底改變了人機交互的方式。ChatGPT 作爲其中的佼佼者,憑藉其強大的自然語言處理能力,在各個領域都展現出巨大的應用潛力。然而,對於開發者而言,構建自己的 ChatGPT 應用往往需要耗費大量的時間和資源。Ollama 和 Ollamaweb 的出現爲開發者提供了一個快速構建類 ChatGPT 應用的解決方案。Ollama 是一款開源的 LLM 服務,它支 ⌘ Read more

⤋ Read More

Go 機器學習框架之火重燃,Google 前研究員開源期望媲美 Jax 的 GoMLX
Go 作爲一門兼具高性能與簡潔性的編程語言,近年來在各種領域得到廣泛應用。然而,在機器學習領域,Go 相比 Python、C++、Julia 等語言,生態仍然較爲薄弱。目前的 Go 機器學習框架無論在功能全面性上,還是在社區生態支持上都難以與 TensorFlow、PyTorch、Jax 等重量級框架抗衡。究其原因,筆者覺得還是 Go 社區缺少熟悉和精通機器學習方面的人才。不過,隨着時間的推移,總 ⌘ Read more

⤋ Read More

Go 語言實現 Windows 守護進程
在 Windows 系統中,守護進程(Windows Service)扮演着不可或缺的角色,默默地執行着後臺任務,保障着系統的穩定運行。本文將深入探討如何利用 Go 語言簡潔高效地構建 Windows 守護進程,並輔以詳細的代碼示例,助你輕鬆掌握這一實用技能。Windows 守護進程:幕後的無名英雄——————–不同於我們日常使用的應用程序,Windows 守護進程沒有華 ⌘ Read more

⤋ Read More

Go 熱重載:使用 Air 改變你的開發流程
在 Go 語言開發中,每次修改代碼後都需要手動重啓服務,這無疑是一件效率低下的事情。本文將介紹一款名爲 Air 的工具,它可以幫助我們實現 Go 代碼的熱重載,從而極大地提升開發效率。手動重啓的煩惱——-假設我們有一個運行中的 Go 程序,例如:go run main.go該程序可能使用 fsnotify 來監聽配置文件的變化,例如 config.json:{  ”dbhost”: ”lo ⌘ Read more

⤋ Read More

Go 語言函數的幕後:從符號表到棧幀
Go 函數是構建 Go 程序的基本模塊,我們每天都在使用它們,但你是否想過 Go 函數在編譯和運行時是如何工作的呢?本文將深入探討 Go 函數的內部機制,從符號表到棧幀,揭示 Go 函數運行的奧祕。函數的命名和符號表———在 Go 中,每個函數都有一個唯一的名稱,這是因爲 Go 編譯器會創建一個符號表來記錄所有變量和函數的名稱。當我們在代碼中定義一個函數時,它的名稱會被添加到符號表中。 ⌘ Read more

⤋ Read More

如何在 Go 中構建可插拔的庫
什麼是 go buildmode=plugin?————————go buildmode=plugin 選項允許開發者將 Go 代碼編譯成共享對象文件。另一個 Go 程序可以在運行時加載該文件。當我們想在應用程序中添加新功能而又不想重建它時,這個選項非常有用。可以將新功能作爲插件加載。Go 中的插件是編譯成共享對象(.so)文件的軟件包。可以使用 Go 中的 plu ⌘ Read more

⤋ Read More

Go 協程上下文切換的代價
在高併發場景下,Go 語言的協程 (Goroutine) 以其輕量級、高效的特性而聞名。但協程的上下文切換真的像想象中那樣輕量級嗎?它在性能上究竟有多大的優勢?本文將深入探討 Go 協程的上下文切換機制,分析其效率和潛在的代價。協程上下文切換的效率———-與傳統的線程相比,Go 協程的上下文切換髮生在用戶空間,避免了昂貴的系統調用,因此切換速度更快。實驗表明,Go 協程的上下文切換平均 ⌘ Read more

⤋ Read More

Builder 模式在 Go 語言中的應用
Builder 模式是一種創建型模式,即用來創建對象。Builder 模式,中文翻譯不太統一,有時候被翻譯爲建造者模式或構建者模式,有時候也被翻譯爲生成器模式。爲了不給讀者造成困擾,我還是直接叫它 Builder 模式好了。《設計模式:可複用面向對象軟件的基礎》 一書中對 Builder 模式的意圖闡明如下: 將一個複雜對象的構建與它的表示分離,使得同樣的構建過程可以創建不同的表示。經典 Bui ⌘ Read more

⤋ Read More
In-reply-to » @movq, maybe you can help me with this. I want to place the vim cursor at the end of the first line on replies, and forks. I have tried adding to this to jenny's configuration:

@movq@www.uninformativ.de hmm, I am already using au BufNewFile,BufRead jenny-posting.eml setl completefunc=jenny#CompleteMentions fo-=t wrap, from jenny. How would I go to incorporate that there?

⤋ Read More
In-reply-to » @movq, maybe you can help me with this. I want to place the vim cursor at the end of the first line on replies, and forks. I have tried adding to this to jenny's configuration:

@movq@www.uninformativ.de hmm, I guess I could do that too. I have startinsert set on my .vimrc, so I will either have to take it out, or exit insert, $, then insert again. I think the way you do it would be the way to go.

I tried setting VISUAL to be something like vim -c 'star!', which does the same thing, but no dice. :-/

⤋ Read More
In-reply-to » Telegram founder Pavel Durov arrested at French airport Article URL: https://www.theguardian.com/media/article/2024/aug/24/telegram-app-founder-pavel-durov-arrested-at-french-airport

@bender@twtxt.net and I saw some conspiracy theory that he knew he was going to be arrested. He was working with French intelligence on a plea deal to defect. And now Russia is freaking out that Ukraine allies can have war comms access.

Yikes! If only they had salty.im!

⤋ Read More

There is a bug in yarnd that’s been around for awhile and is still present in the current version I’m running that lets a person hit a constructed URL like

YOUR_POD/external?nick=lovetocode999&uri=https://socialmphl.com/story19510368/doujin

and see a legitimate-looking page on YOUR_POD, with an HTTP code 200 (success). From that fake page you can even follow an external feed. Try it yourself, replacing “YOUR_POD” with the URL of any yarnd pod you know. Try following the feed.

I think URLs like this should return errors. They should not render HTML, nor produce legitimate-looking pages. This mechanism is ripe for DDoS attacks. My pod gets roughly 70,000 hits per day to URLs like this. Many are porn or other types of content I do not want. At this point, if it’s not fixed soon I am going to have to shut down my pod. @prologic@twtxt.net please have a look.

⤋ Read More

Go 程序如何實現優雅退出?來看看 K8s 是怎麼做的——下篇
K8s 的優雅退出現在,我們已經掌握了 Go 中 HTTP Server 程序如何實現優雅退出,是時候看一看 K8s 中提供的一種更爲優雅的優雅退出退出方案了😄。這要從 K8s API Server 啓動入口說起: https://github.com/kubernetes/kubernetes/blob/release-1.31/cmd/kube-apiserver/apiserver.gofRead more

⤋ Read More

Go 程序如何實現優雅退出?來看看 K8s 是怎麼做的——上篇
在寫 Go 程序時,優雅退出是一個老生常談的問題,也是我們在微服務開發過程中的標配,本文就來介紹下工作中常見的幾種優雅退出場景,以及帶大家一起來看一下 K8s 中的優雅退出是怎麼實現的。優雅退出我們一般可以通過如下方式執行一個 Go 程序:$ go build -o main main.go$ ./main如果要停止正在運行的程序,通常可以這樣做:在正在運行程序的終端執行 Ctrl + C。 ⌘ Read more

⤋ Read More

golang 日誌打印 如何添加 goroutinei
在 Go 語言中,標準庫沒有直接提供獲取 goroutine ID 的功能,因此,如果我們想在日誌中添加 goroutine ID,需要藉助一些非標準的方式來實現。方法 1: 通過第三方庫(如 github.com/petermattis/goid)github.com/petermattis/goid 是一個常用的第三方庫,它可以幫助我們獲取當前 goroutine 的 ID。我們可以通過它來實 ⌘ Read more

⤋ Read More

Golang 面試題:strings 和 strconv 包
作爲一種基本數據結構,每種語言都有一些對於字符串的預定義處理函數。Go 中使用 strings 包來完成對字符串的主要操作。4.7.1 前綴和後綴———–HasPrefix 判斷字符串 s 是否以 prefix 開頭:strings.HasPrefix(s, prefix string) boolHasSuffix 判斷字符串 s 是否以 suffix 結尾:strings.HasS ⌘ Read more

⤋ Read More

一款支持自動流水線和客戶端緩存的 Go 語言 Redis 客戶端
Rueidis 是一款高性能的 Go 語言 Redis 客戶端,它支持自動流水線操作和服務端輔助客戶端緩存等功能。Rueidis 的目標是提供一個簡單易用、性能卓越的 Redis 客戶端庫,以滿足 Go 開發者的各種需求。主要功能—-自動流水線操作,提升非阻塞命令的執行效率 服務端輔助客戶端緩存,大幅降低延遲和提高吞吐量 支持泛型對象映射和客戶端緩存 提供緩存策略模式(Cac ⌘ Read more

⤋ Read More

Viper:強大的 Go 配置解析庫
1 介紹Viper (https://github.com/spf13/viper) 是適用於 Go 應用程序的完整配置解決方案。它被設計用於在應用程序中工作,並且可以處理所有類型的配置需求和格式。目前 Star 26.6k, 它支持以下特性:設置默認值 從 JSON、TOML、YAML、HCL、envfile 和 Java properties 格式的配置文件讀取配置信息 實時監控和 ⌘ Read more

⤋ Read More

你知道 golang 中 sysmon 有什麼作用嗎?
在 Go 語言的運行時 (runtime 包) 中,sysmon 是一個系統監視器 (system monitor) 線程,它在 Go 運行時中扮演着非常重要的角色。sysmon 的主要職責是維護 Go 程序的健壯性和響應性,確保垃圾回收 (Garbage Collection, GC)、搶佔調度 (Preemptive Scheduling)、定時器 (Timers) 和一些其他後臺任務能夠及時 ⌘ Read more

⤋ Read More

Golang 高併發應用中的數據庫連接死鎖
在構建高併發的 Go 應用時, 數據庫連接池的使用是不可或缺的。然而, 如果使用不當, 連接池也可能成爲性能瓶頸, 甚至導致整個應用陷入死鎖。本文將深入探討 Golang 中數據庫連接死鎖的原因、影響以及解決方案, 幫助開發者構建更加健壯的應用程序。數據庫連接池的工作原理———–在深入討論連接死鎖之前, 我們需要先了解數據庫連接池的工作原理。連接池本質上是一個連接的緩存, 它可以避免 ⌘ Read more

⤋ Read More
In-reply-to » Came across YTCH yesterday, and it is very addictive. Simple, and well done. You can host it yourself if you want. The trick I haven't figure out yet is how to create the list.json that drives it.

Its like old school TV but with youtube videos. Each channel has a subject and the channels play in a sort of realtime. so no going forward or back. Perfect for channel surfing.

⤋ Read More

Go 語言什麼時候該使用指針?指針使用的分析與講解
什麼是指針 我們都知道,程序運行時的數據是存放在內存中的,每一個存儲在內存中的數據都有一個編號,這個編號就是內存地址。我們可以根據這個內存地址來找到內存中存儲的數據,而內存地址可以被賦值給一個指針。我們也可以簡單的理解爲指針就是內存地址。指針的聲明和定義 在 Go 語言中,獲取一個指針,直接使用取地址符 & 就可以。 示例:func main() {  name := ”Go語言圈”  na ⌘ Read more

⤋ Read More

Go: string 和 bytes 四種轉換方式的性能比較
昨天公司羣中同事提到 Go 1.22 中 string 和 bytes 的互轉不需要再用 unsafe 那個包了,直接轉就可以。我翻看了 Go 1.22 的 release notes 沒找到相應的介紹,但是大家提到了 kubernetes 的 issue[1] 中有這個說法: As of go 1.22, for string to bytes conversion, we can repla ⌘ Read more

⤋ Read More

The benefits of mentoring and the CNCF Mentorship Program
By Nate Waddington, Head of Mentorship & Documentation, CNCF Technical people have a world of opportunities available to them when it comes to boosting career skills. But I’m going to make the case for taking a somewhat old-fashioned… ⌘ Read more

⤋ Read More

沒有什麼不可能:修改 Go 結構體的私有字段
在 Go 語言中, 結構體 (struct) 中的字段如果是私有的, 只能在定義該結構體的同一個包內訪問。這是爲了實現數據的封裝和信息隱藏, 提高代碼的健壯性和安全性。但是在某些情況下, 我們可能需要在外部包中訪問或修改結構體的私有字段。這時, 我們可以使用 Go 語言提供的反射 (reflect) 機制來實現這一功能。即使我們能夠實現訪問,這些字段你沒有辦法修改,如果嘗試通過反射設置這些私有字段 ⌘ Read more

⤋ Read More

Go 語言的流式處理特性進行高效的 HTTP 請求
在 Go 語言中,當你發起一個 HTTP 請求時,可以通過多種方式來將數據寫入請求的body部分。如果你要處理大型數據或者需要逐步生成請求體數據而不想一次性加載到內存中,可以使用流式寫入的方式。這裏我們會討論如何使用io.Reader接口來實現 HTTP 請求體的流式寫入。1. 基礎概念在 Go 語言的 HTTP 庫中,HTTP 請求的Body字段是一個io.Reader接口。因此,你可以通過實現 ⌘ Read more

⤋ Read More

Go 語言構建可擴展的 Worker Pool
在當今數據驅動的世界中,應用程序需要快速高效地處理大量請求。併發處理通過允許程序同時執行多個任務,成爲解決這一需求的關鍵。Go 語言以其強大的併發原語而聞名,爲構建高性能、可擴展的應用程序提供了優雅而有效的方法。本文將深入探討併發處理的概念,並提供使用 Go 語言構建可擴展 Worker Pool 的分步指南。併發處理:性能和效率的強大工具—————併發處理涉及程序內多個任務的 ⌘ Read more

⤋ Read More

圖解 Go 語言 time-Sleep 的實現原理
我們寫程序的時候,一定遇到過需要讓程序休眠一段時間再執行的場景,這個時候我們一般會想到用 Sleep 方法,Java 語言有Thread.Sleep, PHP 應該是有一個sleep函數,同樣的 Go 語言有內置的 time.Sleep 方法。這篇文章我們來簡單梳理一下,Go 語言的time.Sleep是怎麼實現程序的休眠和喚醒的。在 Go 的程序中,使用time.Sleep(d duration ⌘ Read more

⤋ Read More

通過 Go 示例理解函數式編程思維
一個孩子要嘗試 10 次、20 次才肯接受一種新的食物,我們接受一種新的範式,大概不會比這個簡單。– 郭曉剛 《函數式編程思維》譯者函數式編程 (Functional Programming, 簡稱 fp) 是一種編程範式,與命令式編程(Imperative Programming)、面向對象編程(OOP)、泛型編程(Generics Programming)、邏輯編程 (logic Pro ⌘ Read more

⤋ Read More

從源代碼中窺探 Go 的 WaitGroup 實現和應用
sync.WaitGroup OverviewGo 作爲雲原生開發的代表,以其在併發編程中的易用性而聞名。在大多數情況下,人們會在處理併發時使用 WaitGroup。我經常想要了解它是如何工作的,所以本文主要談談我對 WaitGroup 的理解。在 Go 語言中,sync.WaitGroup 允許主程序或其他 goroutines 在繼續執行之前等待多個 goroutines 執行完畢。它主要用於 ⌘ Read more

⤋ Read More

一文搞定 Golang 反射 -Reflect-
Go (Golang) 中的反射是一項強大的功能,它允許程序在運行時檢查自身的結構和值。這一功能由 reflect 包提供。反射通常用於序列化 / 反序列化、構建泛型庫和測試等任務。本文將概述反射在 Go 中的工作原理,並提供實際示例。基本概念Type: 值的類型,(如 int、string、float、struct)。 Value: 變量的實際數據。 kind: 類型的具體類別(如 ⌘ Read more

⤋ Read More

Installing multiple helm charts in one go [Approach 3 – using simple bash utility]
Community post originally published on Dev.to by Sunny Bhambhani In this article, we will be talking about Approach 3 i.e. how to get multiple helm charts installed using a simple bash utility. If you haven’t read the previous… ⌘ Read more

⤋ Read More

Disney Raising Prices for Hulu, ESPN+, and Disney+ This Fall
Disney will soon increase the cost of its suite of streaming services, including Hulu, ESPN+, and Disney+. Prices will go up for both ad-supported and ad-free plans, and some of Disney’s bundles will also be more expensive. Most plans are increasing by $1 to $2.

Image

  • Disney+ With Ads - $9.99, up from … ⌘ Read more

⤋ Read More

在 golang 裏使用 ZooKeeper,如何使用
在 Go 語言中使用 ZooKeeper,可以藉助第三方庫go-zookeeper。下面介紹如何安裝和使用這個庫與 ZooKeeper 進行交互。安裝 go-zookeeper 庫首先,需要安裝go-zookeeper庫。使用go get命令來安裝:go get github.com/samuel/go-zookeeper/zk使用 ZooKeeper 的基本示例以下是一個簡單的示例,包括連接 Z ⌘ Read more

⤋ Read More

適配器模式在 Go 語言中的應用
前段時間我負責對一個項目進行臨時性的技術方案改造,用到了適配器模式,今天就來跟大家簡單分享下適配器模式在 Go 語言中的應用。適配器模式適配器模式(Adapter Pattern)是 23 種經典設計模式中的一種,屬於行爲型模式,它允許不兼容的接口協同工作。該模式通過創建一個適配器類,封裝不兼容的接口,並對外提供一個兼容的接口。《設計模式:可複用面向對象軟件的基礎》一書中對適配器的意圖定義如下: ⌘ Read more

⤋ Read More

用 Go 語言構建優雅的事件驅動架構
事件驅動架構(EDA)作爲一種強大的軟件設計模式,在構建現代分佈式系統中扮演着越來越重要的角色。它通過異步事件流將不同的服務和組件解耦,從而提升系統的可擴展性、彈性和響應能力。在 Go 語言中,其簡潔的語法和豐富的併發原語爲實現高效的 EDA 提供了天然的優勢。事件驅動架構的核心概念———–在深入探討如何使用 Go 語言構建 EDA 之前,我們先來回顧一下事件驅動架構的核心概念:事件 ⌘ Read more

⤋ Read More
In-reply-to » @lyse As far as I know, they're still visible in the Web UI. Although, in the mobile app and youtube.com, I believe it tells you that the video isn't available without having to click on it. They don't tell you that in the RSS feed, and I agree; it gets annoying.

Definitely something going on here. Cloudflare is my main suspect.

⤋ Read More
In-reply-to » @lyse Ahh so it's not just me! 😅

@aelaraji@aelaraji.com Ahh it might very well be a Clownflare thing as @lyse@lyse.isobeef.org eluded to 🤣 One of these days I’m going to get off Clownflare myself, when I do I’ll share it with you. My idea is to basically have a cheap VPS like @eldersnake@we.loveprivacy.club has and use Wireguard to tunnel out. The VPS becomes the Reverse Proxy that faces the internet. My home network then has in inbound whatsoever.

⤋ Read More

Go1-23 新特性:花了近 10 年,time-After 終於不泄漏了!
大家好,我是煎魚。好多年前,我寫過 timer.After 的使用和坑。Go 這麼多年以來這塊一直有內存泄露。有的同學或多或少都有遇到過。最近 Go1.23 即將正式發佈,Go 核心團隊負責人 rsc 自述花了將近 10 年的努力,終於把這個問題修復了。值得我們關注!timer.After 是什麼—————這是之前編寫的部分,我測試驗證了下。在 Go1.22 依然有效,仍然是有 ⌘ Read more

⤋ Read More

It’s my birthday today :) i was born 41 years go, 3.5 months too early. I was so small my parents had to buy doll clothes at the toy store. Gonna be a nice day today, celebrate with my family :) we always treasure birthdays.🎂

⤋ Read More

在 Go 中如何使用反射實現簡易版 encoding-json
在使用 Go 語言開發過程中,我們經常需要實現結構體到 JSON 字符串的序列化(Marshalling)或 JSON 字符串到結構體的反序列化(Unmarshalling)操作。Go 爲我們提供了 encoding/json 庫可以很方便的實現這一需求。在本文中,我們將探索如何使用 Go 的反射機制自己來實現一個簡易版的 encoding/json 庫。這個過程不僅能幫助我們理解序列化和反序列化 ⌘ Read more

⤋ Read More

Go 還是 TinyGo?
什麼是 TinyGo?TinyGo 與 Go 有何不同? TinyGo 與 Go 相比性能如何?什麼是 TinyGo?———–TinyGo 不是另一種編程語言。它只是 Go 語言的一個編譯器。關鍵區別在於 TinyGo 編譯器創建的二進制文件更小, 主要用於嵌入式系統和 WASM。而 Go 編譯器則用於編譯完整的服務器端應用程序和通用程序。TinyGo 使用 LLVM 作爲後端, 與 ⌘ Read more

⤋ Read More

你是如何用 Go 語言 配置高性能 sql-DB 的?
配置高性能的 sql.DB 是 Go 應用程序開發中一個重要的環節,特別是在需要處理大量數據庫查詢的情況下。以下是一些最佳實踐和配置建議:1. 數據庫連接池的配置Go 的 database/sql 包提供了連接池的功能,您可以通過設置最大空閒連接、最大打開連接數和連接的最大生命週期來優化連接池。db, err := sql.Open(“mysql”, ”user:password@tcp(127. ⌘ Read more

⤋ Read More
In-reply-to » I setup and switched to Headscale last night. It was relatively simple, I spent more time installing a web GUI to manage it to be honest, the actual server is simple enough. The native Tailscale Android app even works with it thankfully.

@prologic@twtxt.net Yes I suppose that is true. There is an article on Tailscale’s site that explains it all quite a bit: https://tailscale.com/blog/how-nat-traversal-works

To me, with CGNAT, it’s a small miracle that a direct connection can be made between peers (as opposed to going through a relay constantly) but it does indeed work. I guess to host it at home you would need to have it WAN accessible, and if you’ve already gone to the trouble of port forwarding etc… well 😅
Not that I could personally do that, but for those with static IPs etc.

⤋ Read More

Lambda-Go:將函數式編程引入 Go
函數式編程是編程範式當中的一種,喜歡的人愛之如命,不喜歡的人嗤之以鼻,以簡單高效著稱的 Go 天然在函數式編程上有自己的優勢。Lambda-Go[1] 是一個旨在將受 Haskell 啓發的函數式編程技術引入 Go 生態系統的庫。在本文中,我們將探討 Lambda-Go 的功能,以及它如何增強你的 Go 編程體驗。Lambda-Go 簡介Lambda-Go 是一個 Go 庫,它通過函數式編程結構擴 ⌘ Read more

⤋ Read More
In-reply-to » Bought a motorcycle this summer, I did not want two cars, and Marlyn would like to have the car more when I'm at work. So I bought a new cheap motorcycle, KTM Adventure 390. It's been 10 years since I last had a motorcycle (back then I had a KTM 990cc). Here I am with my daughter on the new bike :) My kids love to go for rides, so does Marlyn as well, so it's a lot of fun for all of us. Media

@bender@twtxt.net It cost what you mentioned here too, but they had a special discount, and the shop gave 20% discount for all the gear we needed (since I bought the bike + gear for two persons), so all in all I got a really good deal on it. Also interest rate is locked for 3 years (low rate) so that was also a good deal.
I just took the longest time I could on the loan, to have a low price each month, and then i just pay extra whenever I can to get it payed down faster.
Luckily the Marlyn, my son, and my daughter all fit the same gear, so the 3 of them share that, that saved a lot of money too :)

When i met Marlyn (before we had kids) I asked here to go on her first trip with me (I had a bike before I met her back then), and we went on a 2 week ride from Norway to Italy and back (venice) through the alps and all that. Was super fun, and I think it’s pretty cool of her to say yes to a 2 week trip as passenger :)

⤋ Read More

Bought a motorcycle this summer, I did not want two cars, and Marlyn would like to have the car more when I’m at work. So I bought a new cheap motorcycle, KTM Adventure 390.
It’s been 10 years since I last had a motorcycle (back then I had a KTM 990cc).
Here I am with my daughter on the new bike :)
My kids love to go for rides, so does Marlyn as well, so it’s a lot of fun for all of us.

Image

⤋ Read More

Go 異步編程小技巧
我們通過一個簡單的例子看一下 Goroutine 的使用func main() {    go func() {        fmt.Println(“Goroutine started”)        // do some work        fmt.Println(“Goroutine finished”)    }()    // wait for Goroutine to fini ⌘ Read more

⤋ Read More

Anyway, I’m gonna have to go to bed… We’ll continue this on the weekend. Still trying to hunt down some kind of suspected mult-GB avatar using @stigatle@yarn.stigatle.no ’s pod’s cache:

$ (echo "URL Bytes"; sort -n -k 2 -r < avatars.txt | head) | column -t
URL                                                                                                       Bytes
https://birkbak.neocities.org/avatar.jpg                                                                  667640
https://darch.neocities.org/avatar.png                                                                    652960
http://darch.dk/avatar.png                                                                                603210
https://social.naln1.ca/media/0c4f65a4be32ff3caf54efb60166a8c965cc6ac7c30a0efd1e51c307b087f47b.png        327947
...

But so far nothing much… Still running the search…

⤋ Read More
In-reply-to » @stigatle / @abucci My current working theory is that there is an asshole out there that has a feed that both your pods are fetching with a multi-GB avatar URL advertised in their feed's preamble (metadata). I'd love for you both to review this PR, and once merged, re-roll your pods and dump your respective caches and share with me using https://gist.mills.io/

@prologic@twtxt.net here you go:
https://drive.proton.me/urls/XRKQQ632SG#LXWehEZMNQWF

⤋ Read More
In-reply-to » @prologic hm, it seems to be full disk that's the issue, same problem with the avatar in tmp it seems that's mentioned earlier here. I deleted them now. I regained 33% space (9GB).

@prologic@twtxt.net I got it working, I reinstalled go under home (instead of where go wiki tells me to install it), and pointed to that, as well as the variables you mentioned, that enabled me to compile it. deleted the old yarnd , and made sure I run the new one.
Thanks for the help (as always :) ).

⤋ Read More