spywiree-priv / translateimage

Google Translate Images for free in Go
MIT License
2 stars 1 forks source link

It is inconvenient to pass in language parameters #7

Closed Avey777 closed 5 months ago

Avey777 commented 5 months ago

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?

spywiree-priv commented 5 months ago

Something like this? https://github.com/spywiree/langcodes/pull/1

Avey777 commented 5 months ago
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

spywiree-priv commented 5 months ago

You can just use string(languagecodes.ENGLISH).