Home / Function/ buildLogFuncChain() — fiber Function Reference

buildLogFuncChain() — fiber Function Reference

Architecture documentation for the buildLogFuncChain() function in template_chain.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  2fbc139e_824d_570d_9ba5_53cfa8655e91["buildLogFuncChain()"]
  4db9061f_6bf2_d2fa_c165_0c988219853c["template_chain.go"]
  2fbc139e_824d_570d_9ba5_53cfa8655e91 -->|defined in| 4db9061f_6bf2_d2fa_c165_0c988219853c
  style 2fbc139e_824d_570d_9ba5_53cfa8655e91 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

middleware/logger/template_chain.go lines 17–71

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

Frequently Asked Questions

What does buildLogFuncChain() do?
buildLogFuncChain() is a function in the fiber codebase, defined in middleware/logger/template_chain.go.
Where is buildLogFuncChain() defined?
buildLogFuncChain() is defined in middleware/logger/template_chain.go at line 17.

Analyze Your Own Codebase

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

Try Supermodel Free