People tend to use strings far too much.

Does tlsCert in this code really need to be a string?

Probably not. 
But it it does really need to be a string, then converting to a sting as 
you have done is
quite straight forward. And explicit is better than implicit.
The beauty of Go is its simplicity. Go doesn't do magic.


On Friday, 11 September 2020 17:45:52 UTC+1, Kevin Chadwick wrote:
>
> I apologise if this has already been discussed. Google didn't turn up 
> anything 
> directly related. 
>
> If you read a file using the following that returns a byte slice. 
>
> tlsCertb, err := ioutil.ReadFile("/etc/ssl/mycert") 
> if err != nil { 
>    log.Fatal(err) 
> } 
> tlsCert = string(tlsCertb) 
>
> Is there a way to get a string without the cast. 
>
> Otherwise couldn't the language automatically return a string rather than 
> a byte 
> slice in these cases if the receiving var is already a string? 
>
> e.g. 
>
> var string tlsCert 
> tlsCert, err = ioutil.ReadFile("/etc/ssl/mycert") 
> if err != nil { 
>    log.Fatal(err) 
> } 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/103608b3-9254-476f-b83d-b8f40651a422o%40googlegroups.com.

Reply via email to