In this tutorial you will find how to start oss-go-sdk and get the bucket list from the server
Go to OSS website, create a new account for new user.
After account created, you can create the OSS instance and get the accessKeyId
and accessKeySecret
.
Just use the simple go get
to install the sdk
go get -v github.com/Lupino/oss-go-sdk
Once you installed the sdk import
it on you code.
import (
"github.com/Lupino/oss-go-sdk"
)
Get the default api options use oss.GetDefaultAPIOptioins
,
then set the access key and secret from you OSS account.
var APIOptions = oss.GetDefaultAPIOptioins()
APIOptions.AccessID = AccessKeyID
APIOptions.SecretAccessKey = AccessKeySecret
var OSSAPI, err = oss.NewAPI(APIOptions)
oss.ListAllMyBucketsResult
is the result of GetService
,
it also parse some argument for GetService
,
the argument is Prefix
, Marker
, MaxKeys
.
var result oss.ListAllMyBucketsResult
var headers = make(map[string]string)
var err error
err = OSSAPI.GetService(&result, headers)
oss-go-sdk
implement error return by OSS into error
interface by oss.Error
,
so you can get error return by OSS server from oss.Error
, just like:
var realErr = err.(*oss.Error)
the source code main.go