Go 程序如何實現優雅退出?來看看 K8s 是怎麼做的——下篇
K8s 的優雅退出現在,我們已經掌握了 Go 中 HTTP Server 程序如何實現優雅退出,是時候看一看 K8s 中提供的一種更爲優雅的優雅退出退出方案了😄。這要從 K8s API Server 啓動入口說起: https://github.com/kubernetes/kubernetes/blob/release-1.31/cmd/kube-apiserver/apiserver.gof ⌘ Read more
Automatic Komoot export
While I like Komoot and use it to navigate and record all my tours, whether that are bike tours or hiking trips, it sucks that there’s no option to export all your data. There’s also no official API to easily implement such functionality. ⌘ Read more
golang 做 api 開發離不開簽名驗證- 如何設計?
在 API 開發中,簽名驗證是一種常見的安全措施,用於確保請求的完整性和來源的可靠性。以下是設計一個簽名驗證機制的步驟和示例代碼。設計思路密鑰管理:爲每個客戶端分配一個唯一的 API 密鑰和 API 密鑰。 簽名生成:客戶端在請求 API 時,使用預定義的算法生成簽名,並將簽名和其他必要參數(如時間戳、隨機數等)一起發送到服務器。 簽名驗證:服務器接收到請求後,根據相同的算法重新生成簽 ⌘ Read more
The importance of secrets detection and redaction within the SLSA framework
Member post by Wayne McDaniel, GitGuardian Leaked credentials, aka secrets, are an easy way for bad actors to gain access to your environments and data. While no one intends to leave these valuable API keys, tokens, and passwords… ⌘ Read more
ProcessOne: ejabberd 24.06
This new ejabberd 24.06 includes four months of work, close to 200 commits, including several minor improvements in the core ejabberd, and a lot of improvements in the administrative parts of ejabberd, like the WebAdmin and new API commands.
Brief summary- *Webadmin rework … ⌘ Read more
I have a question for the IndieWeb community: What can we do against Webmention spam, except filter it out, when it fails validation? I receive hundreds of invalid Webmentions a day, and even using a filtering DNS server doesn’t seem to help much. But I also don’t want to waste network traffic to access all those spam sites. Is there any good block list I can check first before doing the request for validation? I thought about Akismet, but the API has no such option to only check the submitted URL. ⌘ Read more
如何架構優秀的 Go 後端 REST API 服務
REST(Representational State Transfer)是 Web 服務中廣泛使用的一種架構風格,其核心思想是使用 HTTP 協議出色地創建、讀取、更新和刪除(CRUD)資源。作爲一種靜態類型、編譯型語言,Go 在構建高效、可靠的 Web 服務時具有顯著優勢。使用 Go 語言構建 REST API 服務需要我們從多個方面入手,包括項目結構、框架選擇、數據庫操作、路由設計等。以下將 ⌘ Read more
ProcessOne: ejabberd 24.06
This new ejabberd 24.06 includes four months of work, close to 200 commits, including several minor improvements in the core ejabberd, and a lot of improvements in the administrative parts of ejabberd, like the WebAdmin and new API commands.
Brief summary- *Webadmin rework … ⌘ Read more
ProcessOne: ejabberd 24.06
This new ejabberd 24.06 includes four months of work, close to 200 commits, including several minor improvements in the core ejabberd, and a lot of improvements in the administrative parts of ejabberd, like the WebAdmin and new API commands.
Brief summary- *Webadmin rework … ⌘ Read more
ProcessOne: ejabberd 24.06
This new ejabberd 24.06 includes four months of work, close to 200 commits, including several minor improvements in the core ejabberd, and a lot of improvements in the administrative parts of ejabberd, like the WebAdmin and new API commands.
Brief summary- *Webadmin rework … ⌘ Read more
萬字長文:Go 語言流行 ORM 框架 GORM 使用詳解
GORM 是 Go 語言中最受歡迎的 ORM 庫之一,它提供了強大的功能和簡潔的 API,讓數據庫操作變得更加簡單和易維護。本文將詳細介紹 GORM 的常見用法,包括數據庫連接、模型定義、CRUD、事務管理等方面,幫助大家快速上手使用 GORM 進行 Web 後端開發。安裝通過如下命令安裝 GORM:$ go get -u gorm.io/gorm你也許見過使用 go get -u github. ⌘ Read more
Ignite Realtime Blog: Openfire restAPI plugin version 1.11.0 release
Earlier today, version 1.11.0 of the REST API plugin for Openfire was released!
The REST API Plugin provides the ability to manage Openfire (the real-time communications server created by the Ignite Realtime community) by sending an REST/HTTP request to the server. This plugin’s functionality is useful for applications that need to administer Openfire outs … ⌘ Read more
PocketBase:一體化的開源 Go 語言實時後端
PocketBase 是一個開源的實時後端解決方案,採用單一文件的形式進行分發。它由嵌入式數據庫 (SQLite) 和實時訂閱功能組成,提供了開箱即用的文件和用戶管理功能、方便的管理儀表板 UI 以及簡單的 REST 風格 API。本文將深入探討 PocketBase 的功能、安裝、示例代碼和一些高級的應用技巧。主要特性—-嵌入式數據庫PocketBase 內嵌 SQLite 數據庫,這意味着 ⌘ Read more
使用 Golang 構建你的第一個 k8s Operator
本文將展示如何使用 Operator SDK[1] 搭建一個基本的 k8s Operator。在本文中,您將瞭解如何創建一個新項目,並通過創建自定義資源定義 (CRD) 和基本控制器來添加 API。我們將在 CRD 中添加字段,以包含一些有關期望狀態和實際狀態的信息,修改控制器以調和新資源的實例,然後將 operator 部署到 Kubernetes 集羣。Prerequisites安裝 Oper ⌘ Read more
如何將圖片編碼成 base64?
圖片的 base64 編碼在多種上下文中都很有用。當需要通過旨在處理文本數據的媒體存儲或傳輸圖片時,它通常會被使用,比如嵌入到網頁或者通過 API 上傳圖片。這篇文章將介紹如何使用 Go 標準庫得到任何圖片的 base64 編碼的值。在 Go 中將圖片轉換爲其 base64 表示很容易。所有你需要做的是將文件讀取爲字節 slice 並使用包 encoding/base64 對其進行編碼。處理本地圖 ⌘ Read more
基於 Go 語言實現的 Ollama 大語言模型框架
大語言模型在現代人工智能領域中扮演着重要角色。Ollama 作爲一個輕量級且可擴展的框架,幫助開發者在本地機器上構建和運行這些模型。Ollama 簡介———Ollama 是一個簡單、可擴展的框架,旨在幫助開發者構建和運行大語言模型。它提供了一個簡潔的 API,用於創建、運行和管理模型。此外,Ollama 附帶了豐富的預構建模型庫,供開發者在各種應用中輕鬆使用。Ollama 的特性包括: ⌘ Read more
Go 語言主流 ORM 框架對比:GORM vs- Ent
GORM 和 Ent 是 Go 語言中使用廣泛的兩種 ORM(對象關係映射)框架。它們都有助於將數據庫操作從底層 SQL 抽象出來,簡化數據庫交互,但它們的設計理念和使用方式有顯著的不同。本文將詳細介紹 GORM 和 Ent 的不同特點、使用示例,並比較它們在不同場景下的優劣。GORM 簡介——-GORM 是一個易於使用的 ORM 庫,旨在提供簡單、乾淨的 API。它通過反射機制動態處理數 ⌘ Read more
全面掌握 GORM 中的遷移系統,實現自動遷移與手動遷移
在 Golang 生態系統中,GORM 作爲一個廣泛使用的 ORM 框架,不僅在數據庫操作方面提供了友好的 API 支持,其遷移系統(Migration System)同樣功能強大且易於使用。在本文中,我們將詳細解析 GORM 中的遷移機制,包括自動遷移和手動遷移,同時提供詳盡的代碼示例,幫助開發者全面掌握這一技術。什麼是數據庫遷移?———在數據庫系統中,遷移是指對數據庫架構進行變更的 ⌘ Read more
Go 語言中,HTTP 請求流式是如何寫入 body 的?
最近在開發一個功能時,需要通過 http 協議上報大量的日誌內容,但是在 Go 標準庫裏的 http client 的 API 是這樣的: http.NewRequest(method, url string, body io.Reader)body 是通過 io.Reader 接口來傳遞,並沒有暴露一個 io.Writer 接口來提供寫入的辦法,先來看看正常情況下怎麼寫入一個 body ,示例 ⌘ Read more
go3d:Go 語言遊戲方向的高性能 2D-3D 數學庫
在面向性能的編程世界中,go3d是爲 Go 語言提供的一款 2D/3D 數學庫,致力於提高圖形計算的效率與速度。適用於那些需要進行向量、矩陣等數學計算以實現圖形處理的應用程序,go3d提供了一套豐富的 API,以支持高效的數學運算。下面,我們將深入瞭解這個庫的主要特性、結構和使用方式,以及如何在項目中有效利用它。主要特性—-高性能設計:go3d庫主要關注於性能,通過優化算法和數據結構來減少計算 ⌘ Read more
Lura:基於 Gin 實現的下一代超高性能 API 網關,支持大量插件!
在快速發展的技術世界中,管理和分發服務變得愈發重要。API 網關作爲一種服務架構模式,爲微服務架構提供了一種高效的管理方式。近年來,Lura(以前稱爲 KrakenD)在開源社區嶄露頭角,以其輕量級和高性能稱爲熱議的焦點。Lura 項目不僅僅是一個 API 網關,它還提供了豐富的中間件,可以幫助開發者在 Linux 環境中更好地管理微服務。接下來我們將深入探討 Lura 的技術架構,以及如何使用其 ⌘ Read more
使用 OpenTelemetry 實現 Golang 服務的可觀測系統
這篇文章中我們會討論可觀測性概念,並瞭解了有關 OpenTelemetry 的一些細節,然後會在 Golang 服務中對接 OpenTelemetry 實現分佈式系統可觀測性。Test Project我們將使用 Go 1.22 開發我們的測試服務。我們將構建一個 API,返回服務的名稱及其版本。我們將把我們的項目分成兩個簡單的文件(main.go 和 info.go)。// file: main. ⌘ Read more
單元測試中如何解決文件依賴問題
現如今的 Web 應用程序往往採用 RESTful API 接口形式對外提供服務,後端接口直接向前端返回 HTML 文件的情況越來越少,所以在程序中操作文件的場景也變少了。不過有些時候還是需要對文件進行操作,比如某個 API 接口需要返回應用程序的 ChangeLog,那麼這個接口就可以通過讀取項目的 CHANGELOG.md 文件內容,將其發送給前端。在編寫單元測試時,文件就成了被測試代碼的外部 ⌘ Read more
用 Go 語言做了一個分佈式限流器, 看看實現的方法與步驟
項目中需要對 api 的接口進行限流,但是麻煩的是,api 可能有多個節點,傳統的本地限流無法處理這個問題。限流的算法有很多,比如計數器法,漏斗法,令牌桶法,等等。各有利弊,相關博文網上很多,這裏不再贅述。項目的要求主要有以下幾點:支持本地 / 分佈式限流,接口統一 支持多種限流算法的切換 方便配置,配置方式不確定 go 語言不是很支持 OOP,我在實現的時候是按 Java 的思 ⌘ Read more
Go 語言實現開源優雅的跨平臺 USDT 收付中間件
Epusdt(全稱:Easy Payment Usdt)是一個由 Go 語言編寫的私有化部署 Usdt 支付中間件 (Trc20 網絡)。站長或開發者可以通過 Epusdt 提供的 http api 集成至任何系統,無需過多的配置,僅僅依賴 mysql 和 redis。通過它,可以實現 USDT 的在線支付和消息回調,均可在優雅和瞬間完成。私有化搭建使得無需額外的手續費和簽約費用,Usdt 代幣直 ⌘ Read more
利用 Go 操控 Etcd:構建強一致性系統的祕訣
etcd 是一個開源的、高可用的分佈式鍵值(key-value)存儲系統,它主要用來共享配置和服務發現。etcd 由 CoreOS 團隊開發,是以 Go 語言編寫的。etcd 採用了 Raft 協議來處理日誌複製以提供強一致性和高可用性,它成爲很多分佈式系統和雲原生技術(如 Kubernetes)中的基礎組件。etcd 的核心特性包括:簡潔的鍵值存儲:etcd 提供 HTTP/JSON API,允 ⌘ Read more
Even though the bridges that #beeper use are AGPL licensed, the beeper client is proprietary software 😭
This is big sad.
They almost had it.
It is also kind of limited on google-free android phones, since the QR code scanner for device verification key-signing depends on a google play services API (which microg doesn’t implement). This means that you can’t share message history between your google-free android and the beeper desktop client. ⌘ Read more
使用 Golang 構建你的 LLM API
大語言模型,像 ChatGPT, Llama 等已經席捲全球,從上圖的數據可以看出,ChatGPT 花了 5 天時間就達到了 100 萬用戶。而 Netflix 則花了近 4 年的時間。本文將使用 Gin 和 Langchain 教你快速構建一套 LLM API。GinGin[1] 是一個用於使用 GoLang 構建 API 的現代、快速的 Web 框架。它被設計爲易於使用、高效且性能出色,利用了 ⌘ Read more
Telegram Premium allows you to convert voice messages to text. But Telegram Premium isn’t officially available in Germany. So why not develop your own solution? That’s exactly what I did this morning: I created a Telegram bot that takes the voice message and transcribes it using OpenAI’s Whisper API. The bot runs as a serverless container on Scaleway. The source code is published on my Gitea instance. ⌘ Read more
Due to OpenAI’s move to prepaid billing, I (finally) had to pay for using the OpenAI API. But this also allows me to finally use the gpt-4-turbo-preview model as I have reached tier 1. Now the AI-generated summaries on this blog will be created using this new model. 😄 ⌘ Read more
Go arena 民間庫來了,可以手動管理內存!
大家好,我是煎魚。上年我們有討論過關於 Go arena 手動管理內存的相關提案。一開始還高歌猛進,但沒想到後面由於嚴重的 API 問題(想把 arena 應用到其他的標準庫中,但會引入大問題):Go 核心團隊中途咕咕咕到現在,沒有新的推動和突破性進展,實屬尷尬。最近有社區的大佬有了新的動作,來自 Grafana 的 @Miguel Ángel Ortuño 開源了一個新的第三方庫 ortuman ⌘ Read more
ProcessOne: Matrix gateway setup with ejabberd
As of version 24.02, ejabberd is shipped with a Matrix gateway and can participate in the Matrix\
\
federation. This means that an XMPP client can exchange messages with Matrix users or rooms.
Let’s see how to configure your ejabberd to enable this gateway.
Configuration in ejabberd HTTPS listenerFirst, add an [HTTP h … ⌘ Read more
PEP 743: Add Py_COMPAT_API_VERSION to the Python C API
Add Py_COMPAT_API_VERSION and Py_COMPAT_API_VERSION_MAX macros to opt-in for planned incompatible C API changes in a C extension. Maintainers can decide when they make their C extension compatible and also decide which future Python version they want to be compatible with. ⌘ Read more
ProcessOne: WebPush support on your fluux.io instance
We’re excited to announce the latest enhancement to Fluux.io services – the integration of WebPush support. This significant update extends our services beyond
FCM/APNs, enabling push notifications for XMPP across various platforms. Now, our push notification capabilities are not li … ⌘ Read more
使用 Templ 進行 Go 模板化
使用 Templ 在 Go 項目中高效生成動態內容的指南—————————-動態內容生成是 Web 開發的一個基本方面。無論您是在構建網站、Web 應用程序還是 API,根據數據和模板生成動態內容的能力都至關重要。在 Go 編程世界中,一個名爲 “Templ” 的強大工具簡化了這一過程。在這份全面的指南中,我們將探索使用 Templ 進行 Go 模板化,它的關鍵 ⌘ Read more
使用 Gin 框架中的 PureJSON 發送未轉義的 JSON
當我們使用 Go 的 Gin web 框架來構建 RESTful API 時,通常會遇到返回 JSON 響應的需求。Gin 框架提供了c.JSON方法來以 JSON 格式發送回覆,同時它會對特殊字符進行轉義,比如把 < 轉換爲 \u003c。但在某些情況下,我們需要發送未轉義的 JSON 數據,這時我們就可以使用 Gin 框架中的c.PureJSON方法。在 Gin 框架中,c.PureJSON方 ⌘ Read more
Go Web 開發不得不說的請求路由
*1. 請求路由的概念請求路由的定義:請求路由是指將客戶端的請求與服務器上對應的處理程序匹配和映射的過程。它決定了不同的 URL 或 API 請求被映射到哪些處理函數。請求路由的作用:請求路由實現了請求與處理函數之間的解耦,使代碼更加模塊化。同時,它也使得 URL 和 API 更符合 RESTful 設計規範。請求路由還可以實現諸如負載均衡、緩存、日誌記錄、身份驗證等功能。2. net/http ⌘ Read more
PEP 741: Python Configuration C API
Add a C API to the limited C API to configure the Python preinitialization and initialization, and to get the current configuration. It can be used with the stable ABI. ⌘ Read more
Go 調用 C– 動態庫實現車牌識別
前言—–很久沒更新博客,這次正好趁着這次機會來更新一個稍微有點意思的內容,利用 C++ 中 Opencv、TensorRT 等庫編譯出動態庫供 Go 調用,再寫個簡單的 api 對上傳的車輛圖片進行車牌識別。究其原因,天下苦 Java 久矣,每次寫 JNI 去給公司 Java 後端服務調用,而我不喜歡 Java 那我每次寫好的模型動態庫就到此爲止了?白白浪費之前那麼多計算資源於心不忍,因此打 ⌘ Read more
ProcessOne: WebPush support on your fluux.io instance
We’re excited to announce the latest enhancement to Fluux.io services – the integration of WebPush support. This significant update extends our services beyond
FCM/APNs, enabling push notifications for XMPP across various platforms. Now, our push notification capabilities are not li … ⌘ Read more
ProcessOne: WebPush support on your fluux.io instance
We’re excited to announce the latest enhancement to Fluux.io services – the integration of WebPush support. This significant update extends our services beyond
FCM/APNs, enabling push notifications for XMPP across various platforms. Now, our push notification capabilities are not li … ⌘ Read more
Go 巧用 io-Pipe– 優化內存佔用情況
當需要向服務端通過 http api 上傳大文件時候,通常會使用以下這種方式func main(){ filename := “nohup.out” body := new(bytes.Buffer) writer := multipart.NewWriter(body) part, err := writer.CreateFormFile(“file”, filename ⌘ Read more
手把手教你寫個自己的 protoc-gen-go
你是否用過 protobuf 或 gRPC? 你們公司項目的 API 有沒有用到 proto 文件? 本文將帶你一步一步寫個類似protoc-gen-go-grpc的 proto 文件生成工具,從 proto 文件生成兼容 Go 標準庫的 HTTP 框架代碼。掌握它之後,你就能隨心所欲的從 proto 文件生成gin、echo、net/http代碼,甚至生成你自己的框架代碼。 別擔心 ⌘ Read more
go-elasticsearch 使用指南
本文是 go-elasticsearch 庫的使用指南。go-elasticsearch 是 Elasticsearch 官方提供的 Go 客戶端。每個 Elasticsearch 版本會有一個對應的 go-elasticsearch 版本。官方會維護最近的兩個主要版本。go-elasticsearch 提供了 Low-level 和 Fully-typed 兩套 API。本文以 Fully-ty ⌘ Read more
介紹 Agency: 使 AI 與 Go 語言無縫對接
在當今應用開發領域,類似 OpenAI API 等生成式 AI 技術的蓬勃發展正在徹底改變着應用開發的格局。Python 和 JavaScript 等語言已經擁有豐富的資源來支持這些技術,其中 LangChain 就是一個顯著的例子。然而,Go 語言開發者面臨的選擇卻相對有限。LangChainGo,作爲 LangChain 的 Go 語言版本,一直在努力與 Go 的編程理念保持一致,而 Lang ⌘ Read more
Remote community strives to improve health by growing their own fruit and veg in APY Lands
A Central Australian Aboriginal community hopes to improve the health of residents and increase food security by re-establishing a once plentiful orchard that has fallen into disrepair. ⌘ Read more
PEP 737: Unify type name formatting
Add new convenient APIs to format type names the same way in Python and in C. No longer format type names differently depending on how types are implemented. Also, put an end to truncating type names in C. The new C API is compatible with the limited C API. ⌘ Read more
Ignite Realtime Blog: REST API Openfire plugin 1.10.2 released!
Earlier today, we have have performed a maintenance release for the REST API plugin for Openfire. In this release, version 1.10.2, we have made a warning in documentation more visible. This is aimed at reducing confusion around installation with Openfire 4.7.5.
Also in this release a translation into Ukrainian, gracefully provided by community member Yurii Savchuk (svais) and his son Vladislav Savchuk (Bruhmozavr)!
Th … ⌘ Read more
I quickly played with OpenAI’s new Text-To-Speech model to check if it’s an alternative to Google’s API. And wow! English is fantastic and even German is not bad. Just some syllables in German have a weird English accent. But even then, it’s still good. But sadly, it’s also a bit costly. Let’s wait a few months until it gets cheaper and better, and you can enjoy my blog’s “Read aloud” feature even more. 😉 ⌘ Read more
Get Started with the Microcks Docker Extension for API Mocking and Testing
Read how running Microcks as a Docker extension enables developers to swiftly create, test, and iterate on APIs without leaving the Docker environment. ⌘ Read more