Skip to content

go-zwbc/go-webtablezh

Repository files navigation

GitHub Workflow Status (branch) GoDoc Coverage Status Supported Go Versions GitHub Release Go Report Card

go-webtablezh

Lightweight Go package to generate HTML tables with Chinese function names


CHINESE README

中文说明

Main Features

🎯 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

Installation

go get github.com/go-zwbc/go-webtablezh

Quick Start

Basic Usage

package 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)
}

Setting Alignment

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向右对齐(),
}

Batch Data Addition

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网页表格()

Using Various Data Types

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网页表格()

Using W3M Command-Line Rendering

import "github.com/go-zwbc/go-webtablezh/w3mdebugzh"

// Show table with heading
w3mdebugzh.Show标题内容("Student Scores", tab.Gen网页表格())

API Reference

Create Column

col := webtablezh.NewC表格单列("Column Name")

Add Data

  • V值(string) - Add string value
  • V整数(int) - Add int value
  • V两位小数(float64) - Add float64 with 2 fraction digits
  • V三位小数(float64) - Add float64 with 3 fraction digits
  • V小数(float64, int) - Add float64 with custom precision
  • V布尔值(bool) - Add boolean value
  • V时间(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

Style Setting

  • H样() - Get heading style configuration
  • D样() - Get data element style configuration

Alignment

  • C居中对齐() - Center alignment
  • L向左对齐() - Left alignment
  • R向右对齐() - Right alignment

Generate Table

html := tab.Gen网页表格()

XSS Protection

This package auto-escapes HTML content to prevent XSS injection attacks.


📄 License

MIT License - see LICENSE.


💬 Contact & Feedback

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

🔧 Development

New code contributions, follow this process:

  1. Fork: Fork the repo on GitHub (using the webpage UI).
  2. Clone: Clone the forked project (git clone https://github.com/yourname/repo-name.git).
  3. Navigate: Navigate to the cloned project (cd repo-name)
  4. Branch: Create a feature branch (git checkout -b feature/xxx).
  5. Code: Implement the changes with comprehensive tests
  6. Testing: (Golang project) Ensure tests pass (go test ./...) and adhere to Go code style conventions
  7. Documentation: Update documentation to support client-facing changes
  8. Stage: Stage changes (git add .)
  9. Commit: Commit changes (git commit -m "Add feature xxx") ensuring backward compatible code
  10. Push: Push to the branch (git push origin feature/xxx).
  11. PR: Open a merge request on GitHub (on the GitHub webpage) with detailed description.

Please ensure tests pass and include relevant documentation updates.


🌟 Support

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! 🎉🎉🎉


GitHub Stars

Stargazers

About

使用go语言拼接网络表格

Resources

License

Stars

Watchers

Forks

Packages

No packages published