Closed Avey777 closed 5 months ago
Something like this? https://github.com/spywiree/langcodes/pull/1
type RequestData struct {
PATH. string `json:"PATH"`
SL string `json:"SL"`
TL string `json:"TL"`
}
func handlePostRequest(c *gin.Context) {
var requestData RequestData
// 解析传入的 JSON 数据并映射到 requestData 结构体上
if err := c.ShouldBindJSON(&requestData); err != nil {
c.JSON(400, gin.H{"error": "Invalid JSON format"})
return
TranslateList, err := TranslateImages(requestData.PATH,requestData.SL, requestDataTL)
if err != nil {
log.Print(err)
c.JSON(http.StatusBadRequest, gin.H{"status": " err", "TranslateImages": "TranslateImages 传入参数错误"})
}
log.Print(TranslateList)
c.JSON(http.StatusBadRequest, gin.H{"status": " ok", "TranslateImages": TranslateImages})
}
Parameter passing as shown above is not possible because languages.ENGLISH is not a string type
You can just use string(languagecodes.ENGLISH).
languagecodes.DETECT_LANGUAGE, languagecodes.ENGLISH
The parameter passing types of the source language and target language are customized, and it is inconvenient to use the API to pass parameters.
https://github.com/Avey777/translateimage/blob/main/example2/languageCodeMap.go Is there a simpler solution?