MCPcopy Create free account
hub / github.com/nhost/nhost / ApplyJSONPatches

Function ApplyJSONPatches

cli/cmd/config/validate.go:75–111  ·  view source on GitHub ↗
(
	cfg T,
	overlayPath string,
)

Source from the content-addressed store, hash-verified

73}
74
75func ApplyJSONPatches[T any](
76 cfg T,
77 overlayPath string,
78) (*T, error) {
79 f, err := os.Open(overlayPath)
80 if err != nil {
81 return nil, fmt.Errorf("failed to open json patches file: %w", err)
82 }
83 defer f.Close()
84
85 patchesb, err := io.ReadAll(f)
86 if err != nil {
87 return nil, fmt.Errorf("failed to read json patches file: %w", err)
88 }
89
90 cfgb, err := json.Marshal(cfg)
91 if err != nil {
92 return nil, fmt.Errorf("failed to marshal config: %w", err)
93 }
94
95 patch, err := jsonpatch.DecodePatch(patchesb)
96 if err != nil {
97 return nil, fmt.Errorf("failed to apply json patches: %w", err)
98 }
99
100 cfgb, err = patch.Apply(cfgb)
101 if err != nil {
102 return nil, fmt.Errorf("failed to apply json patches: %w", err)
103 }
104
105 var r T
106 if err := json.Unmarshal(cfgb, &r); err != nil {
107 return nil, fmt.Errorf("failed to unmarshal config: %w", err)
108 }
109
110 return &r, nil
111}
112
113func Validate(
114 ce *clienv.CliEnv,

Callers 4

ValidateFunction · 0.92
ValidateFunction · 0.85
ValidateRemoteFunction · 0.85
CopyConfigFunction · 0.85

Calls 3

ErrorfMethod · 0.80
ApplyMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected