MCPcopy
hub / github.com/cloudflare/cloudflared / rawNetworkInformationWriter

Function rawNetworkInformationWriter

diagnostic/diagnostic.go:237–267  ·  view source on GitHub ↗
(resultMap map[string]networkCollectionResult)

Source from the content-addressed store, hash-verified

235}
236
237func rawNetworkInformationWriter(resultMap map[string]networkCollectionResult) (string, error) {
238 // nolint: gosec // Intentionally creating a temporary diagnostic file in the OS temp directory.
239 networkDumpHandle, err := os.Create(filepath.Join(os.TempDir(), rawNetworkBaseName))
240 if err != nil {
241 return "", ErrCreatingTemporaryFile
242 }
243
244 defer func() { _ = networkDumpHandle.Close() }()
245
246 var exitErr error
247
248 for k, v := range resultMap {
249 if v.err != nil {
250 if exitErr == nil {
251 exitErr = v.err
252 }
253
254 _, err := networkDumpHandle.WriteString(k + "\nno content\n")
255 if err != nil {
256 return networkDumpHandle.Name(), fmt.Errorf("error writing 'no content' to raw network file: %w", err)
257 }
258 } else {
259 _, err := networkDumpHandle.WriteString(k + "\n" + v.raw + "\n")
260 if err != nil {
261 return networkDumpHandle.Name(), fmt.Errorf("error writing raw network information: %w", err)
262 }
263 }
264 }
265
266 return networkDumpHandle.Name(), exitErr
267}
268
269func jsonNetworkInformationWriter(resultMap map[string]networkCollectionResult) (string, error) {
270 // nolint: gosec

Callers 1

Calls 4

WriteStringMethod · 0.80
ErrorfMethod · 0.80
CloseMethod · 0.65
NameMethod · 0.65

Tested by

no test coverage detected