我們最近開源了用於建立企業 golang 應用程式的自製框架,稱為 INFINI 框架。
github 倉庫是 https://github.com/infinilabs/framework。
在本文中,我將向您展示如何開始使用 INFINI Framework。
創建新應用程式
我們以NewAPP作為新專案為例。
建立專案資料夾
使用名稱new_app作為專案id,並建立專案資料夾如下:
cd ~/go/src/infini.sh/ mkdir new_app
注意:確保new_app與framework資料夾位於同一目錄中。這個結構是 Makefile 正確運作所必需的。
建立主文件
建立一個空的main.go文件,並貼上以下程式碼:
package main import ( "infini.sh/framework" "infini.sh/framework/core/module" "infini.sh/framework/core/util" "infini.sh/framework/modules/api" "infini.sh/new_app/config" ) func main() { terminalHeader := (" __ _ ___ ___ \n") terminalHeader += (" /\ \ \_____ __/_\ / _ \/ _ \\n") terminalHeader += (" / \/ / _ \ \ /\ / //_\\ / /_)/ /_)/\n") terminalHeader += ("/ /\ / __/\ V V / _ \/ ___/ ___/ \n") terminalHeader += ("\_\ \/ \___| \_/\_/\_/ \_/\/ \/ \n\n") terminalFooter := ("Goodbye~") app := framework.NewApp("new_app", "Make a golang application is such easy~.", util.TrimSpaces(config.Version), util.TrimSpaces(config.BuildNumber), util.TrimSpaces(config.LastCommitLog), util.TrimSpaces(config.BuildDate), util.TrimSpaces(config.EOLDate), terminalHeader, terminalFooter) app.IgnoreMainConfigMissing() app.Init(nil) defer app.Shutdown() if app.Setup(func() { module.RegisterSystemModule(&api.APIModule{}) module.Start() }, func() { }, nil) { app.Run() } }
我們使用這個線上工具來產生一個漂亮的基於 ASCII 的終端頭。
建立設定檔
touch new_app.yml
建立生成文件
建立一個空的Makefile,並貼上以下程式碼:
SHELL=/bin/bash # APP info APP_NAME := new_app APP_VERSION := 1.0.0_SNAPSHOT APP_CONFIG := $(APP_NAME).yml APP_EOLDate ?= "2025-12-31T10:10:10Z" APP_STATIC_FOLDER := .public APP_STATIC_PACKAGE := public APP_UI_FOLDER := ui APP_PLUGIN_FOLDER := plugins PREFER_MANAGED_VENDOR=fase include ../framework/Makefile
建立應用程式
➜ new_app OFFLINE_BUILD=true make build building new_app 1.0.0_SNAPSHOT main /Users/medcl/go/src/infini.sh/new_app framework path: /Users/medcl/go/src/infini.sh/framework fatal: not a git repository (or any of the parent directories): .git update generated info update configs (cd ../framework/ && make update-plugins) || true # build plugins in framework GOPATH=~/go:~/go/src/infini.sh/framework/../vendor/ CGO_ENABLED=0 GRPC_GO_REQUIRE_HANDSHAKE=off GO15VENDOREXPERIMENT="1" GO111MODULE=off go build -a -gcflags=all="-l -B" -ldflags '-static' -ldflags='-s -w' -gcflags "-m" --work -o /Users/medcl/go/src/infini.sh/new_app/bin/new_app WORK=/var/folders/j5/qd4qt3n55dz053d93q2mswfr0000gn/T/go-build435280758 # infini.sh/new_app ./main.go:17:9: can inline main.deferwrap1 ./main.go:21:12: can inline main.func2 ./main.go:18:22: func literal does not escape ./main.go:19:45: &api.APIModule{} escapes to heap ./main.go:21:12: func literal escapes to heap restore generated info
運行應用程式
➜ new_app git:(main) ✗ ./bin/new_app __ _ ___ ___ /\ \ \_____ __/_\ / _ \/ _ \ / \/ / _ \ \ /\ / //_\ / /_)/ /_)/ / /\ / __/\ V V / _ \/ ___/ ___/ \_\ \/ \___| \_/\_/\_/ \_/\/ \/ [NEW_APP] Make a golang application is such easy~. [NEW_APP] 1.0.0_SNAPSHOT#001, 2024-12-16 06:15:10, 2025-12-31 10:10:10, HEAD [12-16 14:15:19] [INF] [env.go:203] configuration auto reload enabled [12-16 14:15:19] [INF] [env.go:209] watching config: /Users/medcl/go/src/infini.sh/new_app/config [12-16 14:15:19] [INF] [app.go:311] initializing new_app, pid: 64426 [12-16 14:15:19] [INF] [app.go:312] using config: /Users/medcl/go/src/infini.sh/new_app/new_app.yml [12-16 14:15:19] [INF] [api.go:214] local ips: 192.168.3.17 [12-16 14:15:19] [INF] [api.go:312] api server listen at: http://0.0.0.0:2900 [12-16 14:15:19] [INF] [module.go:159] started module: api [12-16 14:15:19] [INF] [module.go:184] all modules are started [12-16 14:15:19] [INF] [instance.go:101] workspace: /Users/medcl/go/src/infini.sh/new_app/data/new_app/nodes/ctfs8hbq50kevmkb3m6g [12-16 14:15:19] [INF] [app.go:537] new_app is up and running now. ^C [NEW_APP] got signal: interrupt, start shutting down [12-16 14:15:23] [INF] [module.go:213] all modules are stopped [12-16 14:15:23] [INF] [app.go:410] new_app now terminated. [NEW_APP] 1.0.0_SNAPSHOT, uptime: 4.13334s Goodbye~
結論
示範程式碼可以在這裡找到。
透過利用 INFINI 框架,創建 Go 應用程式變得更加簡單和有效率。
該框架提供內建命令和模組,簡化了開發流程,使您能夠專注於建立應用程式的核心功能。
追蹤我們:https://github.com/infinilabs
以上是INFINI Framework 入門 - 我們用於建立企業 golang 應用程式的自製框架的詳細內容。更多資訊請關注PHP中文網其他相關文章!

Golang更適合高並發任務,而Python在靈活性上更有優勢。 1.Golang通過goroutine和channel高效處理並發。 2.Python依賴threading和asyncio,受GIL影響,但提供多種並發方式。選擇應基於具體需求。

Golang和C 在性能上的差異主要體現在內存管理、編譯優化和運行時效率等方面。 1)Golang的垃圾回收機制方便但可能影響性能,2)C 的手動內存管理和編譯器優化在遞歸計算中表現更為高效。

selectgolangforhighpperformanceandcorrency,ifealforBackendServicesSandNetwork程序; selectpypypythonforrapiddevelopment,dataScience和machinelearningDuetoitsverserverserverserversator versator anderticality andextility andextentensivelibraries。

Golang和Python各有优势:Golang适合高性能和并发编程,Python适用于数据科学和Web开发。Golang以其并发模型和高效性能著称,Python则以简洁语法和丰富库生态系统著称。

Golang和Python分別在哪些方面更易用和學習曲線更平緩? Golang更適合高並發和高性能需求,學習曲線對有C語言背景的開發者較平緩。 Python更適合數據科學和快速原型設計,學習曲線對初學者非常平緩。

Golang和C 在性能競賽中的表現各有優勢:1)Golang適合高並發和快速開發,2)C 提供更高性能和細粒度控制。選擇應基於項目需求和團隊技術棧。

Golang適合快速開發和並發編程,而C 更適合需要極致性能和底層控制的項目。 1)Golang的並發模型通過goroutine和channel簡化並發編程。 2)C 的模板編程提供泛型代碼和性能優化。 3)Golang的垃圾回收方便但可能影響性能,C 的內存管理複雜但控制精細。

goimpactsdevelopmentpositationality throughspeed,效率和模擬性。 1)速度:gocompilesquicklyandrunseff,IdealforlargeProjects.2)效率:效率:ITScomprehenSevestAndardArdardArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdEcceSteral Depentencies,增強的Depleflovelmentimency.3)簡單性。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能