Skip to content

Commit

Permalink
Improved example
Browse files Browse the repository at this point in the history
- Improved formatting and commenting
- Add code to logout of session at the end

Signed-off-by: Chris Arceneaux <[email protected]>
  • Loading branch information
carceneaux committed Apr 17, 2021
1 parent 783e984 commit 94dd686
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The SDK includes a `vendor` folder containing the runtime dependencies of the SD

### Example

This example shows a complete working Go file which will list the names of all Backup Jobs and demonstrate how to configure the timeout logic that will cancel the request if it takes too long. This example highlights how to login to a VBR server with trusted or self-signed certs, make a request, handle the error, and process the response.
This example shows a complete working Go file which will list the names of all Backup Jobs and demonstrate how to configure the timeout logic that will cancel the request if it takes too long. This example highlights how to login to a VBR server with trusted or self-signed certs, make a request, handle the error, process the response, and then logout.

```go
package main
Expand All @@ -51,9 +51,9 @@ import (
func main() {
// Setting variables
host := "vbr.contoso.local:9419" // default API port 9419
u := "contoso\\jsmith" // VBR username
u := "contoso\\jsmith" // VBR username
p := strfmt.Password("password") // VBR password
timeout := 15 * time.Second // 15 seconds
timeout := 15 * time.Second // 15 seconds

// Using untrusted (self-signed) certificates
skipTlsClient := &http.Client{
Expand All @@ -80,18 +80,18 @@ func main() {
params.Password = &p

// Authenticating to VBR API
login, err := veeam.Login.CreateToken(params)
l, err := veeam.Login.CreateToken(params)
if err != nil {
panic(err)
}
token := *login.Payload.AccessToken
token := *l.Payload.AccessToken

// Setting authorization
// From this point, all calls will require the 'auth' variable
auth := httptransport.BearerToken(token)

// Retrieving all backup jobs
jobs, err := veeam.Jobs.GetAllJobs(
allJobs, err := veeam.Jobs.GetAllJobs(
jobs.NewGetAllJobsParams().WithDefaults(),
auth)
if err != nil {
Expand All @@ -101,9 +101,14 @@ func main() {
// Printing out job names
// Working with the response payload
fmt.Printf("Job Names:\n\n")
for _, job := range jobs.Payload.Data {
for _, job := range allJobs.Payload.Data {
fmt.Println(*job.Name)
}

// Logging out session
veeam.Login.Logout(
login.NewLogoutParams().WithDefaults(),
auth)
}
```

Expand Down

0 comments on commit 94dd686

Please sign in to comment.