Lightweight Go package to generate HTML tables with Chinese function names
🎯 Fluent Chain API: Elegant and concise method chaining pattern 🔒 Safe HTML Escaping: Auto protection against XSS injection attacks 🎨 Flexible Styling: Independent alignment settings on heading and data elements 📊 Auto Column Padding: Prevents table collapse with automatic height matching 🌐 W3M Integration: Direct HTML table rendering in the command-line
go get github.com/go-zwbc/go-webtablezhpackage main
import (
"fmt"
"github.com/go-zwbc/go-webtablezh/webtablezh"
)
func main() {
// Create table columns and add data
tab := webtablezh.T表格行列{
webtablezh.NewC表格单列("Name").V值("Alice").V值("Bob"),
webtablezh.NewC表格单列("Age").V整数(25).V整数(30),
webtablezh.NewC表格单列("Score").V两位小数(89.5).V两位小数(92.3),
}
// Generate HTML table
html := tab.Gen网页表格()
fmt.Println(html)
}tab := webtablezh.T表格行列{
// H样() sets heading style, D样() sets data element style
webtablezh.NewC表格单列("Name").V值("Alice").V值("Bob").
H样().L向左对齐().D样().L向左对齐(),
webtablezh.NewC表格单列("Age").V整数(25).V整数(30).
H样().C居中对齐().D样().C居中对齐(),
webtablezh.NewC表格单列("Score").V两位小数(89.5).V两位小数(92.3).
H样().R向右对齐().D样().R向右对齐(),
}type Student struct {
Name string
Age int
Score float64
}
students := []Student{
{"Alice", 25, 89.5},
{"Bob", 30, 92.3},
{"Carol", 28, 87.8},
}
// Define table columns
name := webtablezh.NewC表格单列("Name").H样().L向左对齐().D样().L向左对齐()
age := webtablezh.NewC表格单列("Age").H样().C居中对齐().D样().C居中对齐()
score := webtablezh.NewC表格单列("Score").H样().R向右对齐().D样().R向右对齐()
// Batch add data
for _, s := range students {
name.V值(s.Name)
age.V整数(s.Age)
score.V两位小数(s.Score)
}
tab := webtablezh.T表格行列{name, age, score}
html := tab.Gen网页表格()import "time"
tab := webtablezh.T表格行列{
webtablezh.NewC表格单列("Task").
V值("Task A").V值("Task B").V值("Task C"),
webtablezh.NewC表格单列("Completed").
V布尔值(true).V布尔值(false).V布尔值(true),
webtablezh.NewC表格单列("Progress").
V百分比(0.75).V百分比(0.30).V百分比(1.0),
webtablezh.NewC表格单列("Deadline").
V日期(time.Now()).V日期(time.Now().AddDate(0, 0, 7)).V日期(time.Now().AddDate(0, 1, 0)),
webtablezh.NewC表格单列("Precise").
V小数(3.14159, 5).V小数(2.71828, 5).V小数(1.41421, 5),
}
html := tab.Gen网页表格()import "github.com/go-zwbc/go-webtablezh/w3mdebugzh"
// Show table with heading
w3mdebugzh.Show标题内容("Student Scores", tab.Gen网页表格())col := webtablezh.NewC表格单列("Column Name")V值(string)- Add string valueV整数(int)- Add int valueV两位小数(float64)- Add float64 with 2 fraction digitsV三位小数(float64)- Add float64 with 3 fraction digitsV小数(float64, int)- Add float64 with custom precisionV布尔值(bool)- Add boolean valueV时间(time.Time)- Add time (format: 2006-01-02 15:04:05)V日期(time.Time)- Add date (format: 2006-01-02)V百分比(float64)- Add percentage (0.5 shows as 50.00%)V错误(error)- Add error message
H样()- Get heading style configurationD样()- Get data element style configuration
C居中对齐()- Center alignmentL向左对齐()- Left alignmentR向右对齐()- Right alignment
html := tab.Gen网页表格()This package auto-escapes HTML content to prevent XSS injection attacks.
MIT License - see LICENSE.
Contributions are welcome! Report bugs, suggest features, and contribute code:
- 🐛 Mistake reports? Open an issue on GitHub with reproduction steps
- 💡 Fresh ideas? Create an issue to discuss
- 📖 Documentation confusing? Report it so we can enhance it
- 🚀 Need new features? Share the use cases to help us understand requirements
- ⚡ Performance issue? Help us optimize via reporting slow operations
- 🔧 Configuration problem? Ask questions about complex setups
- 📢 Track project progress? Watch the repo to get new releases and features
- 🌟 Success stories? Share how this package enhanced the workflow
- 💬 Feedback? We welcome suggestions and comments
New code contributions, follow this process:
- Fork: Fork the repo on GitHub (using the webpage UI).
- Clone: Clone the forked project (
git clone https://github.com/yourname/repo-name.git). - Navigate: Navigate to the cloned project (
cd repo-name) - Branch: Create a feature branch (
git checkout -b feature/xxx). - Code: Implement the changes with comprehensive tests
- Testing: (Golang project) Ensure tests pass (
go test ./...) and adhere to Go code style conventions - Documentation: Update documentation to support client-facing changes
- Stage: Stage changes (
git add .) - Commit: Commit changes (
git commit -m "Add feature xxx") ensuring backward compatible code - Push: Push to the branch (
git push origin feature/xxx). - PR: Open a merge request on GitHub (on the GitHub webpage) with detailed description.
Please ensure tests pass and include relevant documentation updates.
Welcome to contribute to this project via submitting merge requests and reporting issues.
Project Support:
- ⭐ Give GitHub stars if this project helps you
- 🤝 Share with teammates and (golang) programming friends
- 📝 Write tech blogs about development tools and workflows - we provide content writing support
- 🌟 Join the ecosystem - committed to supporting open source and the (golang) development scene
Have Fun Coding with this package! 🎉🎉🎉