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 GinCore Middleware calls 3 called by 1

Entity Profile

Dependency Diagram

graph TD
  9b707d02_bf2d_b689_b041_4d275fda4cdd["CustomRecoveryWithWriter()"]
  b2655a63_5a3e_56ca_c0dd_550d7efec3e6["recovery.go"]
  9b707d02_bf2d_b689_b041_4d275fda4cdd -->|defined in| b2655a63_5a3e_56ca_c0dd_550d7efec3e6
  65fb708f_3900_4daf_c46d_f84f0cd169ac["RecoveryWithWriter()"]
  65fb708f_3900_4daf_c46d_f84f0cd169ac -->|calls| 9b707d02_bf2d_b689_b041_4d275fda4cdd
  a2e61019_cf3e_6a6e_97bf_9701f33cd17f["secureRequestDump()"]
  9b707d02_bf2d_b689_b041_4d275fda4cdd -->|calls| a2e61019_cf3e_6a6e_97bf_9701f33cd17f
  a5a2c11f_fbd3_a1f0_aeec_dccf9706ea5f["timeFormat()"]
  9b707d02_bf2d_b689_b041_4d275fda4cdd -->|calls| a5a2c11f_fbd3_a1f0_aeec_dccf9706ea5f
  d45c1ff3_74e9_75f8_35fd_779a5973b503["stack()"]
  9b707d02_bf2d_b689_b041_4d275fda4cdd -->|calls| d45c1ff3_74e9_75f8_35fd_779a5973b503
  style 9b707d02_bf2d_b689_b041_4d275fda4cdd 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

Defined In

Frequently Asked Questions

What does CustomRecoveryWithWriter() do?
CustomRecoveryWithWriter() is a function in the gin codebase, defined in recovery.go.
Where is CustomRecoveryWithWriter() defined?
CustomRecoveryWithWriter() is defined in recovery.go at line 53.
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