[go-nuts] How to use errors.As with sentinel errors?

2021-08-02 Thread cpu...@gmail.com
Consider this example: https://play.golang.org/p/16cU0kc8Lku, basically

var Err = errors.New("sentinel")
err := errors.New("foo")
if errors.As(err, &Err) {
  fmt.Println("why?")
}

I'm wondering why this matches the sentinel error, or rather how to 
properly use sentinel errors. errors.As says "An error matches target if 
the error's concrete value is assignable to the value pointed to by 
target". This seems to be the case here (both are of type error).

However, if thats the case, how should I construct a sentinel error that 
would be usable with errors.As? I don't want to rely on errors.Is as errors 
could be wrapped. So to "break" the assignability- would that mean that I'd 
need to define sentinel errors as e.g. struct types?

Seem's I'm still lacking the level of understanding for go errors that I'd 
aspire to :/

Cheers,
Andi

-- 
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/4d8969b4-dd5a-4834-893b-3e01174570bfn%40googlegroups.com.


[go-nuts] Re: How to use errors.As with sentinel errors?

2021-08-02 Thread cpu...@gmail.com
Ah, think I found it: https://blog.golang.org/go1.13-errors says:

In the simplest case, the errors.Is function behaves like a comparison to a 
sentinel error, and the errors.Asfunction behaves like a type assertion. 
When operating on wrapped errors, however, these functions consider all the 
errors in a chain. 

So I should just use errors.Is here... Sorry for the confusion!
On Monday, August 2, 2021 at 10:02:11 AM UTC+2 cpu...@gmail.com wrote:

> Consider this example: https://play.golang.org/p/16cU0kc8Lku, basically
>
> var Err = errors.New("sentinel")
> err := errors.New("foo")
> if errors.As(err, &Err) {
>   fmt.Println("why?")
> }
>
> I'm wondering why this matches the sentinel error, or rather how to 
> properly use sentinel errors. errors.As says "An error matches target if 
> the error's concrete value is assignable to the value pointed to by 
> target". This seems to be the case here (both are of type error).
>
> However, if thats the case, how should I construct a sentinel error that 
> would be usable with errors.As? I don't want to rely on errors.Is as errors 
> could be wrapped. So to "break" the assignability- would that mean that I'd 
> need to define sentinel errors as e.g. struct types?
>
> Seem's I'm still lacking the level of understanding for go errors that I'd 
> aspire to :/
>
> Cheers,
> Andi
>

-- 
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/7a495842-a022-4c41-92aa-39e8dff00f97n%40googlegroups.com.


Re: [go-nuts] How to use errors.As with sentinel errors?

2021-08-02 Thread 'Axel Wagner' via golang-nuts
On Mon, Aug 2, 2021 at 10:02 AM cpu...@gmail.com  wrote:

> Consider this example: https://play.golang.org/p/16cU0kc8Lku, basically
>
> var Err = errors.New("sentinel")
> err := errors.New("foo")
> if errors.As(err, &Err) {
>   fmt.Println("why?")
> }
>
> I'm wondering why this matches the sentinel error
>

Because both are of type `*errors.errorString`, so the types match and it
copies over the value.
Arguably, `errors.errorString` should implement `As()` and return `false`,
unless the pointers match. I suggest filing an issue.


> or rather how to properly use sentinel errors.
>

Use `errors.Is`, instead of `errors.As`.


> However, if thats the case, how should I construct a sentinel error that
> would be usable with errors.As? I don't want to rely on errors.Is as errors
> could be wrapped.
>

And? They can be wrapped for `As` as well. `errors.As` is only useful if
you want to get additional information out of the error (e.g. it's useful
for use with `os.PathError`). By definition, it's pointless to use it with
a sentinel error.


> So to "break" the assignability- would that mean that I'd need to define
> sentinel errors as e.g. struct types?
>
> Seem's I'm still lacking the level of understanding for go errors that I'd
> aspire to :/
>
> Cheers,
> Andi
>
> --
> 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/4d8969b4-dd5a-4834-893b-3e01174570bfn%40googlegroups.com
> 
> .
>

-- 
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/CAEkBMfGyjtNg-vGCvS95Pt0_iy_-yVWhr8TcKixhyvvMVkf_0g%40mail.gmail.com.


[go-nuts] Retrieving Pageview data using SearchConsole API

2021-08-02 Thread Cedric Franz
Hi,

I am trying to retrieve the number of page clicks recorded in GA per page 
on out site for a date range using the searchconsole/v1 library.  I have 
created an API key for out project and it has not API restricts set yet.

I have the following questions:
1) is this the best API to use to retrieve this data
2) Why is the authentication failing?
ctx := context.Background()
searchService, err := searchconsole.NewService(ctx, 
option.WithAPIKey("AIza."))
if err != nil {
  log.Panic().Err(err).Send()
}
req := &searchconsole.SearchAnalyticsQueryRequest{
  StartDate: startdate,
  EndDate: enddate,
  Dimensions: []string{"PAGE"},
}
query := pcd.searchService.Searchanalytics.Query("http://www.example.com";, 
req)

// send the query to the API, get a big fat gaData back.
res, err := query.Do()

I would really welcome any help or a working example of how to do this.

Thanks

-- 
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/f58d54e9-58b2-4863-bf2c-2a154ed0924an%40googlegroups.com.


Re: [go-nuts] How to use errors.As with sentinel errors?

2021-08-02 Thread Andreas Götz
> Because both are of type `*errors.errorString`, so the types match and it 
copies over the value.
Arguably, `errors.errorString` should implement `As()` and return `false`, 
unless the pointers match. I suggest filing an issue.

Will do. It could also be a vet check to highlight errors.As used on 
sentinel errors which is most likely wrong as I demonstrated.

On Monday, August 2, 2021 at 10:09:48 AM UTC+2 axel.wa...@googlemail.com 
wrote:

> On Mon, Aug 2, 2021 at 10:02 AM cpu...@gmail.com  wrote:
>
>> Consider this example: https://play.golang.org/p/16cU0kc8Lku, basically
>>
>> var Err = errors.New("sentinel")
>> err := errors.New("foo")
>> if errors.As(err, &Err) {
>>   fmt.Println("why?")
>> }
>>
>> I'm wondering why this matches the sentinel error
>>
>
> Because both are of type `*errors.errorString`, so the types match and it 
> copies over the value.
> Arguably, `errors.errorString` should implement `As()` and return `false`, 
> unless the pointers match. I suggest filing an issue.
>  
>
>> or rather how to properly use sentinel errors.
>>
>
> Use `errors.Is`, instead of `errors.As`.
>  
>
>> However, if thats the case, how should I construct a sentinel error that 
>> would be usable with errors.As? I don't want to rely on errors.Is as errors 
>> could be wrapped.
>>
>
> And? They can be wrapped for `As` as well. `errors.As` is only useful if 
> you want to get additional information out of the error (e.g. it's useful 
> for use with `os.PathError`). By definition, it's pointless to use it with 
> a sentinel error.
>  
>
>> So to "break" the assignability- would that mean that I'd need to define 
>> sentinel errors as e.g. struct types?
>>
>> Seem's I'm still lacking the level of understanding for go errors that 
>> I'd aspire to :/
>>
>> Cheers,
>> Andi
>>
>> -- 
>> 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...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/4d8969b4-dd5a-4834-893b-3e01174570bfn%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
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/730c78dd-cd24-4377-b154-c1e238a2c929n%40googlegroups.com.


[go-nuts] icmpengine - a small golang ping library

2021-08-02 Thread dave seddon
G'day,

I hope this is an appropriate place to post about a new little library.

Recently I was looking for a basic ping library but didn't have much luck, 
so I hope the community will find this helpful:

https://github.com/EdgeCast/icmpengine

Feedback welcome.

Kind regards,
Dave Seddon

-- 
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/33536eb5-00ec-4fb6-ac0e-9817254df5b0n%40googlegroups.com.


[go-nuts] Go 1.17 Release Candidate 2 is released

2021-08-02 Thread Alex Rakoczy
Hello gophers,

We have just released go1.17rc2, a release candidate version of Go 1.17.
It is cut from release-branch.go1.17 at the revision tagged go1.17rc2.

Please try your production load tests and unit tests with the new version.
Your help testing these pre-release versions is invaluable.

Report any problems using the issue tracker:
https://golang.org/issue/new

If you have Go installed already, the easiest way to try go1.17rc2
is by using the go command:
$ go get golang.org/dl/go1.17rc2
$ go1.17rc2 download

You can download binary and source distributions from the usual place:
https://golang.org/dl/#go1.17rc2

To find out what has changed in Go 1.17, read the draft release notes:
https://tip.golang.org/doc/go1.17

Cheers,
The Go Team

-- 
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/CA%2BxaJdSSkE8M76dFO%2BLMWJbS1-UpdNaSCB70F_4DuRBkwANKXA%40mail.gmail.com.