Skip to content

Commit 3e5b2d5

Browse files
committed
Update project documentation.
1 parent b34d5dc commit 3e5b2d5

File tree

3 files changed

+25
-59
lines changed

3 files changed

+25
-59
lines changed
File renamed without changes.

LICENSE.md renamed to license.md

File renamed without changes.

README.md renamed to readme.md

Lines changed: 25 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ This project follows [Semantic Versioning](https://semver.org). The version of t
88

99
## Installation
1010

11-
Use `go get` to add the library as a project's dependency. Do not forget to run `go mod init` first if necessary.
11+
Use `go get` to add the library as a dependency to your project. Do not forget to run `go mod init` first if necessary.
1212

1313
```shell
1414
go get github.com/netbox-community/go-netbox/v3
1515

1616
# Or install a specific version
17-
go get github.com/netbox-community/go-netbox/v3@v3.4.5-1
17+
go get github.com/netbox-community/go-netbox/v3@v3.7.1-0
1818
```
1919

2020
**Note:** dependencies should be managed with [Go modules](https://go.dev/doc/modules/managing-dependencies).
@@ -23,102 +23,68 @@ go get github.com/netbox-community/go-netbox/v3@v3.4.5-1
2323

2424
### Instantiate the client
2525

26-
The package has some convenience functions for creating clients with the most common configurations.
26+
The package has a constructor for creating a client providing a URL and an authentication token.
2727

2828
```golang
2929
package main
3030

3131
import (
32+
"context"
3233
"log"
3334

34-
"github.com/netbox-community/go-netbox/v3/netbox"
35+
"github.com/netbox-community/go-netbox/v3"
3536
)
3637

3738
func main() {
38-
c := netbox.NewNetboxAt("netbox.example.org:8000")
39-
40-
// or:
41-
// c := netbox.NewNetboxWithAPIKey("netbox.example.org:8000", "<api-token>")
39+
ctx := context.Background()
4240

43-
log.Printf("%+v", c)
44-
}
45-
```
46-
47-
In order to consume the Netbox API with HTTP over TLS, a transport must be created.
48-
49-
```golang
50-
package main
51-
52-
import (
53-
"fmt"
54-
"log"
55-
56-
transport "github.com/go-openapi/runtime/client"
57-
"github.com/netbox-community/go-netbox/v3/netbox/client"
58-
)
59-
60-
func main() {
61-
t := transport.New("netbox.example.org", client.DefaultBasePath, []string{"https"})
62-
63-
t.DefaultAuthentication = transport.APIKeyAuth(
64-
"Authorization",
65-
"header",
66-
fmt.Sprintf("Token %v", "<api-token>"),
67-
)
68-
69-
c := client.New(t, nil)
41+
c := netbox.NewAPIClientFor("https://demo.netbox.dev", "v3ry$3cr3t")
7042

7143
log.Printf("%+v", c)
7244
}
73-
```
74-
75-
For more complex client configurations, see the documentation of _[github.com/go-openapi/runtime/client](https://pkg.go.dev/github.com/go-openapi/runtime/client)_, the library which in turn is used by the client.
7645

77-
**Note:** setting the `DEBUG` environment variable will dump all requests to standard error output.
46+
```
7847

7948
### Use the client
8049

8150
With the client already instantiated, it is possible to consume any API feature.
8251

83-
For example, to list the first 100 active virtual machines:
52+
For example, to list the first 10 active virtual machines:
8453

8554
```golang
8655
package main
8756

8857
import (
58+
"context"
8959
"log"
9060

91-
"github.com/netbox-community/go-netbox/v3/netbox"
92-
"github.com/netbox-community/go-netbox/v3/netbox/client/virtualization"
61+
"github.com/netbox-community/go-netbox/v3"
9362
)
9463

95-
var status = "active"
96-
var pageLimit = int64(100)
97-
9864
func main() {
99-
c := netbox.NewNetboxWithAPIKey("netbox.example.org", "<api-token>")
65+
ctx := context.Background()
10066

101-
req := virtualization.
102-
NewVirtualizationVirtualMachinesListParams().
103-
WithStatus(&status).
104-
WithLimit(&pageLimit)
67+
c := netbox.NewAPIClientFor("https://demo.netbox.dev", "v3ry$3cr3t")
10568

106-
// additional `authInfo` is `nil` because the API token has already been specified in the client
107-
res, err := w.netbox.Virtualization.VirtualizationVirtualMachinesList(req, nil)
69+
res, _, err := c.VirtualizationAPI.
70+
VirtualizationVirtualMachinesList(ctx).
71+
Status([]string{"active"}).
72+
Limit(10).
73+
Execute()
10874

10975
if err != nil {
11076
log.Fatal(err)
11177
}
11278

113-
log.Printf("%+v", res.Payload.Results)
79+
log.Printf("%v", res.Results)
11480
}
11581
```
11682

117-
See [reference](https://pkg.go.dev/github.com/netbox-community/go-netbox) for more information on all possible usages.
83+
See [docs](docs) or [reference](https://pkg.go.dev/github.com/netbox-community/go-netbox) for more information on all possible usages.
11884

11985
## Development
12086

121-
The project comes with a containerized development environment that can be used from any platform. It is only required to have [Git](https://git-scm.com) and [Docker Desktop](https://www.docker.com/products/docker-desktop/) (or, separately, [Docker](https://docs.docker.com/engine/install) and [Docker Compose](https://docs.docker.com/compose/install/)) installed on the machine.
87+
The project comes with a containerized development environment that may be used from any platform. It is only required to have [Git](https://git-scm.com) and [Docker Desktop](https://www.docker.com/products/docker-desktop/) (or, separately, [Docker](https://docs.docker.com/engine/install) and [Docker Compose](https://docs.docker.com/compose/install/)) installed on the machine.
12288

12389
To start the development environment, run the following command.
12490

@@ -140,12 +106,12 @@ make down
140106

141107
### Considerations
142108

143-
The library is almost entirely generated from the Netbox [OpenAPI](https://www.openapis.org/) specification using _[go-swagger](https://github.com/go-swagger/go-swagger)_. Therefore, files under directories `netbox/client` and `netbox/models` should not be directly modified, as they will be overwritten in the next regeneration (see next section).
109+
The library is entirely generated from the Netbox [OpenAPI](https://www.openapis.org/) specification using _[openapi-generator](https://github.com/OpenAPITools/openapi-generator)_. Therefore, files listed [here](.openapi-generator/files) should not be directly modified, as they will be overwritten in the next regeneration (see next section).
144110

145-
To fix issues in generated code, there are two options:
111+
In order to fix a bug in the generated code, the corresponding error in the OpenAPI spec must be fixed. To do so, the following steps may be followed:
146112

147-
- Change the OpenAPI spec with pre-generation hooks (see [`scripts/pre-generation`](scripts/pre-generation)).
148-
- If the above is not possible, change the generated code with post-generation hooks (see [`scripts/post-generation`](scripts/post-generation)).
113+
1. Optional. Patch the OpenAPI spec in this repo by editing [this script](scripts/fix-spec.py), so that a corrected version can be published as soon as possible.
114+
2. Fix the OpenAPI spec in the [Netbox repository](https://github.com/netbox-community/netbox), either by reporting an issue or by creating a pull request.
149115

150116
### Regenerate the library
151117

0 commit comments

Comments
 (0)