Gin 框架: 通過 Web 獲取服務(wù)元信息
介紹
通過一個(gè)完整例子,在 Gin 框架中嵌入 Web UI 獲取服務(wù)元信息。
名稱 | 詳情 |
---|---|
README | 如果本地有 README.md 文件,會展示 |
進(jìn)程信息 | 顯示進(jìn)程信息 |
API 列表 | 獲取 API 列表 |
Entry 列表 | Entry 列表,請參考詳情 |
Config 列表 | 列出 Config 文件信息 |
CA 證書 | 列出 TLS/SSL 證書信息 | |
依賴 | 列出 go.mod 信息 |
LICENSE | 如果本地有 LICENSE 文件,會展示 |
OS 信息 | 當(dāng)前 OS 信息 |
Go Env 信息 | Go 環(huán)境信息 |
Git 信息 | 如果是 Git 工程,會展示 |
Log 信息 | 展示 Log 原信息 |
Metrics | 展示 Prometheus Metrics |
我們將會使用 rk-boot 來啟動 Gin 服務(wù)。
請?jiān)L問如下地址獲取完整教程:
安裝
go get github.com/rookie-ninja/rk-boot
快速開始
為了完整展示,我們使用一個(gè) git 工程,并且添加 API。
1.創(chuàng)建 boot.yaml
除了開啟 gin.tv.enabled,我們還開啟了其他服務(wù),這樣就可以驗(yàn)證完整 TV 頁面。
請參考專欄里其他文章來獲取每個(gè)選項(xiàng)的詳細(xì)信息。
或者訪問:rk-boot 官方文檔。
--- gin: - name: greeter # Required port: 8080 # Required enabled: true # Required commonService: enabled: true # Optional, enable common service tv: enabled: true # Optional, enable TV sw: enabled: true # Optional, enable swagger UI interceptors: metricsProm: enabled: true
2.創(chuàng)建 main.go
// Copyright (c) 2021 rookie-ninja // // Use of this source code is governed by an Apache-style // license that can be found in the LICENSE file. package main import ( "context" "github.com/rookie-ninja/rk-boot" ) // Application entrance. func main() { // Create a new boot instance. boot := rkboot.NewBoot() // Bootstrap boot.Bootstrap(context.Background()) // Wait for shutdown sig boot.WaitForShutdownSig(context.Background())
}
3.文件夾結(jié)構(gòu)
.
├── LICENSE ├── README.md ├── boot.yaml ├── go.mod ├── go.sum └── main.go
4.驗(yàn)證
$ go run main.go
4.1 README
rk-boot 會讀取本地 README.md 文件,并展示在 TV 頁面中。
如果是打包編譯的情況,rk-boot 會尋找 .rk/README.md 路徑,可以通過 RK 命令行,方便編譯。
請參考:例子
4.2 進(jìn)程元信息
rk-boot 會讀取本地進(jìn)程信息。
4.3 API 列表
rk-boot 會讀取 Gin 內(nèi)部所有 API 列表。
4.4 Entry 列表
4.5 Config 列表
如果 boot.yaml 里有 config 入口,會顯示在這里。
下面的圖只是個(gè)例子截圖,上面的代碼不會有 Config,因?yàn)槲覀儧]有加入 Config。
4.6 證書
如果 boot.yaml 里有 cert 入口,會顯示在這里。
下面的圖只是個(gè)例子截圖,上面的代碼不會有 Cert,因?yàn)槲覀儧]有加入 Cert。
4.7 依賴
rk-boot 會讀取本地 go.mod 文件,并展示在 TV 頁面中。
如果是打包編譯的情況,rk-boot 會尋找 .rk/go.mod 路徑,可以通過 RK 命令行,方便編譯。
請參考:例子
4.8 OS 信息
rk-boot 會收集本地 OS 信息。
4.9 Go Env 信息
rk-boot 會收集本地 Go Env 信息。
4.10 Git 信息
rk-boot 會讀取本地 .git 文件,并展示在 TV 頁面中。
如果是打包編譯的情況,rk-boot 會尋找 .rk/rk.yaml 路徑,里面包含了 git 信息??梢酝ㄟ^ RK 命令行,方便編譯。
請參考:例子
4.11 Log 信息
rk-boot 會顯示目前在進(jìn)程中的所有 Log 實(shí)例信息。
4.12 Prometheus Metrics
rk-boot 如果開啟了 Prometheus 中間件,我們可以在這個(gè)頁面中看到 API 的基本監(jiān)控信息。