-
Notifications
You must be signed in to change notification settings - Fork 8
/
clients_cache.go
42 lines (32 loc) · 1011 Bytes
/
clients_cache.go
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
package openapi
import (
"fmt"
"os"
"path/filepath"
gencontext "github.com/mify-io/mify/pkg/generator/gen-context"
"gopkg.in/yaml.v2"
)
const (
CLIENTS_FILENAME = ".clients.yaml"
)
func updateClientsList(ctx *gencontext.GenContext) error {
tmpDir := ctx.GetWorkspace().GetServiceCacheDirectory(ctx.GetServiceName())
ctx.Logger.Infof("updating clients list in: %s", tmpDir)
err := os.MkdirAll(tmpDir, 0755)
if err != nil {
return fmt.Errorf("failed to write clients list file: %w", err)
}
f, err := os.OpenFile(filepath.Join(tmpDir, CLIENTS_FILENAME), os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
if err != nil {
return fmt.Errorf("failed to write clients list file: %w", err)
}
list := make([]string, 0, len(ctx.MustGetMifySchema().OpenAPI.Clients))
for client := range ctx.MustGetMifySchema().OpenAPI.Clients {
list = append(list, client)
}
err = yaml.NewEncoder(f).Encode(list)
if err != nil {
return fmt.Errorf("failed to write clients list file: %w", err)
}
return nil
}