github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/msgfmt/formatter_invalid.go (about)

     1  package msgfmt
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  )
     7  
     8  type invalidFormatter string
     9  
    10  func (formatter invalidFormatter) Format(space []byte, kv []interface{}) []byte {
    11  	output, err := json.Marshal(kv)
    12  	if err != nil {
    13  		space = append(space, "%! (INVALID FORMAT) "...)
    14  		space = append(space, formatter...)
    15  		space = append(space, "%! (FORMAT ARGS) "...)
    16  		space = append(space, output...)
    17  	} else {
    18  		space = append(space, "%! (INVALID FORMAT) "...)
    19  		space = append(space, formatter...)
    20  		space = append(space, "%! (FORMAT ARGS) "...)
    21  		space = append(space, fmt.Sprintf("%v", kv)...)
    22  	}
    23  	return space
    24  }