From 3e61c5014184ecfc8e4ff15ce4c0b1ffe100cf81 Mon Sep 17 00:00:00 2001 From: pavel <36902936+pavel-github@users.noreply.github.com> Date: Sun, 11 Aug 2024 13:45:52 +0200 Subject: [PATCH] docs: update readme with examples --- .github/CONTRIBUTING.md | 24 ++++++++++++++++ README.md | 64 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 .github/CONTRIBUTING.md diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..6e2b91d --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,24 @@ +# Contributing + +We love contributions! You are welcome to open a pull request, but it's a good idea to +open an issue and discuss your idea with us first. + +Once you are ready to open a PR, please keep the following guidelines in mind: + +1. Code should be `go fmt` compliant. +2. Types, structs and funcs should be documented. +3. Tests and linters pass. + +## Getting set up + +`xelon-sdk-go` uses go modules. Just fork this repo, clone your fork and off you go! +Run `make help` to see all available make commands. + + +## Running tests and lint + +When working on code in this repository, tests and linters can be run via: + +```shell +make lint test +``` diff --git a/README.md b/README.md index 75a39c8..1231491 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,67 @@ [![GoDoc](https://img.shields.io/badge/pkg.go.dev-doc-blue)](http://pkg.go.dev/github.com/Xelon-AG/xelon-sdk-go) xelon-sdk-go is the official Xelon SDK for the Go programming language. + +## Installation + +```sh +# X.Y.Z is the version you need +go get github.com/Xelon-AG/xelon-sdk-go@vX.Y.Z + + +# for non Go modules usage or latest version +go get github.com/Xelon-AG/xelon-sdk-go +``` + +## Usage + +```go +import "github.com/Xelon-AG/xelon-sdk-go" +``` + +Create a new Xelon client, then use the exposed services to access +different parts of the Xelon API. + +### Authentication + +Currently, Bearer token is the only method of authenticating with the API. +You can learn how to obtain it [here](https://www.xelon.ch/docs/xelon-api-101#authorize-youself). +Then use your token to create a new client: + +```go +client := client := xelon.NewClient("my-secret-token") +``` + +If you want to specify more parameters by client initialization, use +`With...` methods and pass via option pattern: + +```go +var opts []xelon.ClientOption +opts = append(opts, xelon.WithBaseURL(baseURL)) +opts = append(opts, xelon.WithClientID(clientID)) +opts = append(opts, xelon.WithUserAgent(userAgent)) + +client := client := xelon.NewClient("my-secret-token", opts...) +``` + +### Examples + +List all ssh keys for the user. + +```go +func main() { + client := xelon.NewClient("my-secret-token") + + // list all ssh keys for the authenticated user + ctx := context.Background() + sshKeys, _, err := client.SSHKeys.List(ctx) +} +``` + +## Contributing + +We love pull requests! Please see the [contribution guidelines](.github/CONTRIBUTING.md). + +## License + +This SDK is distributed under the Apache-2.0 license, see [LICENSE](LICENSE) for more information.