[go-nuts] Re: Proposal: auto return String instead of []byte if requested

2020-09-12 Thread Amnon
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.


[go-nuts] Re: Proposal: auto return String instead of []byte if requested

2020-09-11 Thread Volker Dobler
Please no. This is just begging for problems.
A simple type conversion is 1 (one!) line and pretty clear.
Once you open this can of worms someone would like
to  have a []rune and then automatic conversions from
int32 to int and 6 month later you have a JavaScript
like nonsense language just because you saved one
trivial line of code.

V

On Friday, 11 September 2020 at 18:45:52 UTC+2 m8il...@gmail.com 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/493ceb14-e34d-4c39-8d03-1c0c2c0358can%40googlegroups.com.