mirror of
https://github.com/ArvinLovegood/go-stock.git
synced 2025-07-19 00:00:09 +08:00
- 实现了 MarkdownTable 函数,可以将结构体或结构体切片转换为 Markdown 表格格式 - 添加了相关辅助函数,如 markdownSingleStruct、markdownStructSlice、shouldSkip 等 - 示例结构体 User 和 Address 用于演示功能 - 新增 struct_to_markdown_test.go 文件进行测试验证
55 lines
966 B
Go
55 lines
966 B
Go
package util
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestMd(t *testing.T) {
|
|
// 示例使用:单个结构体
|
|
user := User{
|
|
Name: "张三",
|
|
Age: 30,
|
|
Email: "zhangsan@example.com",
|
|
Address: Address{
|
|
City: "北京",
|
|
Country: "中国",
|
|
},
|
|
Phones: []string{"13800138000", "13900139000"},
|
|
Active: true,
|
|
}
|
|
|
|
fmt.Println("单个结构体转换:")
|
|
fmt.Println(MarkdownTable(user))
|
|
fmt.Println()
|
|
|
|
// 示例使用:结构体切片
|
|
users := []User{
|
|
{
|
|
Name: "张三",
|
|
Age: 30,
|
|
Email: "zhangsan@example.com",
|
|
Address: Address{
|
|
City: "北京",
|
|
Country: "中国",
|
|
},
|
|
Phones: []string{"13800138000"},
|
|
Active: true,
|
|
},
|
|
{
|
|
Name: "李四",
|
|
Age: 25,
|
|
Email: "lisi@example.com",
|
|
Address: Address{
|
|
City: "上海",
|
|
Country: "中国",
|
|
},
|
|
Phones: []string{"13900139000", "13700137000"},
|
|
Active: false,
|
|
},
|
|
}
|
|
|
|
fmt.Println("结构体切片转换:")
|
|
fmt.Println(MarkdownTable(users))
|
|
}
|