{"id":28399896,"url":"https://github.com/fish-tennis/csv","last_synced_at":"2026-02-28T13:10:53.266Z","repository":{"id":257825608,"uuid":"871527094","full_name":"fish-tennis/csv","owner":"fish-tennis","description":"parse csv data to object(struct,protobuf,map[K]V,slice[E])","archived":false,"fork":false,"pushed_at":"2025-05-12T08:19:44.000Z","size":42,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-07T01:35:09.455Z","etag":null,"topics":["csv","csv-parser"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fish-tennis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-10-12T07:56:26.000Z","updated_at":"2025-05-12T08:18:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"69ac4a28-6b25-42b8-a5cb-1966955a8460","html_url":"https://github.com/fish-tennis/csv","commit_stats":null,"previous_names":["fish-tennis/csv"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/fish-tennis/csv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fish-tennis%2Fcsv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fish-tennis%2Fcsv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fish-tennis%2Fcsv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fish-tennis%2Fcsv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fish-tennis","download_url":"https://codeload.github.com/fish-tennis/csv/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fish-tennis%2Fcsv/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29935068,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-28T13:00:17.143Z","status":"ssl_error","status_checked_at":"2026-02-28T12:59:13.669Z","response_time":90,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csv","csv-parser"],"created_at":"2025-06-01T08:11:36.684Z","updated_at":"2026-02-28T13:10:53.247Z","avatar_url":"https://github.com/fish-tennis.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# csv\nparse csv data to object(struct,protobuf,map[K]V,slice[E])\n\n读取csv数据,转换成对象(struct,protobuf,map[K]V,slice[E]等),支持自定义解析接口,以及结构嵌套(支持2层)\n\n# 示例\n```go\n// 模拟一个物品配置结构\ntype ItemCfg struct {\n  CfgId  int32  `json:\"CfgId,omitempty\"`  // 配置id\n  Name   string `json:\"Name,omitempty\"`   // 物品名\n  Detail string `json:\"Detail,omitempty\"` // 物品描述\n  Unique bool   `json:\"Unique,omitempty\"` // 是否是不可叠加的物品\n}\n```\n# csv数据转换成map\n```go\nrows := [][]string{\n    {\"CfgId\", \"Name\", \"Detail\", \"Unique\", \"unknownColumnTest\"},\n    {\"1\", \"普通物品1\", \"普通物品1详细信息\", \"false\", \"123\"},\n    {\"2\", \"普通物品2\", \"普通物品2详细信息\", \"false\", \"test\"},\n    {\"3\", \"装备3\", \"装备3详细信息\", \"true\", \"\"},\n}\nm := make(map[int32]*ItemCfg)\nerr := ReadCsvFromDataMap(rows, m, nil)\n```\n\n# csv数据转换成slice\n```go\nrows := [][]string{\n    {\"CfgId\", \"Name\", \"Detail\", \"Unique\", \"unknownColumnTest\"},\n    {\"1\", \"普通物品1\", \"普通物品1详细信息\", \"false\", \"123\"},\n    {\"2\", \"普通物品2\", \"普通物品2详细信息\", \"false\", \"test\"},\n    {\"3\", \"装备3\", \"装备3详细信息\", \"true\", \"\"},\n}\ns := make([]*ItemCfg, 0)\ns,_ = ReadCsvFromDataSlice(rows, s, nil)\n```\n\n# key-value格式的csv数据转换成对象\n```go\ntype Settings struct {\n  ImageQuality int\n  Volume       int\n  Language     string\n}\nrows := [][]string{\n  {\"Key\", \"Value\", \"comment\"},\n  {\"ImageQuality\", \"100\", \"画质设置\"},\n  {\"Volume\", \"80\", \"音量设置\"},\n  {\"Language\", \"Simplified Chinese\", \"语言设置\"},\n}\nsettings := new(Settings)\nerr := ReadCsvFromDataObject(rows, settings, nil)\n```\n\n# 自定义解析接口\n```go\nrows := [][]string{\n    {\"CfgId\", \"Color\", \"ColorFlags\"},\n    {\"1\", \"Red\", \"Red;Green;Blue\"},\n    {\"2\", \"Gray\", \"Gray;Yellow\"},\n    {\"3\", \"\", \"\"},\n}\ntype colorCfg struct {\n    CfgId      int32\n    Color      Color // Color是protobuf定义的枚举\n    ColorFlags int32 // 颜色的组合值,如 Red | Green\n}\noption := DefaultCsvOption\n// 注册颜色枚举的自定义解析接口,csv中可以直接填写颜色对应的字符串\noption.RegisterConverterByType(reflect.TypeOf(Color(0)), func(obj any, columnName, fieldStr string) any {\n    if colorValue, ok := Color_value[\"Color_\"+fieldStr]; ok {\n        return Color(colorValue)\n    }\n    return Color(0)\n})\n// 注册列名对应的解析接口\n// 这里的ColorFlags列演示了一种特殊需求: 颜色的组合值用更易读的方式在csv中填写\noption.RegisterConverterByColumnName(\"ColorFlags\", func(obj any, columnName, fieldStr string) any {\n    colorStrSlice := strings.Split(fieldStr, \";\")\n    flags := int32(0)\n    for _, colorStr := range colorStrSlice {\n        if colorValue, ok := Color_value[\"Color_\"+colorStr]; ok \u0026\u0026 colorValue \u003e 0 {\n            flags |= 1 \u003c\u003c (colorValue - 1)\n        }\n    }\n    return flags\n})\nm := make(map[int]*colorCfg)\nerr := ReadCsvFromDataMap(rows, m, \u0026option)\n```\n\n# 嵌套结构\n详见csv_test.go里的TestNestStruct用例\n\n# 更多示例\n游戏项目中经常使用csv作为配置文件,并需要支持热更新(服务器不重启的情况下,重新加载配置数据)\n\n可参考[gserver](https://github.com/fish-tennis/gserver)中的配置数据的使用方式(https://github.com/fish-tennis/gserver/tree/main/cfg)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffish-tennis%2Fcsv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffish-tennis%2Fcsv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffish-tennis%2Fcsv/lists"}