github.com/lingyao2333/mo-zero@v1.4.1/core/logx/color.go (about) 1 package logx 2 3 import ( 4 "sync/atomic" 5 6 "github.com/lingyao2333/mo-zero/core/color" 7 ) 8 9 // WithColor is a helper function to add color to a string, only in plain encoding. 10 func WithColor(text string, colour color.Color) string { 11 if atomic.LoadUint32(&encoding) == plainEncodingType { 12 return color.WithColor(text, colour) 13 } 14 15 return text 16 } 17 18 // WithColorPadding is a helper function to add color to a string with leading and trailing spaces, 19 // only in plain encoding. 20 func WithColorPadding(text string, colour color.Color) string { 21 if atomic.LoadUint32(&encoding) == plainEncodingType { 22 return color.WithColorPadding(text, colour) 23 } 24 25 return text 26 }