MCPcopy Index your code
hub / github.com/APIParkLab/APIPark / saveCsv

Function saveCsv

initialization.go:67–90  ·  view source on GitHub ↗
(as map[string]*Access, key string)

Source from the content-addressed store, hash-verified

65 return version
66}
67func saveCsv(as map[string]*Access, key string) string {
68 buf := &bytes.Buffer{}
69 w := csv.NewWriter(buf)
70 err := w.Write([]string{"group", "name", "cname", "desc"})
71 if err != nil {
72 return ""
73 }
74 list := utils.MapToSliceNoKey(as)
75 sort.Sort(AccessListSort(list))
76 for _, i := range list {
77 err := w.Write([]string{i.Group, i.Name, i.Cname, i.Desc})
78 if err != nil {
79 return ""
80 }
81 }
82 w.Flush()
83 filePath := fmt.Sprintf("access.%s.csv", key)
84 err = os.WriteFile(filePath, buf.Bytes(), 0666)
85 if err != nil {
86 log.Fatal(err)
87
88 }
89 return filePath
90}
91
92type AccessListSort []*Access
93

Callers 1

doCheckFunction · 0.85

Calls 4

AccessListSortTypeAlias · 0.85
WriteMethod · 0.80
FlushMethod · 0.80
SortMethod · 0.65

Tested by

no test coverage detected