### Perform YOP Go SDK GET Request Source: https://github.com/yop-platform/yop-go-sdk/blob/main/README.md This Go example demonstrates how to make a GET request using the YOP Go SDK. It initializes a `YopRequest` with the HTTP method, API path, AppId, private key, and adds a parameter before sending the request. ```Go var priKey = request.IsvPriKey{Value: "isvPriKey", CertType: request.RSA2048} var yopRequest = request.NewYopRequest(constants.GET_HTTP_METHOD, "/rest/v1.0/test/product-query/query-for-doc") yopRequest.AppId = "appId" yopRequest.IsvPriKey = priKey yopRequest.AddParam("paramName", "paramValue") yopResp, err := client.DefaultClient.Request(yopRequest) if nil != err{ // request failed } //yopResp.Result is the request result ``` -------------------------------- ### Configure YOP Go SDK Credentials Source: https://github.com/yop-platform/yop-go-sdk/blob/main/examples/README.md Demonstrates how to set up your App ID and Private Key for the YOP Go SDK within your Go application. ```Go appId := "your-actual-app-id" privateKey := "your-actual-private-key" ``` -------------------------------- ### Verify Go SDK Setup with Tests Source: https://github.com/yop-platform/yop-go-sdk/blob/main/CONTRIBUTING.md Command to run all tests in the YOP Go SDK to ensure the development environment is correctly set up and functional. ```bash go test ./... ``` -------------------------------- ### Configure YOP Go SDK Server Root for Different Environments Source: https://github.com/yop-platform/yop-go-sdk/blob/main/examples/README.md Provides examples of setting the ServerRoot for production, test, and YOS file service environments in the YOP Go SDK. ```Go // Production (default) yopRequest.ServerRoot = "https://openapi.yeepay.com/yop-center" // Test environment yopRequest.ServerRoot = "https://ycetest.yeepay.com:30228/yop-center" // YOS file service yopRequest.ServerRoot = "https://yos.yeepay.com/yop-center" ``` -------------------------------- ### Install Go Development Tools Source: https://github.com/yop-platform/yop-go-sdk/blob/main/CONTRIBUTING.md Commands to install `golangci-lint` for code linting and `goimports` for organizing Go imports, essential for maintaining code quality. ```bash curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.2 go install golang.org/x/tools/cmd/goimports@latest ``` -------------------------------- ### Install YOP Go SDK Source: https://github.com/yop-platform/yop-go-sdk/blob/main/README.md This snippet shows how to install the YOP Go SDK using Go modules. Run this command in your terminal to add the SDK to your project. ```Bash go get github.com/yop-platform/yop-go-sdk ``` -------------------------------- ### Set Up YOP Go SDK Development Environment Source: https://github.com/yop-platform/yop-go-sdk/blob/main/README.md Provides step-by-step instructions for setting up the development environment for the YOP Go SDK, including cloning the repository, installing dependencies, running tests, and formatting code. ```bash git clone https://github.com/yop-platform/yop-go-sdk.git cd yop-go-sdk go mod download go test ./... go fmt ./... goimports -w . ``` -------------------------------- ### Install Go Module Dependencies Source: https://github.com/yop-platform/yop-go-sdk/blob/main/CONTRIBUTING.md Command to download and install all necessary Go module dependencies for the project. ```bash go mod download ``` -------------------------------- ### Configure YOP Go SDK Test Environment Server Root Source: https://github.com/yop-platform/yop-go-sdk/blob/main/examples/README.md Shows how to set the ServerRoot for the YOP Go SDK to point to a specific test environment URL. ```Go yopRequest.ServerRoot = "https://ycetest.yeepay.com:30228/yop-center" ``` -------------------------------- ### Mock YOP Go SDK Client for Testing Source: https://github.com/yop-platform/yop-go-sdk/blob/main/examples/README.md Illustrates how to create a mock client for the YOP Go SDK to facilitate testing without making actual API calls. ```Go // Create a mock client for testing mockClient := &MockYopClient{} yopResp, err := mockClient.Request(yopRequest) ``` -------------------------------- ### Making GET Request with YOP SDK Go Source: https://github.com/yop-platform/yop-go-sdk/blob/main/llms.txt This snippet demonstrates how to construct and execute a GET request using the YOP Go SDK. It involves creating a new YopRequest with the GET method and API path, setting the application ID and ISV private key, adding request parameters, and calling the DefaultClient.Request method. ```Go var priKey = &request.IsvPriKey{Value: "isvPriKey", CertType: request.RSA2048} var yopRequest = request.NewYopRequest(constants.GET_HTTP_METHOD,"/rest/v1.0/test-wdc/product-query/query-for-doc") yopRequest.AppId = "appId" yopRequest.IsvPriKey = priKey yopRequest.AddParam("paramName", "paramValue") yopResp, err := client.DefaultClient.Request(yopRequest) if nil != err{ // request failed } //yopResp.Result为请求结果 ``` -------------------------------- ### Example Go Unit Test Structure Source: https://github.com/yop-platform/yop-go-sdk/blob/main/CONTRIBUTING.md A template for writing Go unit tests, demonstrating a table-driven test approach with multiple test cases, input/output validation, and error handling. ```go func TestFunctionName(t *testing.T) { tests := []struct { name string input InputType expected ExpectedType wantErr bool }{ { name: "valid input", input: validInput, expected: expectedOutput, wantErr: false, }, // Add more test cases... } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { result, err := FunctionName(tt.input) if (err != nil) != tt.wantErr { t.Errorf("FunctionName() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(result, tt.expected) { t.Errorf("FunctionName() = %v, want %v", result, tt.expected) } }) } } ``` -------------------------------- ### Conventional Commit Message Examples Source: https://github.com/yop-platform/yop-go-sdk/blob/main/CONTRIBUTING.md Provides examples of well-formatted commit messages for different types of changes, such as new features, bug fixes, documentation updates, and tests. ```APIDOC feat: add support for file upload with progress tracking fix: resolve race condition in request signing docs: update README with advanced configuration examples test: add unit tests for callback decryption ``` -------------------------------- ### Validate YOP Go SDK Request Construction and Signing Source: https://github.com/yop-platform/yop-go-sdk/blob/main/examples/README.md Shows how to build and validate a YOP Go SDK request, including signing, without sending it to the API, useful for testing request integrity. ```Go // Just build and validate the request err := auth.RsaSigner{}.SignRequest(*yopRequest) if err != nil { log.Printf("Request signing failed: %v", err) } ``` -------------------------------- ### Set Custom Timeout for YOP Go SDK Request Source: https://github.com/yop-platform/yop-go-sdk/blob/main/examples/README.md Demonstrates how to configure a custom timeout duration for a YOP Go SDK request using the Timeout property. ```Go yopRequest := request.NewYopRequest(constants.GET_HTTP_METHOD, "/api/path") yopRequest.Timeout = 30 * time.Second // Custom timeout ``` -------------------------------- ### Perform File Download Request in Go Source: https://github.com/yop-platform/yop-go-sdk/blob/main/README.md Illustrates how to download a file using the YOP Go SDK. It sets up a YopRequest for a GET method, includes application details and parameters. The downloaded file content is accessible via `yopResp.Content`. ```go var priKey = request.IsvPriKey{Value: "isvPriKey", CertType: request.RSA2048} var yopRequest = request.NewYopRequest(constants.GET_HTTP_METHOD, "/rest/v1.0/test/product-query/query-for-doc") yopRequest.AppId = "appId" yopRequest.IsvPriKey = priKey yopRequest.AddParam("paramName", "paramValue") yopResp, err := client.DefaultClient.Request(yopRequest) if nil != err{ // request failed } // yopResp.Content is the file content ``` -------------------------------- ### Perform YOP Go SDK POST Form Request Source: https://github.com/yop-platform/yop-go-sdk/blob/main/README.md This Go example illustrates how to send a POST request with form parameters using the YOP Go SDK. It configures the `YopRequest` with the POST method, API path, AppId, private key, and adds a form parameter. ```Go var priKey = request.IsvPriKey{Value: "isvPriKey", CertType: request.RSA2048} var yopRequest = request.NewYopRequest(constants.POST_HTTP_METHOD, "/rest/v1.0/test/product-query/query-for-doc") yopRequest.AppId = "appId" yopRequest.IsvPriKey = priKey yopRequest.AddParam("paramName", "paramValue") yopResp, err := client.DefaultClient.Request(yopRequest) if nil != err{ // request failed } //yopResp.Result is the request result ``` -------------------------------- ### Handle YOP Go SDK Request and Business Errors Source: https://github.com/yop-platform/yop-go-sdk/blob/main/examples/README.md Illustrates a robust error handling pattern for YOP Go SDK requests, covering both network/request building errors and business-level errors returned in the API response. ```Go yopResp, err := client.DefaultClient.Request(yopRequest) if err != nil { // Handle network or request building errors log.Printf("Request failed: %v", err) return } // Check business errors if yopResp.Result != nil { result := yopResp.Result.(map[string]interface{}) if status, ok := result["status"]; ok && status != "SUCCESS" { log.Printf("Business error: %v", result["errorMsg"]) return } } ``` -------------------------------- ### Configure YOP Go SDK Request Source: https://github.com/yop-platform/yop-go-sdk/blob/main/README.md This example demonstrates how to configure a YOP request in Go. It sets the application's private key, AppId, and an optional request timeout. The `YopRequest` object is central to all API interactions. ```Go var priKey = request.IsvPriKey{Value: "Your private key content", CertType: request.RSA2048} var yopRequest = request.NewYopRequest(constants.POST_HTTP_METHOD, "/rest/v1.0/api/path") yopRequest.AppId = "Your AppId" yopRequest.IsvPriKey = priKey yopRequest.Timeout = 15 * time.Second // Set timeout to 15 seconds (optional) ``` -------------------------------- ### Add Custom Headers to YOP Go SDK Request Source: https://github.com/yop-platform/yop-go-sdk/blob/main/examples/README.md Shows how to include custom HTTP headers in a YOP Go SDK request by modifying the Headers map. ```Go yopRequest.Headers["Custom-Header"] = "custom-value" ``` -------------------------------- ### Perform YOP Go SDK POST JSON Request Source: https://github.com/yop-platform/yop-go-sdk/blob/main/README.md This Go example demonstrates how to send a POST request with a JSON payload using the YOP Go SDK. It sets up the `YopRequest` and assigns a JSON string generated from a map to the `Content` field. ```Go var priKey = request.IsvPriKey{Value: "isvPriKey", CertType: request.RSA2048} var yopRequest = request.NewYopRequest(constants.POST_HTTP_METHOD, "/rest/v1.0/test/product-query/query-for-doc") yopRequest.AppId = "appId" yopRequest.IsvPriKey = priKey // Set JSON request payload var params = map[string]any{} params["merchantId"] = "1595815987915711" params["requestId"] = "requestId" yopRequest.Content = utils.ParseToJsonStr(params) yopResp, err := client.DefaultClient.Request(yopRequest) if nil != err{ // request failed } //yopResp.Result is the request result ``` -------------------------------- ### Handle Common Error Types in YOP SDK Requests Source: https://github.com/yop-platform/yop-go-sdk/blob/main/README.md Provides an example of how to handle errors returned from YOP SDK requests, distinguishing between network/request building errors and business-level errors indicated by the response status. ```go yopResp, err := client.DefaultClient.Request(yopRequest) if err != nil { // Network error or request building error log.Printf("Request failed: %v", err) return } // Check business errors if yopResp.Result != nil { result := yopResp.Result.(map[string]interface{}) if status, ok := result["status"]; ok && status != "SUCCESS" { log.Printf("Business error: %v", result["errorMsg"]) return } } ``` -------------------------------- ### Generate RSA Signature in Go Source: https://github.com/yop-platform/yop-go-sdk/blob/main/README.md Provides an example of generating an RSA signature using `utils.RsaSignBase64`. It takes the content to be signed, the private key, and the hashing algorithm (SHA256) as input. The function returns the base64 encoded signature. ```go //utils.RsaSignBase64 // This is test data, please use the real private key for production var priKey = "" var content = "a=123!@#¥%……Chinese" signature, error := utils.RsaSignBase64(content, priKey, crypto.SHA256) if nil != error { //sign error } ``` -------------------------------- ### Verify YOP Platform Signature in Go Source: https://github.com/yop-platform/yop-go-sdk/blob/main/llms.txt This Go code snippet demonstrates how to verify a digital signature using the `utils.VerifySign` function. It takes the original data, the signature string, the public key, and the hashing algorithm (SHA256) as inputs to check the integrity and authenticity of the data. The example includes sample public key, signature, and data. ```Go var pubKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwRwXR20F7D0/hKQISwPZNkOTvBiwgFBS1mAee1IXOGTWtmFIY60xbxWTBULjI2lYHZhRk76nxmFEAUZXRxYX/ZLl3+Sz2/ptASf0eQFgsk3F+wx6LqBjgzH8ZAma4piC8GFw5MIWEx6+YRFefJxkULRziFQeWuIv8uGdb719TCIwPvDid86WsVypI/uOjrX5o5aFDxhUs8/q6q0UbTKmHjy5FmdCfgpiFzNSsJf5IGFKv2BkmMvUOb06IzfVgSs5O3rjqAnLFrUawUMrHcjN8gz144Z18extJ4dO4UlIfqzA2e2bLdJVUKJf+5D18zcIenlJkRmPZX67iDEuZINcnQIDAQAB" var signature = "glTZg6lLl6oV4Ho15fAUegcVILlTwYJkbZO_Iz8AYUKTZ_1JP4AqAqSdm3GqjaukoNrDkxPGv2WW8plxYxtzsXjkzWiCMth5aShHgA7a9SXW0jfo365KPyVj0zFO2QIV9odHEnY1apwcAxvr54j4d5SHoC3vKUczZ20txTsNjcG9ifi1AoJhblILxKL2NO0tdIzTMQCRaBdOXUOdnL7RgP1qPew5yJT4e1QdtTjkirCKJurm4SumOA3Uroz-G-9MUZgiTkU4RXrEvu-rJPlqfJPsITYoWLsuPy1Gfne_5j-IgChXpoHacI0s-NlzKmyjsFt3-5aUYDd0cFw58ErUXw" var data = "{\"result\":{\"requestId\":\"requestId\",\"errorMsg\":\"exception.record.not.found.transferDomesticOrder|merchantId:[null],requestId:[requestId]\",\"status\":\"FAILED\"}}" if !utils.VerifySign(data, signature, pubKey, crypto.SHA256) { //verify failed } ``` -------------------------------- ### Run Benchmarks for YOP Go SDK Source: https://github.com/yop-platform/yop-go-sdk/blob/main/README.md Outlines commands to run performance benchmarks for the YOP Go SDK, including an option to display memory allocation statistics during benchmarking. ```bash # Run benchmarks go test -bench=. ./... # Run benchmarks with memory allocation stats go test -bench=. -benchmem ./... ``` -------------------------------- ### Clone YOP Go SDK Repository Source: https://github.com/yop-platform/yop-go-sdk/blob/main/CONTRIBUTING.md Instructions to clone the YOP Go SDK repository from GitHub using `git clone` and navigate into the directory. ```bash git clone https://github.com/your-username/yop-go-sdk.git cd yop-go-sdk ``` -------------------------------- ### Run Unit Tests for YOP Go SDK Source: https://github.com/yop-platform/yop-go-sdk/blob/main/README.md Provides commands to execute unit tests for the YOP Go SDK, including options to run all tests, generate coverage reports, and view coverage in HTML format. ```bash # Run all tests go test ./... # Run tests with coverage go test -cover ./... # Generate coverage report go test -coverprofile=coverage.out ./... go tool cover -html=coverage.out -o coverage.html ``` -------------------------------- ### Configure YOP SDK Server Environment Source: https://github.com/yop-platform/yop-go-sdk/blob/main/README.md Demonstrates how to configure the YOP Go SDK to connect to different environments, including production, test, and YOS file services, by setting the `ServerRoot` property. ```go // Production environment (default) yopRequest.ServerRoot = "https://openapi.yeepay.com/yop-center" // Test environment yopRequest.ServerRoot = "https://ycetest.yeepay.com:30228/yop-center" // YOS file service yopRequest.ServerRoot = "https://yos.yeepay.com/yop-center" ``` -------------------------------- ### Run Go Project Tests Source: https://github.com/yop-platform/yop-go-sdk/blob/main/CONTRIBUTING.md Various commands to execute tests in a Go project, including running all tests, tests with coverage, tests with race detection, and benchmarks. ```bash go test ./... go test -cover ./... go test -race ./... go test -bench=. ./... ``` -------------------------------- ### Import YOP Go SDK Packages Source: https://github.com/yop-platform/yop-go-sdk/blob/main/README.md This snippet shows the necessary Go packages to import when using the YOP Go SDK. These imports provide access to client, constants, request, and utility functions. ```Go import ( "github.com/yop-platform/yop-go-sdk/yop/client" "github.com/yop-platform/yop-go-sdk/yop/constants" "github.com/yop-platform/yop-go-sdk/yop/request" "github.com/yop-platform/yop-go-sdk/yop/utils" ) ``` -------------------------------- ### Perform File Upload Request in Go Source: https://github.com/yop-platform/yop-go-sdk/blob/main/README.md Demonstrates how to upload a file using the YOP Go SDK. It initializes a YopRequest with application details and adds a file for upload. The request is then sent via the default client, with the result available in `yopResp.Result`. ```go var priKey = request.IsvPriKey{Value: "isvPriKey", CertType: request.RSA2048} var yopRequest = request.NewYopRequest(constants.POST_HTTP_METHOD, "/rest/v1.0/test/product-query/query-for-doc") yopRequest.AppId = "appId" yopRequest.IsvPriKey = priKey yopRequest.AddFile("file", f) yopResp, err := client.DefaultClient.Request(yopRequest) if nil != err{ // request failed } // yopResp.Result is the upload request result ``` -------------------------------- ### Format Go Code Source: https://github.com/yop-platform/yop-go-sdk/blob/main/CONTRIBUTING.md Commands to automatically format Go source code using `go fmt` and organize imports with `goimports`, ensuring adherence to standard Go style guidelines. ```bash go fmt ./... goimports -w . ``` -------------------------------- ### Configure Custom HTTP Client for YOP SDK Source: https://github.com/yop-platform/yop-go-sdk/blob/main/README.md Illustrates how to create and integrate a custom `http.Client` with the YOP Go SDK, allowing for fine-grained control over HTTP request parameters like timeouts and transport settings. ```go import ( "net/http" "time" ) // Create custom HTTP client customClient := &http.Client{ Timeout: 30 * time.Second, Transport: &http.Transport{ MaxIdleConns: 100, MaxIdleConnsPerHost: 10, IdleConnTimeout: 90 * time.Second, }, } // Use custom client yopClient := client.YopClient{Client: customClient} yopResp, err := yopClient.Request(yopRequest) ``` -------------------------------- ### YopRequest API Reference Source: https://github.com/yop-platform/yop-go-sdk/blob/main/README.md `YopRequest` is the main object for initiating YOP API requests. ```APIDOC YopRequest: Main Properties: - AppId: Application identifier - IsvPriKey: Application private key - Timeout: Request timeout (seconds) - Content: Request content (for JSON requests) Main Methods: - NewYopRequest(httpMethod, apiUri string): Create a new request object - AddParam(paramName, paramValue string): Add request parameter - AddFile(paramName string, file *os.File): Add upload file ``` -------------------------------- ### Run Go Code Linting Source: https://github.com/yop-platform/yop-go-sdk/blob/main/CONTRIBUTING.md Command to execute `golangci-lint` to check Go code for style violations and potential errors before committing changes. ```bash golangci-lint run ``` -------------------------------- ### Signing Data with YOP SDK Go Source: https://github.com/yop-platform/yop-go-sdk/blob/main/llms.txt This snippet demonstrates how to sign arbitrary data using the ISV's private key and the RSA SHA256 algorithm with Base64 encoding, utilizing the utils.RsaSignBase64 function provided by the SDK. ```Go //utils.RsaSignBase64 // 此处为测试数据,正式使用是请使用真实的私钥 var priKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDBHBdHbQXsPT+EpAhLA9k2Q5O8GLCAUFLWYB57Uhc4ZNa2YUhjrTFvFZMFQuMjaVgdmFGTvqfGYUQBRldHFhf9kuXf5LPb+m0BJ/R5AWCyTcX7DHouoGODMfxkCZrimILwYWDkwhYTHr5hEV58nGRQtHOIVB5a4i/y4Z1vvX1MIjA+8OJ3zpaxXKkj+46OtfmjloUPGFSzz+rqq0UbTKmHjy5FmdCfgpiFzNSsJf5IGFKv2BkmMvUOb06IzfVgSs5O3rjqAnLFrUawUMrHcjN8gz144Z18extJ4dO4UlIfqzA2e2bLdJVUKJf+5D18zcIenlJkRmPZX67iDEuZINcnQIDAQABECgoAD4yQf0rTCEOiQq7mkAu+SLVGRwYB6EMPeH2C1tE0V3EfLM5GgugmK9ij3u+U1HweATwLjYbzgXDBhgzA6FNqGRvj8JQ8u0C92DL8Z2XqAFFs2JsXl3uIp761oOR5GTfIi0x7/c928ZEvKSe54PTCyxDMoLSNQSonTDpIb//k/+U4xEOQ1mjlSvlOM5ic7/kdw+G+aP/Hk/T6kg/vIblWQHx8SB3WYpLb/R6oPO+05X+zcQ+vVX1TrQ/amDp6/PouWjTF5hf48JEBdM8+xJzUwnalrG9U7pChfyGAOXQT1fbDdywBJXt6pZsT/mz1RkUC5Uto5/aVQGIDD+IPm/ZDbQgoAGDEwF09sjUb5hHEdmG28RmMf4E0JCOEzCvxiUpovobymqapLM5bf2oLNXqGenEAMbfFQatJFVKx6YBZwFIj/xzQJt8fL/jRzlbLijaANP+1JacvTsfXKBXS888FN3rkKisTlhmYXI+4EwA1wbcRkLDH3vezdVCi9cszQ9HvwkVfOwgoAD7QvzD3pirXIJ64JizWTS4MJMko3CWepsq9UZ5uyoHWh7tSz86H/2y0FK10YpJEJeGtyPXlnU+uQwjYMJRPLlNv8180pjCJX2ZTW2drB2vOJvormhMhDIYAZtPAHu2dajzdy4VRuvFTtH4FpW/KjAJrTLK3ze3K95ACYVBJ8EmBwgoADQK8DiNN724hmLjvqTMjiLpJ19U/lE5+jqbM3qmtTDWl0ddr9BdzH9/E2kKZefLbv8VJH2TQjO07hdRhk599/jZ5BGseSQvOyysaEMgj6ZjunwHOwSNjDspdiOk/uTzPIyVmY2eDDD1zRAiWi2jmBTI2vOIm7CSa75TgofLu4XFAoABJrFM4+vYNlFXbY0/LqU+21ttmV+K471rPj0Jto7GPNhZs6CaEr0g8COpDQNA6JoDv5Td0eIDWZ6c+ii5G9H+VjUCc6WprQIhepVkGzsJUjWlOrp66MeVwEElFdAk/PbXBvEUOWYTwi1uY6Y0trzMK31OvFOODKjWf6WHrf4tfgnAoABOri6bX2D/zqpJT3mJ5MIVJJbn4D4Idx+TCUaVRSY1rBp+Y2ofW1W8ktu7xPO9/LwVQR7kJeosEBAFGTmGqll033ywu5+8X8J1bw6HCghkI0yHW752sOdfl30kXi3Ds8tQsvSEHRfnPb8yvWve2srZb9ubwOvpI0PtOIujZP4fYI=" var content = "a=123!@#¥%……中文" signature, error := utils.RsaSignBase64(content, priKey, crypto.SHA256) if nil != error { //sign error } ``` -------------------------------- ### Configure Logging for YOP Go SDK Source: https://github.com/yop-platform/yop-go-sdk/blob/main/README.md Shows how to customize the logging behavior of the YOP Go SDK, including setting a custom log output destination and disabling log output entirely using `io.Discard`. ```go import ( "log" "os" "github.com/yop-platform/yop-go-sdk/yop/utils" ) // Custom log output utils.Logger = log.New(os.Stdout, "YOP-SDK: ", log.LstdFlags) // Disable log output utils.Logger = log.New(io.Discard, "", 0) ``` -------------------------------- ### Verifying Signature with YOP SDK Go Source: https://github.com/yop-platform/yop-go-sdk/blob/main/llms.txt This snippet shows how to verify a signature against a piece of data using the utils.VerifySign function. It requires the data, the signature string, the platform's public key, and the signing algorithm (crypto.SHA256) to check if the signature is valid. ```Go //utils.VerifySign // 此处为测试数据 ``` -------------------------------- ### Utility Functions: Callback Processing API Source: https://github.com/yop-platform/yop-go-sdk/blob/main/README.md API reference for utility functions related to callback processing. ```APIDOC Callback Processing: - utils.DecryptCallback(platformPubKey, isvPriKey, callback string) (string, error): Decrypt callback content ``` -------------------------------- ### API Reference for Signature Operations Source: https://github.com/yop-platform/yop-go-sdk/blob/main/README.md Details the functions available for generating and verifying signatures using RSA with Base64 encoding within the YOP Go SDK. ```APIDOC `utils.RsaSignBase64(content, priKey string, hash crypto.Hash) (string, error)`: Generate signature `utils.VerifySign(data, signature, pubKey string, hash crypto.Hash) bool`: Verify signature ``` -------------------------------- ### Verify RSA Signature in Go Source: https://github.com/yop-platform/yop-go-sdk/blob/main/README.md Demonstrates how to verify an RSA signature using `utils.VerifySign`. This function checks the authenticity of data against a provided signature, public key, and hashing algorithm. It returns a boolean indicating verification success or failure. ```go //utils.VerifySign // This is test data var pubKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwRwXR20F7D0/hKQISwPZNkOTvBiwgFBS1mAee1IXOGTWtmFIY60xbxWTBULjI2lYHZhRk76nxmFEAUZXRxYX/ZLl3+Sz2/ptASf0eQFgsk3F+wx6LqBjgzH8ZAma4piC8GFg5MIWEx6+YRFefJxkULRziFQeWuIv8uGdb719TCIwPvDid86WsVypI/uOjrX5o5aFDxhUs8/q6q0UbTKmHjy5FmdCfgpiFzNSsJf5IGFKv2BkmMvUOb06IzfVgSs5O3rjqAnLFrUawUMrHcjN8gz144Z18extJ4dO4UlIfqzA2e2bLdJVUKJf+5D18zcIenlJkRmPZX67iDEuZINcnQIDAQAB" var signature = "glTZg6lLl6oV4Ho15fAUegcVILlTwYJkbZO_Iz8AYUKTZ_1JP4AqAqSdm3GqjaukoNrDkxPGv2WW8plxYxtzsXjkzWiCMth5aShHgA7a9SXW0jfo365KPyVj0zFO2QIV9odHEnY1apwcAxvr54j4d5SHoC3vKUczZ20txTsNjcG9ifi1AoJhblILxKL2NO0tdIzTMQCRaBdOXUOdnL7RgP1qPew5yJT4e1QdtTjkirCKJurm4SumOA3Uroz-G-9MUZgiTkU4RXrEvu-rJPlqfJPsITYoWLsuPy1Gfne_5j-IgChXpoHacI0s-NlzKmyjsFt3-5aUYDd0cFw58ErUXr" var data = "{\"result\":{\"requestId\":\"requestId\",\"errorMsg\":\"exception.record.not.found.transferDomesticOrder|merchantId:[null],requestId:[requestId]\",\"status\":\"FAILED\"}}" if !utils.VerifySign(data, signature, pubKey, crypto.SHA256) { //verify failed } ``` -------------------------------- ### YopResponse API Reference Source: https://github.com/yop-platform/yop-go-sdk/blob/main/README.md `YopResponse` is the encapsulation of YOP API responses. ```APIDOC YopResponse: Main Properties: - State: Response status - Result: Request result - Error: Error information - Content: Response content (for file downloads) ``` -------------------------------- ### Implement Retry Mechanism for YOP SDK Requests Source: https://github.com/yop-platform/yop-go-sdk/blob/main/README.md Demonstrates a function that implements a retry mechanism with exponential backoff for YOP SDK requests, improving robustness against transient network issues or service unavailability. ```go func requestWithRetry(yopRequest *request.YopRequest, maxRetries int) (*response.YopResponse, error) { var lastErr error for i := 0; i <= maxRetries; i++ { yopResp, err := client.DefaultClient.Request(yopRequest) if err == nil { return yopResp, nil } lastErr = err if i < maxRetries { time.Sleep(time.Duration(i+1) * time.Second) // Exponential backoff } } return nil, fmt.Errorf("request failed after %d retries: %v", maxRetries, lastErr) } ``` -------------------------------- ### Optimize HTTP Connection Pool for YOP SDK Source: https://github.com/yop-platform/yop-go-sdk/blob/main/README.md Shows how to configure the `http.Transport` to optimize connection pooling parameters like `MaxIdleConns`, `MaxIdleConnsPerHost`, and `IdleConnTimeout` for improved performance of HTTP requests. ```go // Optimize HTTP transport configuration transport := &http.Transport{ MaxIdleConns: 100, MaxIdleConnsPerHost: 10, IdleConnTimeout: 90 * time.Second, TLSHandshakeTimeout: 10 * time.Second, } customClient := &http.Client{ Transport: transport, Timeout: 30 * time.Second, } ``` -------------------------------- ### Define YOP Go SDK Certificate Types Source: https://github.com/yop-platform/yop-go-sdk/blob/main/README.md This Go snippet defines the supported certificate types for the YOP Go SDK, specifically RSA2048. These constants are used when configuring the private key for signing requests. ```Go // Defined in the request package const ( RSA2048 = "RSA2048" // RSA2048 algorithm ) ``` -------------------------------- ### Process Batch YOP SDK Requests Concurrently Source: https://github.com/yop-platform/yop-go-sdk/blob/main/README.md Illustrates a Go function for processing multiple YOP SDK requests concurrently using a semaphore to limit the maximum number of parallel goroutines, ensuring efficient resource utilization. ```go func processBatchRequests(requests []*request.YopRequest) { const maxConcurrency = 10 semaphore := make(chan struct{}, maxConcurrency) var wg sync.WaitGroup for _, req := range requests { wg.Add(1) go func(r *request.YopRequest) { defer wg.Done() semaphore <- struct{}{} // Acquire semaphore defer func() { <-semaphore }() // Release semaphore resp, err := client.DefaultClient.Request(r) if err != nil { log.Printf("Request failed: %v", err) return } // Process response... }(req) } wg.Wait() } ``` -------------------------------- ### Making POST JSON Request with YOP SDK Go Source: https://github.com/yop-platform/yop-go-sdk/blob/main/llms.txt This snippet shows how to send a POST request with a JSON request body. Instead of using AddParam, the JSON content is generated from a map using utils.ParseToJsonStr and assigned to the yopRequest.Content field before the request is executed. ```Go var priKey = request.IsvPriKey{Value: "isvPriKey", CertType: request.RSA2048} var yopRequest = request.NewYopRequest(constants.POST_HTTP_METHOD,"/rest/v1.0/test-wdc/product-query/query-for-doc") yopRequest.AppId = "appId" yopRequest.IsvPriKey = priKey // 设置json请求报文 var params = map[string]any{} params["merchantId"] = "1595815987915711" params["requestId"] = "requestId" result.Content = utils.ParseToJsonStr(params) yopResp, err := client.DefaultClient.Request(yopRequest) if nil != err{ // request failed } //yopResp.Result为请求结果 ``` -------------------------------- ### Decrypt Callback Content in Go Source: https://github.com/yop-platform/yop-go-sdk/blob/main/README.md Shows how to decrypt callback content using `utils.DecryptCallback`. This function requires the platform public key, the ISV private key, and the encrypted callback string. It returns the decrypted content or an error. ```go //utils.DecryptCallback var callback = "Ars6jASSiylO70_VJDQ5SFU1zQwaI36kG5WhlSKHjkGdU3fEVEkkbhvAxKjOTUiw9vF7RMnmGKQQWAuV8jCKaOpMNjIEMHehBaPASwTiEE946CcbOeoNILGHf0o20xj2gqqvkQToFXEMNiic7bcYbfi0PxIrR6loBZnW-m5bqzB5RXLibiSjGlmr5CDnxV4tZXmYlkkeN2BcT4msWjfCtuaTMK_fN77WJcCMlW7ffqiN5yIOeqB4QBb5lOnClTRW4DThKPOMkXupAM2AnPxTkDp4n9lh-SK56zLuafk1bQhWUNcS9L4YEKZGJIjP7DY20TAWEr3yXo8w0w0VtB13Ig$Xf6fETKWcLTudBh2HluGSQTqhBRJa6EXHhXlMryWW8Y384RjVwIfpQm19RmTgkoqRc2tNcTWxRIW6itIS62DrzixlqRa099jx21uGqt8FCpvdWwnwlC16SgkeU_5NnrpjA_WQ0XW9RhNxzuQmwfxHGbtnth4vNXWswcSm23j3KQaXFjVP5Ws1uYVCxYSLMxqJE7a56DNWONGcGJJsc0KTCc7cdfr8n24emAaPCNteIG2RM8B17pRxY5yVnguTSZPXmhBlyI25xS7rciWzKZLp2Kfh_JCivABbA-_5V3VWPmjITs-TR5HlGVFbnT0eOUMUepXUemjjP8R0f8cBeH2NKej6QjQL99tvlrrxg_QfmezE0WTCITCNDBhpbHiq90lFyLjwlWNDTRo8rhjouSlMA9Ae_b-B4eZorDRVxw3BWywdyo2FzNk-dUDeBVaIth9YsaMGsq9XivGjlnnx3YEVfEtuVSvEm1xBdYsTHcM02nMwZb8Ze2WL1kIFo8IFM0$AES$SHA256" // This is test data, please use the real platform public key for production var platformPubKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7LqdMV7ZeOWUwVp0duSucTr4VwUNHtYLlWEUWlBtDQDEPhx0WZZdwzDxEbQqMQM5BjXZACYlhEdPt0HicDthOIUeUt8JNcvgq06vIE958RzgVBa5z3zvMLYWJIZaUyxsxC7Us06eNiB+du0rEBxUckru41ZSu/DX9jssFC+l5459b3WWELNf2fXqJyfb4f8GuGk8enXgJdxBUcmwgaEQxJjWkPqhzSiRy9GKjcXBdCkzCYR4xmLkHe6K0YFiBxax7lOni3zVOsvHC9XdhbepwB9fMkHbZXS/LJf5aS5ltendObpVrAD9kck7bIQzsrM49/SG/dYmbtm139I6ygsCzQIDAQAB" var isvPriKey = "" content, err := utils.DecryptCallback(platformPubKey, isvPriKey, callback) if nil != err { //"decrypt failed" } ```