After checking with gometalinter this part of code:
//ListenerButton is hanging listeners for contact button
func ListenerButton(number int, button *ui.Button, conn net.Conn) string {
button.OnClicked(func(*ui.Button) {
sliceMembers := []string{login, button.Text()}
groupName = login + button.Text()
_, err := conn.Write([]byte(JSONencode(login, "", "",
0, groupName, 1,
login, sliceMembers, " ", " ", "",
" ", " ", " ", true, " ", "CreateGroup")))
if err != nil {
log.Println(err)
}
fmt.Println(login, groupName, number, "graphic 131")
})
return groupName
}
I've got this warning:
warning: conn can be io.Writer (interfacer)
What does it mean and how i have to resolve it?
CODE EXAMPLE An io.Writer is an entity to which you can write a stream of bytes. The standard library contains many Writers, and Writers are accepted as input by many utilities. About Home Algorithms Go How to use the io.Writer interface yourbasic.org/golang Basics How to use a built-in writer (3 examples) Optimize string writes Basics
CODE EXAMPLE An io.Reader is an entity from which you can read a stream of bytes. The standard library has many Reader implementations, including in-memory byte buffers, files and network connections. Readers are accepted as input by many utilities such as HTTP clients and server implementations.
CODE EXAMPLE An io.Writer is an entity to which you can write a stream of bytes. The standard library contains many Writers, and Writers are accepted as input by many utilities. About Home Algorithms Go How to use the io.Writer interface
That means that the ListenerButton
function is only only using the Write
method of conn
. By changing the type from net.Conn
to io.Writer
, that allows your function to use a much larger number of io.Writer
implementations. Having as small of interfaces as possible should be a goal when implementing your API.
With that change, for example, you could use an io.MultiWriter
to write debug information to stderr, as well as the network connection:
func ListenerButton(number int, button *ui.Button, conn io.Writer) string {
// ...
}
ListenerButton(number, button, io.MultiWriter(os.Stderr, networkConn))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With