template_chain.go — fiber Source File
Architecture documentation for template_chain.go, a go file in the fiber codebase. 1 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 4db9061f_6bf2_d2fa_c165_0c988219853c["template_chain.go"] c0b86961_3ef1_0168_52fc_98627566ed27["bytes"] 4db9061f_6bf2_d2fa_c165_0c988219853c --> c0b86961_3ef1_0168_52fc_98627566ed27 style 4db9061f_6bf2_d2fa_c165_0c988219853c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
package logger
import (
"bytes"
"fmt"
"github.com/gofiber/utils/v2"
)
// buildLogFuncChain analyzes the template and creates slices with the functions for execution and
// slices with the fixed parts of the template and the parameters
//
// fixParts contains the fixed parts of the template or parameters if a function is stored in the funcChain at this position
// funcChain contains for the parts which exist the functions for the dynamic parts
// funcChain and fixParts always have the same length and contain nil for the parts where no data is required in the chain,
// if a function exists for the part, a parameter for it can also exist in the fixParts slice
func buildLogFuncChain(cfg *Config, tagFunctions map[string]LogFunc) ([][]byte, []LogFunc, error) {
// process flow is copied from the fasttemplate flow https://github.com/valyala/fasttemplate/blob/2a2d1afadadf9715bfa19683cdaeac8347e5d9f9/template.go#L23-L62
templateB := utils.UnsafeBytes(cfg.Format)
startTagB := utils.UnsafeBytes(startTag)
endTagB := utils.UnsafeBytes(endTag)
paramSeparatorB := utils.UnsafeBytes(paramSeparator)
var fixParts [][]byte
var funcChain []LogFunc
for {
before, after, found := bytes.Cut(templateB, startTagB)
if !found {
// no starting tag found in the existing template part
break
}
// add fixed part
funcChain = append(funcChain, nil)
fixParts = append(fixParts, before)
templateB = after
before, after, found = bytes.Cut(templateB, endTagB)
if !found {
// cannot find end tag - just write it to the output.
funcChain = append(funcChain, nil)
fixParts = append(fixParts, startTagB)
break
}
// ## function block ##
// first check for tags with parameters
tag, param, foundParam := bytes.Cut(before, paramSeparatorB)
if foundParam {
logFunc, ok := tagFunctions[utils.UnsafeString(tag)+paramSeparator]
if !ok {
return nil, nil, fmt.Errorf("%w: %q", ErrTemplateParameterMissing, utils.UnsafeString(before))
}
funcChain = append(funcChain, logFunc)
// add param to the fixParts
fixParts = append(fixParts, param)
} else if logFunc, ok := tagFunctions[utils.UnsafeString(before)]; ok {
// add functions without parameter
funcChain = append(funcChain, logFunc)
fixParts = append(fixParts, nil)
}
// ## function block end ##
// reduce the template string
templateB = after
}
// set the rest
funcChain = append(funcChain, nil)
fixParts = append(fixParts, templateB)
return fixParts, funcChain, nil
}
Domain
Subdomains
Functions
Dependencies
- bytes
Source
Frequently Asked Questions
What does template_chain.go do?
template_chain.go is a source file in the fiber codebase, written in go. It belongs to the FiberCore domain, Adapters subdomain.
What functions are defined in template_chain.go?
template_chain.go defines 1 function(s): buildLogFuncChain.
What does template_chain.go depend on?
template_chain.go imports 1 module(s): bytes.
Where is template_chain.go in the architecture?
template_chain.go is located at middleware/logger/template_chain.go (domain: FiberCore, subdomain: Adapters, directory: middleware/logger).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free