go-ddns-svc/module/apis/aws/aws.go
2019-05-02 18:08:39 +08:00

63 lines
1.2 KiB
Go

package aws
import (
"errors"
"git.trj.tw/golang/go-ddns-svc/module/config"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/route53"
)
// AWSClient -
type AWSClient struct {
Session *session.Session
Config *aws.Config
R53 *route53.Route53
}
var client *AWSClient
// Error messages
var (
ErrNoClient = errors.New("client not init")
)
// NewAWS -
func NewAWS() error {
conf := config.GetConfig()
awsConf := &aws.Config{}
awsConf.Region = aws.String("us-east-1")
var sess *session.Session
if conf.AWS.SharedConfig {
if len(conf.AWS.SharedName) == 0 {
return errors.New("aws shared config name empty")
}
awsConf.Credentials = credentials.NewSharedCredentials("", conf.AWS.SharedName)
} else {
awsConf.Credentials = credentials.NewStaticCredentials(conf.AWS.AccessKey, conf.AWS.SecretKey, "")
}
sess = session.New(awsConf)
client = &AWSClient{}
client.Session = sess
client.Config = awsConf
client.R53 = route53.New(client.Session)
return nil
}
// ZoneData -
type ZoneData struct {
ID *string
Name string
}
// QueryDomain -
func QueryDomain() (*ZoneData, error) {
return nil, nil
}