Skip to content

Commit 34d17e9

Browse files
authored
Merge pull request #1 from MurashovVen/feature/base-client
Add base client
2 parents a954b84 + 79ea096 commit 34d17e9

34 files changed

Lines changed: 4156 additions & 0 deletions

.github/CONTRIBUTING.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Contribution guide
2+
3+
## Basics
4+
5+
Prior to create a PR please create an issue that will describe a problem.
6+
7+
## Tests
8+
9+
Please implement tests for all methods that you're creating.
10+
You can use the fake Transport and Response from the `httptest`
11+
package.

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
For #[ISSUE_NUMBER]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Golangci-lint
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
8+
jobs:
9+
golangci-lint:
10+
runs-on: ubuntu-24.04
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-go@v5
14+
with:
15+
go-version: "1.23"
16+
- uses: golangci/golangci-lint-action@v7
17+
with:
18+
version: v2.1.6

.github/workflows/unit-tests.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Unit Tests
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
8+
jobs:
9+
unit-test:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
fail-fast: false
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v3
17+
18+
- name: Set up Go
19+
uses: actions/setup-go@v3
20+
with:
21+
go-version: '1.23'
22+
23+
- name: Run test
24+
run: make unittest

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea
2+
.DS_Store
3+
coverage.out

.golangci.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
version: "2"
2+
run:
3+
modules-download-mode: readonly
4+
linters:
5+
default: none
6+
enable:
7+
- asciicheck
8+
- bodyclose
9+
- copyloopvar
10+
- dogsled
11+
- errcheck
12+
- exhaustive
13+
- gocognit
14+
- goconst
15+
- gocritic
16+
- gocyclo
17+
- godot
18+
- godox
19+
- goheader
20+
- gomodguard
21+
- goprintffuncname
22+
- gosec
23+
- govet
24+
- ineffassign
25+
- misspell
26+
- nakedret
27+
- nlreturn
28+
- noctx
29+
- nolintlint
30+
- prealloc
31+
- revive
32+
- rowserrcheck
33+
- sqlclosecheck
34+
- staticcheck
35+
- unconvert
36+
- unused
37+
- whitespace
38+
settings:
39+
nlreturn:
40+
block-size: 3
41+
exclusions:
42+
generated: lax
43+
presets:
44+
- comments
45+
- common-false-positives
46+
- legacy
47+
- std-error-handling
48+
rules:
49+
- linters:
50+
- staticcheck
51+
text: 'SA1019:'
52+
- linters:
53+
- errcheck
54+
text: Error return value of `d.Set` is not checked
55+
- linters:
56+
- gosec
57+
text: 'G501:'
58+
- linters:
59+
- gosec
60+
text: 'G404:'
61+
paths:
62+
- third_party$
63+
- builtin$
64+
- examples$
65+
formatters:
66+
enable:
67+
- gci
68+
- gofmt
69+
- gofumpt
70+
- goimports
71+
exclusions:
72+
generated: lax
73+
paths:
74+
- third_party$
75+
- builtin$
76+
- examples$

GNUmakefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
default: tests
2+
3+
tests: golangci-lint test
4+
5+
test:
6+
go test ./...
7+
8+
golangci-lint:
9+
docker run --rm -v $(PWD):/app:ro -w /app golangci/golangci-lint:v2.1.6 golangci-lint run
10+
11+
.PHONY: tests unittest golangci-lint

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,61 @@
11
# dedicated-go
22
Go SDK for Selectel Dedicated Servers
3+
4+
## Getting started
5+
6+
### Installation
7+
8+
You can install needed `dedicated-go` packages via `go get` command:
9+
10+
```bash
11+
go get github.com/selectel/dedicated-go
12+
```
13+
14+
### Authentication
15+
16+
To work with the Selectel Dedicated Servers API you first need to:
17+
18+
* Create a Selectel account: [registration page](https://my.selectel.ru/registration).
19+
* Create a project in Selectel Cloud Platform [projects](https://my.selectel.ru/vpc/projects).
20+
* Retrieve a token for your project via API or [go-selvpcclient](https://github.com/selectel/go-selvpcclient).
21+
22+
### Endpoints
23+
24+
You can find available endpoints [here](https://docs.selectel.ru/en/api/urls/).
25+
26+
### Usage example
27+
28+
```go
29+
package main
30+
31+
import (
32+
"context"
33+
"fmt"
34+
"log"
35+
36+
dedicated "github.com/selectel/dedicated-go/pkg/v2"
37+
)
38+
39+
func main() {
40+
// Auth token.
41+
token := "gAAAAABeVNzu-..."
42+
43+
// Dedicated servers endpoint to work with.
44+
endpoint := "https://api.selectel.ru/servers/v2"
45+
46+
// Create the client.
47+
client := dedicated.NewClientV2(token, endpoint)
48+
49+
// Get the os for location.
50+
q := &dedicated.OperatingSystemsQuery{LocationID: "some-location-uuid"}
51+
operatingSystems, _, err := client.OperatingSystems(context.Background(), q)
52+
if err != nil {
53+
log.Fatal(err)
54+
}
55+
56+
// Print the os.
57+
for idx, os := range operatingSystems {
58+
fmt.Printf("OS %d: %+v", idx, os)
59+
}
60+
}
61+
```

go.mod

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module github.com/selectel/dedicated-go
2+
3+
go 1.23
4+
5+
require github.com/stretchr/testify v1.11.1
6+
7+
require (
8+
github.com/davecgh/go-spew v1.1.1 // indirect
9+
github.com/pmezard/go-difflib v1.0.0 // indirect
10+
gopkg.in/yaml.v3 v3.0.1 // indirect
11+
)

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5+
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
6+
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
7+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
8+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
9+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
10+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)