How to convert bool to string in Go: converting boolean value to string
Hello everyone! I just started learning Go and encountered a simple but very annoying problem. I need to output a boolean value to a log or form a string with the result of a condition check. For example, I'm writing a simple form validator and want to return the string "true" or "false" in a JSON response or just for debugging.
In other languages like Python or JavaScript, this is done easily: str(True) or String(true) in Java. But in Go I can't find a direct way. I tried a simple type conversion:
```go
package main
import "fmt"
func main() {
b := true
s := string(b) // Error!
fmt.Println(s)
}
```
But the compiler gives an error: "cannot convert b (variable of type bool) to type string". I understand that Go has strong typing, but how do I correctly convert it?