Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/knz/go-fmtfwd
Perfect forwarding for Go printf formatting strings
https://github.com/knz/go-fmtfwd
Last synced: 26 days ago
JSON representation
Perfect forwarding for Go printf formatting strings
- Host: GitHub
- URL: https://github.com/knz/go-fmtfwd
- Owner: knz
- License: mit
- Created: 2020-10-10T17:39:07.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2020-10-10T17:49:06.000Z (about 4 years ago)
- Last Synced: 2024-06-20T12:25:35.570Z (5 months ago)
- Language: Go
- Size: 2.93 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-fmtfwd
Perfect forwarding for Go printf formatting strings
This library facilitates the implementation of `fmt.Formatter` on
custom types, when there is a need to forward the call
to a default value.For example:
```go
func (t *T) Format(s fmt.State, verb rune) {
if s.Flag('#') {
fmt.Fprint(s, "hello")
} else {
_, fmtForward := fmtfwd.MakeFormat(s, verb)
fmt.Fprintf(s, fmtForward, "world")
}
}
```Alternatively, the combination `MakeFormat` + `fmt.Fprintf` call
can be combined as a single call `fmtfwd.ReproducePrintf(s, s, verb,
...)`.Package documentation here: https://pkg.go.dev/github.com/knz/go-fmtfwd