阿里云机器翻译Go使用Demo

环境准备

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"}}

参考链接

机器翻译通用版调用指南
阿里云新版人脸识别Go语言调用示例

上一篇:总结之:CentOS 6.5 rsync+inotify实现数据实时同步备份


下一篇:阿里云机器翻译Go使用Demo