INFINI Framework 入門 - 我們用於建立企業 golang 應用程式的自製框架
我們最近開源了用於建立企業 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中文網其他相關文章!

熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

Go語言在構建高效且可擴展的系統中表現出色,其優勢包括:1.高性能:編譯成機器碼,運行速度快;2.並發編程:通過goroutines和channels簡化多任務處理;3.簡潔性:語法簡潔,降低學習和維護成本;4.跨平台:支持跨平台編譯,方便部署。

Golang在並發性上優於C ,而C 在原始速度上優於Golang。 1)Golang通過goroutine和channel實現高效並發,適合處理大量並發任務。 2)C 通過編譯器優化和標準庫,提供接近硬件的高性能,適合需要極致優化的應用。

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

Golang在性能和可擴展性方面優於Python。 1)Golang的編譯型特性和高效並發模型使其在高並發場景下表現出色。 2)Python作為解釋型語言,執行速度較慢,但通過工具如Cython可優化性能。

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

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

C 更適合需要直接控制硬件資源和高性能優化的場景,而Golang更適合需要快速開發和高並發處理的場景。 1.C 的優勢在於其接近硬件的特性和高度的優化能力,適合遊戲開發等高性能需求。 2.Golang的優勢在於其簡潔的語法和天然的並發支持,適合高並發服務開發。

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