fmt.go 447 B

12345678910111213141516171819202122
  1. package ioutils
  2. import (
  3. "fmt"
  4. "io"
  5. )
  6. // FprintfIfNotEmpty prints the string value if it's not empty
  7. func FprintfIfNotEmpty(w io.Writer, format, value string) (int, error) {
  8. if value != "" {
  9. return fmt.Fprintf(w, format, value)
  10. }
  11. return 0, nil
  12. }
  13. // FprintfIfTrue prints the boolean value if it's true
  14. func FprintfIfTrue(w io.Writer, format string, ok bool) (int, error) {
  15. if ok {
  16. return fmt.Fprintf(w, format, ok)
  17. }
  18. return 0, nil
  19. }