Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage example in README.md #6

Merged
merged 1 commit into from
Nov 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 31 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,48 @@ We support the two major Go versions, which are 1.14 and 1.15 at the moment.
# Examples

## Initiate sign request

```go
package main

import (
"context"
"fmt"
"io/ioutil"
"github.com/NicklasWallgren/bankid"
"github.com/NicklasWallgren/bankid/configuration"
"context"
"fmt"
"io/ioutil"

"github.com/NicklasWallgren/bankid"
"github.com/NicklasWallgren/bankid/configuration"
)

certificate, err := ioutil.ReadFile("path/to/environment.p12")
if err != nil {
panic(err)
}
func main() {
certificate, err := ioutil.ReadFile("path/to/environment.p12")
if err != nil {
panic(err)
}

configuration := configuration.New(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed the var so that it doesn't shadow the package

configuration.TestEnvironment,
&configuration.Pkcs12{Content: certificate), Password: "p12 password"},
Copy link
Contributor Author

@yaronius yaronius Nov 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we had an extra bracket, removed it

)
config := configuration.New(
configuration.TestEnvironment,
&configuration.Pkcs12{Content: certificate, Password: "p12 password"},
)

bankId := bankid.New(configuration)
bankId := bankid.New(config)

payload := bankid.SignPayload{PersonalNumber: "<INSERT PERSONAL NUMBER>", EndUserIp: "192.168.1.1", UserVisibleData: "Test"}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed the wrong case for payload property

payload := bankid.SignPayload{PersonalNumber: "<INSERT PERSONAL NUMBER>", EndUserIP: "192.168.1.1", UserVisibleData: "Test"}

response, err := bankId.Sign(&payload)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need context argument for this method

ctx := context.Background()
response, err := bankId.Sign(ctx, &payload)

if err != nil {
if response := bankid.UnwrapErrorResponse(err); response != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't find the UnwrapErrorResponse() function, but it works fine if try to cast it (tested)

fmt.Printf("%s - %s \n", response.Details, response.ErrorCode)
}
if err != nil {
if response, ok := err.(*bankid.ErrorResponse); ok {
fmt.Printf("ErrResponse: %s - %s \n", response.Details, response.ErrorCode)
}

fmt.Printf("%#v", err)
return
}
fmt.Printf("%#v", err)
return
}

fmt.Println(response.Collect())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need context argument for Collect() method too

fmt.Println(response.Collect(ctx))
}
```

## Unit tests
Expand Down