MCPcopy Index your code
hub / github.com/coder/coder / generateIconList

Function generateIconList

scripts/gensite/generate_icon_list.go:11–51  ·  view source on GitHub ↗
(path string)

Source from the content-addressed store, hash-verified

9)
10
11func generateIconList(path string) int {
12 if path == "" {
13 return 0 // skip
14 }
15
16 files, err := os.ReadDir("site/static/icon/")
17 if err != nil {
18 _, _ = fmt.Println("failed to read site/static/icon/ directory")
19 _, _ = fmt.Println("err:", err.Error())
20 return 71 // OSERR
21 }
22
23 icons := make([]string, len(files))
24 i := 0
25 for _, file := range files {
26 if !file.Type().IsRegular() {
27 continue
28 }
29
30 icons[i] = file.Name()
31 i++
32 }
33 icons = icons[:i]
34
35 iconsJSON, err := json.Marshal(icons)
36 if err != nil {
37 _, _ = fmt.Println("failed to serialize JSON")
38 _, _ = fmt.Println("err:", err.Error())
39 return 70 // SOFTWARE
40 }
41
42 if err := atomicwrite.File(path, iconsJSON); err != nil {
43 _, _ = fmt.Println("failed to write JSON")
44 _, _ = fmt.Println("err:", err.Error())
45 return 74 // IOERR
46 }
47
48 _, _ = fmt.Println(green.Sprintf("==>"), path)
49
50 return 0
51}

Callers 1

mainFunction · 0.85

Calls 6

FileFunction · 0.92
ReadDirMethod · 0.80
TypeMethod · 0.65
NameMethod · 0.65
ErrorMethod · 0.45
MarshalMethod · 0.45

Tested by

no test coverage detected