lorenzodonini / ocpp-go

Open Charge Point Protocol implementation in Go
MIT License
277 stars 126 forks source link

Implement Error on base receiver #295

Closed andig closed 2 months ago

andig commented 2 months ago

Proposed changes

Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue.

Types of changes

What types of changes does your code introduce? Put an x in the boxes that apply

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

Further comments

This allows writing code like

        var oe ocpp.Error
        if errors.As(err, &oe) && oe.Code == ocppj.GenericError {
            ...
        }

which would otherwise need be written using pointer to pointer as in

        oe := new(ocpp.Error)
        if errors.As(err, &oe) && oe.Code == ocppj.GenericError {
            ...
        }