https://pkg.go.dev/fmt#State

https://pkg.go.dev/fmt#Formatter

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Format formats the frame according to the fmt.Formatter interface.
//
// %s source file
// %d source line
// %n function name
// %v equivalent to %s:%d
//
// Format accepts flags that alter the printing of some verbs, as follows:
//
// %+s function name and path of source file relative to the compile time
// GOPATH separated by \n\t (<funcname>\n\t<path>)
// %+v equivalent to %+s:%d
func (f Frame) Format(state fmt.State, verb rune) {
switch verb {
case 's':
switch {
case state.Flag('+'): // Flag reports whether the flag is present
io.WriteString(state, f.name()) // state has the Write function -> Writer interface
io.WriteString(state, "\n\t")
io.WriteString(state, f.file())
default:
io.WriteString(state, path.Base(f.file()))
}
case 'd':
io.WriteString(state, strconv.Itoa(f.line()))
case 'n':
io.WriteString(state, funcname(f.name()))
case 'v':
f.Format(state, 's')
io.WriteString(s, ":")
f.Format(state, 'd')
}
}