Skip to content

Commit 2acc0cb

Browse files
authored
Merge pull request #82 from MalteJ/patch-1
Adding example with HTTPS endpoint to README.md
2 parents adba7d1 + 585f90c commit 2acc0cb

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

README.md

+39
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,45 @@ can pass `nil`:
3030
c.Dcim.DcimDeviceTypesCreate(createRequest, nil)
3131
```
3232

33+
If you connect to netbox via HTTPS you have to create an HTTPS configured transport:
34+
```
35+
package main
36+
37+
import (
38+
"os"
39+
40+
httptransport "github.com/go-openapi/runtime/client"
41+
"github.com/netbox-community/go-netbox/netbox/client"
42+
"github.com/netbox-community/go-netbox/netbox/client/dcim"
43+
44+
log "github.com/sirupsen/logrus"
45+
)
46+
47+
func main() {
48+
token := os.Getenv("NETBOX_TOKEN")
49+
if token == "" {
50+
log.Fatalf("Please provide netbox API token via env var NETBOX_TOKEN")
51+
}
52+
53+
netboxHost := os.Getenv("NETBOX_HOST")
54+
if netboxHost == "" {
55+
log.Fatalf("Please provide netbox host via env var NETBOX_HOST")
56+
}
57+
58+
transport := httptransport.New(netboxHost, client.DefaultBasePath, []string{"https"})
59+
transport.DefaultAuthentication = httptransport.APIKeyAuth("Authorization", "header", "Token "+token)
60+
61+
c := client.New(transport, nil)
62+
63+
req := dcim.NewDcimSitesListParams()
64+
res, err := c.Dcim.DcimSitesList(req, nil)
65+
if err != nil {
66+
log.Fatalf("Cannot get sites list: %v", err)
67+
}
68+
log.Infof("res: %v", res)
69+
}
70+
```
71+
3372
Go Module support
3473
================
3574

0 commit comments

Comments
 (0)