Home / Function/ CustomRecoveryWithWriter() — gin Function Reference

CustomRecoveryWithWriter() — gin Function Reference

Architecture documentation for the CustomRecoveryWithWriter() function in recovery.go from the gin codebase.

Function go CoreEngine Routing calls 3 called by 1

Entity Profile

Dependency Diagram

graph TD
  a42c9a57_9a95_764b_260b_2ead107d7770["CustomRecoveryWithWriter()"]
  ca35304d_3bf7_f736_de12_3d746c2bf220["RecoveryWithWriter()"]
  ca35304d_3bf7_f736_de12_3d746c2bf220 -->|calls| a42c9a57_9a95_764b_260b_2ead107d7770
  09ec5a23_fd25_47c3_2acf_ade5bc0dbbb2["secureRequestDump()"]
  a42c9a57_9a95_764b_260b_2ead107d7770 -->|calls| 09ec5a23_fd25_47c3_2acf_ade5bc0dbbb2
  88984237_d31a_eab5_ea06_2517e3bfdae5["timeFormat()"]
  a42c9a57_9a95_764b_260b_2ead107d7770 -->|calls| 88984237_d31a_eab5_ea06_2517e3bfdae5
  fafa3f3c_1482_f023_f289_21663c39573c["stack()"]
  a42c9a57_9a95_764b_260b_2ead107d7770 -->|calls| fafa3f3c_1482_f023_f289_21663c39573c
  style a42c9a57_9a95_764b_260b_2ead107d7770 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

recovery.go lines 53–92

func CustomRecoveryWithWriter(out io.Writer, handle RecoveryFunc) HandlerFunc {
	var logger *log.Logger
	if out != nil {
		logger = log.New(out, "\n\n\x1b[31m", log.LstdFlags)
	}
	return func(c *Context) {
		defer func() {
			if rec := recover(); rec != nil {
				// Check for a broken connection, as it is not really a
				// condition that warrants a panic stack trace.
				var isBrokenPipe bool
				err, ok := rec.(error)
				if ok {
					isBrokenPipe = errors.Is(err, syscall.EPIPE) ||
						errors.Is(err, syscall.ECONNRESET) ||
						errors.Is(err, http.ErrAbortHandler)
				}
				if logger != nil {
					if isBrokenPipe {
						logger.Printf("%s\n%s%s", rec, secureRequestDump(c.Request), reset)
					} else if IsDebugging() {
						logger.Printf("[Recovery] %s panic recovered:\n%s\n%s\n%s%s",
							timeFormat(time.Now()), secureRequestDump(c.Request), rec, stack(stackSkip), reset)
					} else {
						logger.Printf("[Recovery] %s panic recovered:\n%s\n%s%s",
							timeFormat(time.Now()), rec, stack(stackSkip), reset)
					}
				}
				if isBrokenPipe {
					// If the connection is dead, we can't write a status to it.
					c.Error(err) //nolint: errcheck
					c.Abort()
				} else {
					handle(c, rec)
				}
			}
		}()
		c.Next()
	}
}

Domain

Subdomains

Frequently Asked Questions

What does CustomRecoveryWithWriter() do?
CustomRecoveryWithWriter() is a function in the gin codebase.
What does CustomRecoveryWithWriter() call?
CustomRecoveryWithWriter() calls 3 function(s): secureRequestDump, stack, timeFormat.
What calls CustomRecoveryWithWriter()?
CustomRecoveryWithWriter() is called by 1 function(s): RecoveryWithWriter.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free