Home / File/ hooks.go — fiber Source File

hooks.go — fiber Source File

Architecture documentation for hooks.go, a go file in the fiber codebase. 1 imports, 0 dependents.

File go FiberClient Hooks 1 imports 8 functions 3 classes

Entity Profile

Dependency Diagram

graph LR
  14cfc1be_1c8f_085d_1a4e_f0de9527aaba["hooks.go"]
  86295193_b3d6_5771_ebab_205c899f2f71["rand"]
  14cfc1be_1c8f_085d_1a4e_f0de9527aaba --> 86295193_b3d6_5771_ebab_205c899f2f71
  style 14cfc1be_1c8f_085d_1a4e_f0de9527aaba fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

package client

import (
	"crypto/rand"
	"fmt"
	"io"
	"mime/multipart"
	"os"
	"path/filepath"
	"regexp"
	"strconv"
	"strings"
	"sync"

	"github.com/gofiber/utils/v2"
	"github.com/valyala/fasthttp"
)

var protocolCheck = regexp.MustCompile(`^https?://.*$`)

var fileBufPool = sync.Pool{
	New: func() any {
		b := make([]byte, 1<<20) // 1MB buffer
		return &b
	},
}

const (
	headerAccept      = "Accept"
	applicationJSON   = "application/json"
	applicationCBOR   = "application/cbor"
	applicationXML    = "application/xml"
	applicationForm   = "application/x-www-form-urlencoded"
	multipartFormData = "multipart/form-data"

	letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
)

// unsafeRandString returns a random string of length n.
// An error is returned if the random source fails.
func unsafeRandString(n int) (string, error) {
	inputLength := byte(len(letterBytes))

	// Compute the largest multiple of inputLength ≤ 256 to avoid modulo bias.
	// Any byte ≥ max will be rejected and re‑read.
	maxLength := byte(256 - (256 % int(inputLength)))

	out := make([]byte, n)
	buf := make([]byte, n)

	// Read n raw bytes in one shot
	if _, err := rand.Read(buf); err != nil {
		return "", fmt.Errorf("rand.Read failed: %w", err)
	}

	for i, b := range buf {
		// Reject values ≥ maxLength
		for b >= maxLength {
			if _, err := rand.Read(buf[i : i+1]); err != nil {
				return "", fmt.Errorf("rand.Read failed: %w", err)
// ... (295 more lines)

Domain

Subdomains

Dependencies

  • rand

Frequently Asked Questions

What does hooks.go do?
hooks.go is a source file in the fiber codebase, written in go. It belongs to the FiberClient domain, Hooks subdomain.
What functions are defined in hooks.go?
hooks.go defines 8 function(s): addFormFile, logger, parserRequestBody, parserRequestBodyFile, parserRequestHeader, parserRequestURL, parserResponseCookie, unsafeRandString.
What does hooks.go depend on?
hooks.go imports 1 module(s): rand.
Where is hooks.go in the architecture?
hooks.go is located at client/hooks.go (domain: FiberClient, subdomain: Hooks, directory: client).

Analyze Your Own Codebase

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

Try Supermodel Free