搜尋
首頁後端開發GolangINFINI Framework 入門 - 我們用於建立企業 golang 應用程式的自製框架

Getting Started with INFINI Framework - Our homemade framework for building enterprise golang applications

我們最近開源了用於建立企業 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中文網其他相關文章!

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
Golang vs. Python:並發和多線程Golang vs. Python:並發和多線程Apr 17, 2025 am 12:20 AM

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

Golang和C:性能的權衡Golang和C:性能的權衡Apr 17, 2025 am 12:18 AM

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

Golang vs. Python:申請和用例Golang vs. Python:申請和用例Apr 17, 2025 am 12:17 AM

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

Golang vs. Python:主要差異和相似之處Golang vs. Python:主要差異和相似之處Apr 17, 2025 am 12:15 AM

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

Golang vs. Python:易於使用和學習曲線Golang vs. Python:易於使用和學習曲線Apr 17, 2025 am 12:12 AM

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

表演競賽:Golang vs.C表演競賽:Golang vs.CApr 16, 2025 am 12:07 AM

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

Golang vs.C:代碼示例和績效分析Golang vs.C:代碼示例和績效分析Apr 15, 2025 am 12:03 AM

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

Golang的影響:速度,效率和簡單性Golang的影響:速度,效率和簡單性Apr 14, 2025 am 12:11 AM

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

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

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

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
1 個月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
1 個月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
1 個月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.聊天命令以及如何使用它們
1 個月前By尊渡假赌尊渡假赌尊渡假赌

熱工具

SublimeText3 英文版

SublimeText3 英文版

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

SecLists

SecLists

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

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

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

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器

EditPlus 中文破解版

EditPlus 中文破解版

體積小,語法高亮,不支援程式碼提示功能