diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8528e1d --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md index 00b75d7..97d3fde 100644 --- a/README.md +++ b/README.md @@ -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 } ``` diff --git a/client.go b/client.go index 0cbc080..513928b 100644 --- a/client.go +++ b/client.go @@ -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, } diff --git a/go.mod b/go.mod index 332891e..f988277 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module hub.rudder.build/rudder/rudder-go-sdk -go 1.25.2 +go 1.21 diff --git a/transport.go b/transport.go index 944d3d8..d1358d0 100644 --- a/transport.go +++ b/transport.go @@ -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() }