Format implements the fmt.Formatter interface, used by fmt functions to generate output using custom format specifiers. This function creates the format specifiers '%n', '%x', '%e' to extract name, expiration date, and error string from an Info object.
(f fmt.State, c rune)
| 187 | // format specifiers '%n', '%x', '%e' to extract name, expiration date, and |
| 188 | // error string from an Info object. |
| 189 | func (i *certInfo) Format(f fmt.State, c rune) { |
| 190 | w, wok := f.Width() // width modifier. eg., %20n |
| 191 | p, pok := f.Precision() // precision modifier. eg., %.20n |
| 192 | |
| 193 | var str string |
| 194 | switch c { |
| 195 | case 'n': |
| 196 | str = i.commonName |
| 197 | |
| 198 | case 'x': |
| 199 | if i.expireDate.IsZero() { |
| 200 | break |
| 201 | } |
| 202 | str = i.expireDate.Format(time.RFC822) |
| 203 | |
| 204 | case 'e': |
| 205 | if i.err != nil { |
| 206 | str = i.err.Error() |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | if wok { |
| 211 | str = fmt.Sprintf("%-[2]*[1]s", str, w) |
| 212 | } |
| 213 | if pok && len(str) < p { |
| 214 | str = str[:p] |
| 215 | } |
| 216 | |
| 217 | x.Check2(f.Write([]byte(str))) |
| 218 | } |