-
Notifications
You must be signed in to change notification settings - Fork 2
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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( | ||
configuration.TestEnvironment, | ||
&configuration.Pkcs12{Content: certificate), Password: "p12 password"}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. didn't find the |
||
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()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need context argument for |
||
fmt.Println(response.Collect(ctx)) | ||
} | ||
``` | ||
|
||
## Unit tests | ||
|
There was a problem hiding this comment.
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