Add gRPC server implementation and database integration for marketplace and products

This commit is contained in:
2025-05-27 03:41:52 +03:00
parent 008f3df42d
commit b083cccc09
44 changed files with 2182 additions and 1201 deletions

35
internal/ozon/common.go Normal file
View File

@@ -0,0 +1,35 @@
package ozon
import (
"errors"
"git.denco.store/fakz9/ozon-api-client/ozon"
"github.com/tidwall/gjson"
"net/http"
"sipro-mps/internal/marketplace"
)
func GetClientFromMarketplace(mp *marketplace.Marketplace) (*ozon.Client, error) {
authDataParsed := gjson.Parse(mp.AuthData)
clientIdResult := authDataParsed.Get("clientId")
apiKeyResult := authDataParsed.Get("clientToken")
if !clientIdResult.Exists() || !apiKeyResult.Exists() {
return nil, errors.New("auth data is not valid")
}
apiKey := apiKeyResult.String()
clientId := clientIdResult.String()
httpClient := &http.Client{
Transport: NewRateLimitTransport(),
}
opts := []ozon.ClientOption{
ozon.WithAPIKey(apiKey),
ozon.WithClientId(clientId),
ozon.WithHttpClient(httpClient),
}
client := ozon.NewClient(opts...)
if client == nil {
return nil, errors.New("failed to create ozon client")
}
return client, nil
}