-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzapi-command.go
More file actions
50 lines (40 loc) · 1.06 KB
/
zapi-command.go
File metadata and controls
50 lines (40 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"context"
"encoding/json"
. "github.com/theshashankpal/api-collector/logger"
"os"
"strings"
)
var zap = LogFields{Key: "layer", Value: "zapi"}
type ZAPICommands struct {
FunctionName string `json:"function_name"`
Command string `json:"command"`
}
type ZAPICommandsList struct {
Commands []ZAPICommands `json:"zapi_commands"`
}
func WriteZAPICommands(ctx context.Context, zapiCommandsMap map[string][]string, file *os.File) error {
// Write REST APIs to a file
zapiCommandsList := ZAPICommandsList{
Commands: make([]ZAPICommands, 0),
}
for key, value := range zapiCommandsMap {
functionName := strings.TrimSpace(strings.Split(key, ":")[3])
tempZAPICommand := ZAPICommands{
FunctionName: functionName,
Command: value[0],
}
zapiCommandsList.Commands = append(zapiCommandsList.Commands, tempZAPICommand)
}
jsonData, err := json.MarshalIndent(zapiCommandsList, "", " ")
if err != nil {
return err
}
// Write the JSON data to the file
_, err = file.Write(jsonData)
if err != nil {
return err
}
return nil
}