Per-project admin key auth, drop ProjectID; MIT license; go 1.21

This commit is contained in:
rudder
2026-08-12 17:37:46 +03:00
parent 718eb09a78
commit 58eb477763
5 changed files with 35 additions and 15 deletions
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2026 Rudder
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+12 -7
View File
@@ -1,8 +1,7 @@
# liveops-go-sdk
# rudder-go-sdk
Серверный Go SDK для LiveOps-платформы Rudder. Покрывает server-admin
поверхность `/game/v1` (auth по `X-API-Key`, ключ — `GAME_ADMIN_API_KEY`
на gateway).
поверхность `/game/v1` (auth по `X-API-Key`).
## Install
@@ -14,14 +13,20 @@ go env -w GOPRIVATE=hub.rudder.build/*
go get hub.rudder.build/rudder/rudder-go-sdk@latest
```
Требуется Go 1.25+. Токен не нужен — репозиторий публичный.
Требуется Go 1.21+. Токен не нужен — репозиторий публичный.
## Доступ
`APIKey` — это per-project Admin Key: поле «Admin Key» в настройках проекта
в дашборде (app.rudder.build → проект → Settings). Ключ сам определяет
проект, отдельный project ID не нужен. Храните его только на сервере —
никогда не вшивайте в игровые клиенты.
## Usage
```go
client, err := rudder.New(rudder.Config{
APIKey: os.Getenv("GAME_ADMIN_API_KEY"),
ProjectID: "your-project-id",
APIKey: os.Getenv("RUDDER_ADMIN_KEY"),
})
if err != nil {
// *rudder.APIError с кодом sdk/invalid-options
@@ -44,7 +49,7 @@ page, err := client.Ugc.List(ctx, rudder.ListUgcParameters{Status: "pending"})
var apiErr *rudder.APIError
if errors.As(err, &apiErr) {
apiErr.Status // HTTP status
apiErr.Code // машинный код, константы в models.ErrorCode*
apiErr.Code // машинный код из тела ошибки gateway
apiErr.RequestID // корреляция с логами gateway
}
```
-5
View File
@@ -9,7 +9,6 @@ const DefaultBaseURL = "https://api.rudder.build"
type Config struct {
APIKey string
ProjectID string
BaseURL string
Timeout time.Duration
HTTPClient *http.Client
@@ -27,9 +26,6 @@ func New(config Config) (*Client, error) {
if config.APIKey == "" {
return nil, &APIError{Code: ErrorCodeInvalidOptions, Message: "APIKey is required"}
}
if config.ProjectID == "" {
return nil, &APIError{Code: ErrorCodeInvalidOptions, Message: "ProjectID is required"}
}
if config.BaseURL == "" {
config.BaseURL = DefaultBaseURL
@@ -44,7 +40,6 @@ func New(config Config) (*Client, error) {
transport := &transport{
baseURL: config.BaseURL,
apiKey: config.APIKey,
projectID: config.ProjectID,
httpClient: config.HTTPClient,
}
+1 -1
View File
@@ -1,3 +1,3 @@
module hub.rudder.build/rudder/rudder-go-sdk
go 1.25.2
go 1.21
+1 -2
View File
@@ -14,12 +14,11 @@ import (
type transport struct {
baseURL string
apiKey string
projectID string
httpClient *http.Client
}
func (t *transport) do(ctx context.Context, method, path string, query url.Values, body any, out any) error {
endpoint := strings.TrimSuffix(t.baseURL, "/") + "/game/v1/projects/" + t.projectID + path
endpoint := strings.TrimSuffix(t.baseURL, "/") + "/game/v1" + path
if len(query) > 0 {
endpoint += "?" + query.Encode()
}