环境准备
1、Go语言版本
go version go1.12.7 windows/amd64
2、开发使用IDE
LiteIDE
3、SDK安装
go get -u github.com/aliyun/alibaba-cloud-sdk-go/sdk
测试代码
package main
import (
"fmt"
"github.com/aliyun/alibaba-cloud-sdk-go/services/alimt"
)
func main() {
client, err := alimt.NewClientWithAccessKey("cn-hangzhou", "LTAIOZZg********", "v7CjUJCMk7j9aKdu****************")
request := alimt.CreateTranslateGeneralRequest()
request.Scheme = "https"
request.FormatType = "text"
request.SourceLanguage = "zh"
request.TargetLanguage = "en"
request.SourceText = "北京欢迎你"
response, err := client.TranslateGeneral(request)
if err != nil {
fmt.Print(err.Error())
}
fmt.Printf("response is %#v\n", response)
}
运行结果
RequestId:"EE89EA3D-5758-4184-A270-A6392441CD9C", Code:200, Message:"", Data:alimt.Data{Translated:"Welcome to Beijing"}}