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 Серверный Go SDK для LiveOps-платформы Rudder. Покрывает server-admin
поверхность `/game/v1` (auth по `X-API-Key`, ключ — `GAME_ADMIN_API_KEY` поверхность `/game/v1` (auth по `X-API-Key`).
на gateway).
## Install ## Install
@@ -14,14 +13,20 @@ go env -w GOPRIVATE=hub.rudder.build/*
go get hub.rudder.build/rudder/rudder-go-sdk@latest 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 ## Usage
```go ```go
client, err := rudder.New(rudder.Config{ client, err := rudder.New(rudder.Config{
APIKey: os.Getenv("GAME_ADMIN_API_KEY"), APIKey: os.Getenv("RUDDER_ADMIN_KEY"),
ProjectID: "your-project-id",
}) })
if err != nil { if err != nil {
// *rudder.APIError с кодом sdk/invalid-options // *rudder.APIError с кодом sdk/invalid-options
@@ -44,7 +49,7 @@ page, err := client.Ugc.List(ctx, rudder.ListUgcParameters{Status: "pending"})
var apiErr *rudder.APIError var apiErr *rudder.APIError
if errors.As(err, &apiErr) { if errors.As(err, &apiErr) {
apiErr.Status // HTTP status apiErr.Status // HTTP status
apiErr.Code // машинный код, константы в models.ErrorCode* apiErr.Code // машинный код из тела ошибки gateway
apiErr.RequestID // корреляция с логами gateway apiErr.RequestID // корреляция с логами gateway
} }
``` ```
-5
View File
@@ -9,7 +9,6 @@ const DefaultBaseURL = "https://api.rudder.build"
type Config struct { type Config struct {
APIKey string APIKey string
ProjectID string
BaseURL string BaseURL string
Timeout time.Duration Timeout time.Duration
HTTPClient *http.Client HTTPClient *http.Client
@@ -27,9 +26,6 @@ func New(config Config) (*Client, error) {
if config.APIKey == "" { if config.APIKey == "" {
return nil, &APIError{Code: ErrorCodeInvalidOptions, Message: "APIKey is required"} return nil, &APIError{Code: ErrorCodeInvalidOptions, Message: "APIKey is required"}
} }
if config.ProjectID == "" {
return nil, &APIError{Code: ErrorCodeInvalidOptions, Message: "ProjectID is required"}
}
if config.BaseURL == "" { if config.BaseURL == "" {
config.BaseURL = DefaultBaseURL config.BaseURL = DefaultBaseURL
@@ -44,7 +40,6 @@ func New(config Config) (*Client, error) {
transport := &transport{ transport := &transport{
baseURL: config.BaseURL, baseURL: config.BaseURL,
apiKey: config.APIKey, apiKey: config.APIKey,
projectID: config.ProjectID,
httpClient: config.HTTPClient, httpClient: config.HTTPClient,
} }
+1 -1
View File
@@ -1,3 +1,3 @@
module hub.rudder.build/rudder/rudder-go-sdk 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 { type transport struct {
baseURL string baseURL string
apiKey string apiKey string
projectID string
httpClient *http.Client httpClient *http.Client
} }
func (t *transport) do(ctx context.Context, method, path string, query url.Values, body any, out any) error { 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 { if len(query) > 0 {
endpoint += "?" + query.Encode() endpoint += "?" + query.Encode()
} }