v0.1.2

內部套件

最後更新


本頁記錄 internal/ui 與 internal/parser 的匯出型別與函式,供修改或擴充原始碼時參考;兩者位於 internal/,無法從其他 module import。

internal/ui


TUI


  1. type TUI struct {
  2. App *tview.Application
  3. Pages *tview.Pages
  4. LeftView *tview.List
  5. RightView *tview.TextView
  6. HintView *tview.TextView
  7. Watcher *fsnotify.Watcher
  8. Filepath string
  9. Requests []*Request
  10. Mu sync.RWMutex
  11. }

欄位說明
Apptview 應用程式;背景 goroutine 的回應渲染與提示列更新經由 App.QueueUpdateDraw
Pages建立後未加入版面,目前未使用
LeftView請求清單(API 面板)
RightView請求預覽與回應(Info 面板)
HintView底部一行提示列
Watcher由 main 指派的 fsnotify 監控器
Filepath目前載入的 .http 路徑,由 parser.ReadFile 設定
Requests解析結果;讀寫須持有 Mu
Mu保護 Requests 的讀寫鎖

Request


  1. type Request struct {
  2. Name string
  3. Method string
  4. URL string
  5. Headers map[string]string
  6. Body string
  7. }

一個 .http 請求區塊的解析結果;Headers 同名 Key 以最後一筆為準。

函式與方法


符號簽章說明
NewTUIfunc NewTUI() *TUI建立雙欄版面與提示列,註冊全域按鍵(<kbd>Tab</kbd>、<kbd>←</kbd>、<kbd>→</kbd>、<kbd>Ctrl+C</kbd>、<kbd>Esc</kbd>)
UpdateLeftViewfunc (t *TUI) UpdateLeftView()以 Requests 重建清單、綁定 <kbd>Enter</kbd> 送出與游標預覽,並預覽第一個請求

internal/parser


符號簽章說明
ReadFilefunc ReadFile(t *ui.TUI, path string) ([]*ui.Request, error)設定 t.Filepath、解析整個檔案、在 Mu 保護下寫入 t.Requests,並於呼叫端 goroutine 呼叫 UpdateLeftView;開檔或讀取失敗回傳包裝後的錯誤,t.Requests 不變
WatchFilefunc WatchFile(t *ui.TUI)讀取 t.Watcher 的事件與錯誤直到 channel 關閉;fsnotify.Write/fsnotify.Create 以 200ms 去抖動後呼叫 ReloadFile
ReloadFilefunc ReloadFile(t *ui.TUI)顯示 Edited at,以 ReadFile 重新解析 t.Filepath,再於事件迴圈內把游標設為清單目前索引(重建後為 0)並顯示 Reloaded at;失敗時以紅字顯示錯誤

語法細節見 .http 檔案格式,重載行為見 存檔即時重載。
EN