Skip to content

Commit 2e71a0e

Browse files
committed
Rename packages and consolidate view components
- Rename firefoxopen package to firefoxview - Rename w3mopenpage package to w3mview - Rename gintestpage package to mocksite - Rename Dump function to DumpPage - Add newUtf8Envs to fix CJK text rendering in w3m - Add Pane struct with injection via NewPaneWith - Streamline package structure and API design - Add English/Chinese comments - Rename test functions (TestNewTable0 to TestNewTable_Blank) - Use must.Done to reduce test boilerplate - Update go.mod and go.sum - Update release.yml with latest action versions - Update README.md and README.zh.md - Add SkipIfCommandNotFound to skip tests when w3m unavailable - Add TestShow_ChineseTable and TestShow_ChineseWithBadLocale - Add example tests
1 parent ce96823 commit 2e71a0e

38 files changed

+1522
-968
lines changed

.github/workflows/release.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ jobs:
1212
name: lint
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v4
16-
- uses: actions/setup-go@v5
15+
- uses: actions/checkout@v6
16+
- uses: actions/setup-go@v6
1717
with:
1818
go-version: stable
1919
cache: true
2020
- name: golangci-lint
21-
uses: golangci/golangci-lint-action@v8
21+
uses: golangci/golangci-lint-action@v9
2222
with:
2323
version: latest
2424
args: --timeout=5m
@@ -27,11 +27,11 @@ jobs:
2727
runs-on: ubuntu-latest
2828
strategy:
2929
matrix:
30-
go: [ "1.22.x", "1.23.x", "1.24.x", "1.25.x", "stable" ]
30+
go: [ "1.25.x", "stable" ]
3131
steps:
32-
- uses: actions/checkout@v4
32+
- uses: actions/checkout@v6
3333

34-
- uses: actions/setup-go@v5
34+
- uses: actions/setup-go@v6
3535
with:
3636
go-version: ${{ matrix.go }}
3737
cache: true
@@ -82,18 +82,18 @@ jobs:
8282
security-events: write
8383
steps:
8484
- name: Checkout repository
85-
uses: actions/checkout@v4
85+
uses: actions/checkout@v6
8686

8787
- name: Initialize CodeQL
88-
uses: github/codeql-action/init@v3
88+
uses: github/codeql-action/init@v4
8989
with:
9090
languages: go
9191

9292
- name: Auto Build
93-
uses: github/codeql-action/autobuild@v3
93+
uses: github/codeql-action/autobuild@v4
9494

9595
- name: Perform CodeQL Analysis
96-
uses: github/codeql-action/analyze@v3
96+
uses: github/codeql-action/analyze@v4
9797

9898
# 发布 Release
9999
release:
@@ -105,7 +105,7 @@ jobs:
105105
steps:
106106
# 1. 检出代码
107107
- name: Checkout code
108-
uses: actions/checkout@v4
108+
uses: actions/checkout@v6
109109
with:
110110
fetch-depth: 0 # 获取完整历史用于生成更好的 release notes
111111

README.md

Lines changed: 89 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/go-xlan/go-webpage/release.yml?branch=main&label=BUILD)](https://github.com/go-xlan/go-webpage/actions/workflows/release.yml?query=branch%3Amain)
22
[![GoDoc](https://pkg.go.dev/badge/github.com/go-xlan/go-webpage)](https://pkg.go.dev/github.com/go-xlan/go-webpage)
33
[![Coverage Status](https://img.shields.io/coveralls/github/go-xlan/go-webpage/main.svg)](https://coveralls.io/github/go-xlan/go-webpage?branch=main)
4-
[![Supported Go Versions](https://img.shields.io/badge/Go-1.22.8+-lightgrey.svg)](https://go.dev/)
4+
[![Supported Go Versions](https://img.shields.io/badge/Go-1.25+-lightgrey.svg)](https://go.dev/)
55
[![GitHub Release](https://img.shields.io/github/release/go-xlan/go-webpage.svg)](https://github.com/go-xlan/go-webpage/releases)
66
[![Go Report Card](https://goreportcard.com/badge/github.com/go-xlan/go-webpage)](https://goreportcard.com/report/github.com/go-xlan/go-webpage)
77

88
# go-webpage
99

10-
Convert Go struct slice to HTML table with browser automation.
10+
Convert Go struct slice to HTML table with Firefox/w3m output.
1111

1212
---
1313

@@ -20,8 +20,8 @@ Convert Go struct slice to HTML table with browser automation.
2020
## Main Features
2121

2222
🎯 **Struct to HTML Table**: Convert Go struct slices to formatted HTML tables with custom tag support
23-
**Browser Automation**: Open generated HTML in Firefox; render in w3m console
24-
🔄 **Test Server**: Built-in HTTP test server supporting rapid webpage development and testing
23+
**HTML Output**: Open generated HTML in Firefox; display via w3m console
24+
🔄 **HTTP Test Host**: Built-in HTTP test service supporting rapid webpage development and testing
2525
🌍 **Flexible Options**: Customizable table headers, tag names, and rendering configurations
2626
📋 **XSS Protection**: HTML escaping built-in to prevent XSS vulnerabilities
2727

@@ -43,23 +43,23 @@ import (
4343
"github.com/go-xlan/go-webpage/slice2table"
4444
)
4545

46-
type User struct {
46+
type Account struct {
4747
Name string `table:"姓名"`
4848
Age int `table:"年龄"`
4949
}
5050

5151
func main() {
52-
users := []*User{
52+
accounts := []*Account{
5353
{Name: "Alice", Age: 25},
5454
{Name: "Bob", Age: 30},
5555
}
5656

57-
htmlTable := slice2table.NewTable(users)
58-
fmt.Println(htmlTable)
57+
page := slice2table.NewTable(accounts)
58+
fmt.Println(page)
5959
}
6060
```
6161

62-
### Browser Output
62+
### Firefox Output
6363

6464
```go
6565
package main
@@ -69,8 +69,7 @@ import (
6969
"time"
7070

7171
"github.com/brianvoe/gofakeit/v7"
72-
"github.com/go-xlan/go-webpage/firefoxopen"
73-
"github.com/go-xlan/go-webpage/internal/utils"
72+
"github.com/go-xlan/go-webpage/firefoxview"
7473
"github.com/go-xlan/go-webpage/slice2table"
7574
"github.com/yyle88/must"
7675
)
@@ -91,18 +90,18 @@ func main() {
9190
newAdminInfo(),
9291
newAdminInfo(),
9392
}
94-
page1 := utils.NewPage("admins", slice2table.NewTable(admins))
93+
page1 := slice2table.NewTable(admins)
9594

9695
guests := []*GuestInfo{
9796
newGuestInfo(),
9897
newGuestInfo(),
9998
newGuestInfo(),
10099
}
101-
page2 := utils.NewPage("guests", slice2table.NewTable(guests))
100+
page2 := slice2table.NewTable(guests)
102101

103-
firefoxDraw := firefoxopen.NewFirefoxDraw()
104-
defer firefoxDraw.Close(time.Minute)
105-
firefoxDraw.ShowInNewTabs(page1, page2)
102+
pane := firefoxview.NewPane()
103+
defer pane.Close(time.Minute)
104+
pane.ShowInNewTabs(page1, page2)
106105
fmt.Println("done")
107106
}
108107

@@ -131,61 +130,60 @@ import (
131130
"time"
132131

133132
"github.com/brianvoe/gofakeit/v7"
134-
"github.com/go-xlan/go-webpage/internal/utils"
135133
"github.com/go-xlan/go-webpage/slice2table"
136-
"github.com/go-xlan/go-webpage/w3mopenpage"
134+
"github.com/go-xlan/go-webpage/w3mview"
137135
"github.com/yyle88/must"
138136
"github.com/yyle88/osexec"
139137
)
140138

141-
type User struct {
142-
ID string // 用户 ID
139+
type Account struct {
140+
ID string // 账户 ID
143141
Username string // 用户名
144-
Email string // 邮箱
142+
Mailbox string // 邮箱
145143
Role string // 角色(如 admin, guest, student)
146144
IsActive bool // 是否激活
147145
CreatedAt time.Time // 创建时间
148146
}
149147

150-
type Order struct {
151-
ID string // 订单 ID
152-
UserID string // 用户 ID
153-
Total float64 // 总金额
148+
type Invoice struct {
149+
ID string // 账单 ID
150+
AccountID string // 账户 ID
151+
Amount float64 // 金额
154152
Status string // 状态(如 pending, shipped)
155-
OrderedAt time.Time // 下单时间
153+
IssuedAt time.Time // 签发时间
156154
}
157155

158156
func main() {
159-
users := []*User{
160-
newUser(),
161-
newUser(),
162-
newUser(),
157+
accounts := []*Account{
158+
newAccount(),
159+
newAccount(),
160+
newAccount(),
163161
}
164-
page1 := utils.NewPage("users", slice2table.NewTable(users))
162+
page1 := slice2table.NewTable(accounts)
165163

166-
orders := []*Order{
167-
newOrder(),
168-
newOrder(),
169-
newOrder(),
164+
invoices := []*Invoice{
165+
newInvoice(),
166+
newInvoice(),
167+
newInvoice(),
170168
}
171-
page2 := utils.NewPage("orders", slice2table.NewTable(orders))
169+
page2 := slice2table.NewTable(invoices)
172170

173-
commandConfig := osexec.NewOsCommand().WithDebug()
174-
w3mopenpage.Show(commandConfig, page1)
175-
w3mopenpage.Show(commandConfig, page2)
171+
execConfig := osexec.NewOsCommand().WithDebug()
172+
w3mview.Show(execConfig, page1)
173+
w3mview.Show(execConfig, page2)
176174
fmt.Println("done")
177175
}
178176

179-
func newUser() *User {
180-
user := &User{}
181-
must.Done(gofakeit.Struct(user))
182-
return user
177+
func newAccount() *Account {
178+
account := &Account{}
179+
must.Done(gofakeit.Struct(account))
180+
return account
183181
}
184182

185-
func newOrder() *Order {
186-
order := &Order{}
187-
must.Done(gofakeit.Struct(order))
188-
return order
183+
func newInvoice() *Invoice {
184+
invoice := &Invoice{}
185+
must.Done(gofakeit.Struct(invoice))
186+
return invoice
189187
}
190188
```
191189

@@ -198,7 +196,7 @@ func newOrder() *Order {
198196
```go
199197
type Student struct {
200198
Name string `custom:"Student Name"`
201-
Grade int `custom:"Grade Level"`
199+
Grade int `custom:"Grade Rank"`
202200
}
203201

204202
students := []*Student{
@@ -214,8 +212,8 @@ table := slice2table.GenTable(students, options)
214212
```go
215213
import "github.com/go-xlan/go-webpage/slice2table/struct2table"
216214

217-
user := &User{Name: "Alice", Age: 25}
218-
table := struct2table.NewTable(user)
215+
account := &Account{Name: "Alice", Age: 25}
216+
table := struct2table.NewTable(account)
219217
```
220218

221219
## API Reference
@@ -227,58 +225,73 @@ table := struct2table.NewTable(user)
227225
- `NewOptions() *Options` - Create default options
228226
- `(opts *Options) WithTagName(tagName string) *Options` - Set custom tag name
229227

230-
### firefoxopen Package
228+
### struct2table Package
231229

232-
- `OpenInNewWindows(command *osexec.OsCommand, urls ...string)` - Open URLs in new Firefox windows
233-
- `OpenInNewTabs(command *osexec.OsCommand, urls ...string)` - Open URLs in new Firefox tabs
234-
- `NewFirefoxDraw() *FirefoxShow` - Create Firefox output handler
230+
- `NewTable[T any](object *T) string` - Convert single struct to HTML table
231+
- `GenTable[T any](object *T, options *slice2table.Options) string` - Generate table with custom options
235232

236-
### w3mopenpage Package
233+
### firefoxview Package
237234

238-
- `NewW3mDrawPage() *W3mShowPage` - Create w3m output handler
239-
- `Show(page string)` - Show single page in console
240-
- `ShowPages(pages ...string)` - Show multiple pages
235+
- `Open(execConfig *osexec.OsCommand, urls []string, mode string)` - Open URLs in Firefox with mode
236+
- `OpenInNewWindows(execConfig *osexec.OsCommand, urls ...string)` - Open URLs in new Firefox windows
237+
- `OpenInNewTabs(execConfig *osexec.OsCommand, urls ...string)` - Open URLs in new Firefox tabs
238+
- `NewPane() *Pane` - Create Firefox output pane with default config
239+
- `NewPaneWith(pageSite *mocksite.PageSite, execConfig *osexec.OsCommand) *Pane` - Create pane with custom config
240+
- `(p *Pane) Close(waitTime time.Duration)` - Close pane when wait time elapses
241+
- `(p *Pane) ShowInNewWindows(pages ...string)` - Show pages in new windows
242+
- `(p *Pane) ShowInNewTabs(pages ...string)` - Show pages in new tabs
243+
- `(p *Pane) Show(pages []string, mode string)` - Show pages with mode
244+
- `(p *Pane) Open(pages []string, mode string)` - Alias of Show
241245

242-
### gintestpage Package
246+
### w3mview Package
243247

244-
- `NewService() *Service` - Create HTTP test server
245-
- `SetPage(path string, page []byte) string` - Set page and get URL
246-
- `GetLink(path string) string` - Get URL of page path
248+
- `Show(execConfig *osexec.OsCommand, page string)` - Display HTML page via w3m console
249+
- `Open(execConfig *osexec.OsCommand, link string)` - Open URL via w3m console
250+
- `DumpPage(execConfig *osexec.OsCommand, page string) string` - Process HTML and get text output
251+
- `DumpLink(execConfig *osexec.OsCommand, link string) string` - Fetch URL and return text
252+
- `NewPane() *Pane` - Create w3m output pane with default config
253+
- `NewPaneWith(pageSite *mocksite.PageSite, execConfig *osexec.OsCommand) *Pane` - Create pane with custom config
254+
- `(p *Pane) Close()` - Close pane and release resources
255+
- `(p *Pane) Show(page string)` - Show single page via pane
256+
- `(p *Pane) ShowPages(pages ...string)` - Show multiple pages via pane
247257

248-
### utils Package
258+
### mocksite Package
249259

250-
- `NewPage(subject string, content string) string` - Create complete HTML page with escaping
260+
- `NewPageSite() *PageSite` - Create HTTP test instance
261+
- `(s *PageSite) Close()` - Close test instance and release resources
262+
- `(s *PageSite) SetPage(path string, page []byte) string` - Set page and get access link
263+
- `(s *PageSite) GetLink(path string) string` - Get URL of page path
251264

252265
## Examples
253266

254267
Check out the [examples](internal/demos/) path with more usage patterns:
255268

256-
- [demo1x](internal/demos/demo1x/) - Gin test server with Firefox automation
269+
- [demo1x](internal/demos/demo1x/) - Mock site service with Firefox automation
257270
- [demo2x](internal/demos/demo2x/) - Multiple tables in Firefox tabs
258271
- [demo3x](internal/demos/demo3x/) - Console output with w3m
259272
- [demo4x](internal/demos/demo4x/) - W3m page output with multiple datasets
260273

261274
<!-- TEMPLATE (EN) BEGIN: STANDARD PROJECT FOOTER -->
262-
<!-- VERSION 2025-09-26 07:39:27.188023 +0000 UTC -->
275+
<!-- VERSION 2025-11-25 03:52:28.131064 +0000 UTC -->
263276

264277
## 📄 License
265278

266-
MIT License. See [LICENSE](LICENSE).
279+
MIT License - see [LICENSE](LICENSE).
267280

268281
---
269282

270-
## 🤝 Contributing
283+
## 💬 Contact & Feedback
271284

272285
Contributions are welcome! Report bugs, suggest features, and contribute code:
273286

274-
- 🐛 **Found a mistake?** Open an issue on GitHub with reproduction steps
275-
- 💡 **Have a feature idea?** Create an issue to discuss the suggestion
276-
- 📖 **Documentation confusing?** Report it so we can improve
287+
- 🐛 **Mistake reports?** Open an issue on GitHub with reproduction steps
288+
- 💡 **Fresh ideas?** Create an issue to discuss
289+
- 📖 **Documentation confusing?** Report it so we can enhance it
277290
- 🚀 **Need new features?** Share the use cases to help us understand requirements
278-
-**Performance issue?** Help us optimize through reporting slow operations
291+
-**Performance issue?** Help us optimize via reporting slow operations
279292
- 🔧 **Configuration problem?** Ask questions about complex setups
280-
- 📢 **Follow project progress?** Watch the repo to get new releases and features
281-
- 🌟 **Success stories?** Share how this package improved the workflow
293+
- 📢 **Track project progress?** Watch the repo to get new releases and features
294+
- 🌟 **Success stories?** Share how this package enhanced the workflow
282295
- 💬 **Feedback?** We welcome suggestions and comments
283296

284297
---
@@ -292,8 +305,8 @@ New code contributions, follow this process:
292305
3. **Navigate**: Navigate to the cloned project (`cd repo-name`)
293306
4. **Branch**: Create a feature branch (`git checkout -b feature/xxx`).
294307
5. **Code**: Implement the changes with comprehensive tests
295-
6. **Testing**: (Golang project) Ensure tests pass (`go test ./...`) and follow Go code style conventions
296-
7. **Documentation**: Update documentation to support client-facing changes and use significant commit messages
308+
6. **Testing**: (Golang project) Ensure tests pass (`go test ./...`) and adhere to Go code style conventions
309+
7. **Documentation**: Update documentation to support client-facing changes
297310
8. **Stage**: Stage changes (`git add .`)
298311
9. **Commit**: Commit changes (`git commit -m "Add feature xxx"`) ensuring backward compatible code
299312
10. **Push**: Push to the branch (`git push origin feature/xxx`).

0 commit comments

Comments
 (0)