Source File
option.go
Belonging Package
text/template
// Copyright 2015 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.// This file contains the code to handle template options.package templateimport// missingKeyAction defines how to respond to indexing a map with a key that is not present.type missingKeyAction intconst (mapInvalid missingKeyAction = iota // Return an invalid reflect.Value.mapZeroValue // Return the zero value for the map element.mapError // Error out)type option struct {missingKey missingKeyAction}// Option sets options for the template. Options are described by// strings, either a simple string or "key=value". There can be at// most one equals sign in an option string. If the option string// is unrecognized or otherwise invalid, Option panics.//// Known options://// missingkey: Control the behavior during execution if a map is// indexed with a key that is not present in the map.//// "missingkey=default" or "missingkey=invalid"// The default behavior: Do nothing and continue execution.// If printed, the result of the index operation is the string// "<no value>".// "missingkey=zero"// The operation returns the zero value for the map type's element.// "missingkey=error"// Execution stops immediately with an error.func ( *Template) ( ...string) *Template {.init()for , := range {.setOption()}return}func ( *Template) ( string) {if == "" {panic("empty option string")}// key=valueif , , := strings.Cut(, "="); {switch {case "missingkey":switch {case "invalid", "default":.option.missingKey = mapInvalidreturncase "zero":.option.missingKey = mapZeroValuereturncase "error":.option.missingKey = mapErrorreturn}}}panic("unrecognized option: " + )}
![]() |
The pages are generated with Golds v0.7.9-preview. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |