From dafdf2f72eb75dc8769ddf5d1a1e5781edcc112b Mon Sep 17 00:00:00 2001 From: ben Gutier Date: Tue, 12 Sep 2023 16:11:46 +0800 Subject: [PATCH] 20239/12 16:11 --- src/test.go | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/test.go diff --git a/src/test.go b/src/test.go new file mode 100644 index 0000000..1913fb8 --- /dev/null +++ b/src/test.go @@ -0,0 +1,86 @@ +package main + +import ( + "encoding/json" + "github.com/gin-gonic/gin" + "net/http" +) + +func getGithubTest(c *gin.Context, token string) { + githubApiCount++ + data1 := ` + { + "chat_enabled": false, + "code_quote_enabled": false, + "code_quote_v2_enabled": false, + "copilotignore_enabled": false, + "expires_at": 3194360727, + "prompt_8k": true, + "public_suggestions": "disabled", + "refresh_in": 1500, + "sku": "free_educational", + "telemetry": "disabled", + "token": "tid=;exp=1694360727;sku=free_educational;st=dotcom;8kp=1:", + "tracking_id": "" + } + ` + data2 := ` + { + "chat_enabled": false, + "code_quote_enabled": false, + "code_quote_v2_enabled": false, + "copilotignore_enabled": false, + "expires_at": 2294360727, + "prompt_8k": true, + "public_suggestions": "disabled", + "refresh_in": 1500, + "sku": "free_educational", + "telemetry": "disabled", + "token": "tid=;exp=1694360727;sku=free_educational;st=dotcom;8kp=1:", + "tracking_id": "" + } + ` + data3 := ` + { + "chat_enabled": false, + "code_quote_enabled": false, + "code_quote_v2_enabled": false, + "copilotignore_enabled": false, + "expires_at": 3394360727, + "prompt_8k": true, + "public_suggestions": "disabled", + "refresh_in": 1500, + "sku": "free_educational", + "telemetry": "disabled", + "token": "tid=;exp=1694360727;sku=free_educational;st=dotcom;8kp=1:", + "tracking_id": "" + } + ` + //响应体map + var respDataMap = make(map[string]interface{}) + if token == "1" { + err := json.Unmarshal([]byte(data1), &respDataMap) + if err != nil { + // 处理JSON解析错误 + c.JSON(http.StatusInternalServerError, gin.H{"error": "JSON parsing error"}) + return + } + } else if token == "2" { + err := json.Unmarshal([]byte(data2), &respDataMap) + if err != nil { + // 处理JSON解析错误 + c.JSON(http.StatusInternalServerError, gin.H{"error": "JSON parsing error"}) + return + } + } else { + err := json.Unmarshal([]byte(data3), &respDataMap) + if err != nil { + // 处理JSON解析错误 + c.JSON(http.StatusInternalServerError, gin.H{"error": "JSON parsing error"}) + return + } + } + + //token map + tokenMap[token] = respDataMap +}