The ODPS (Open Data Processing Service) object is the entry point for the MaxCompute Go SDK. All resources in the project space—projects, tables, and instances—are accessed through this object.
Prerequisites
Before you begin, ensure that you have:
-
Configured access credentials. For more information, see Configure access credentials of the Go SDK
Initialize the SDK
The following example loads credentials from a configuration file and creates an ODPS instance.
package main
import (
"fmt"
"log"
"github.com/aliyun/aliyun-odps-go-sdk/odps"
"github.com/aliyun/aliyun-odps-go-sdk/odps/account"
)
func main() {
// Load credentials and endpoint from the configuration file
configPath := "./config.ini"
conf, err := odps.NewConfigFromIni(configPath)
if err != nil {
log.Fatalf("%+v", err)
}
aliAccount := account.NewAliyunAccount(conf.AccessId, conf.AccessKey)
odpsIns := odps.NewOdps(aliAccount, conf.Endpoint)
// Set the default MaxCompute project
odpsIns.SetDefaultProjectName(conf.ProjectName)
fmt.Printf("odps:%#v\n", odpsIns)
}
What's next
After the SDK is initialized, use the Go SDK to run SQL queries, manage data uploads and downloads, and work with tables and partitions. For more information, see Use the Go SDK.