This question already has an answer here:
- Convert a byte to a string in Go 4 answers
In the following method, I attempted to redefine the string method on the IPAddr type by appending bytes to an array of string
type IPAddr [4]byte
func (ip IPAddr) String() string {
var s []string
for _, i := range ip {
s = append(s, i)
}
return fmt.Sprintf(strings.Join(s, "."))
}
cannot use i (type byte) as type string in append
</div>