From 95c20be482c28abfec2e352a9a636b37ecdc3936 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 4 Jan 2013 22:14:15 +0000 Subject: [PATCH 1/6] go fix and gofmt to make go 1.0 compatible --- consts.go | 15 +++-- dialer.go | 35 +++++------ ec2/instance.go | 5 +- ec2/service.go | 21 ++++--- ec2/util/ec2_main.go | 19 +++--- elb/service.go | 35 ++++++----- elb/util/elb_main.go | 33 +++++----- escape.go | 6 +- flags/init.go | 7 ++- http_dialer.go | 41 +++++++------ s3/bucket_opers.go | 64 +++++++++---------- s3/consts.go | 1 - s3/service_opers.go | 27 ++++---- s3/util/s3_main.go | 46 +++++++------- samples/s3_proxy/config.go | 16 +++-- samples/s3_proxy/main.go | 10 +-- sdb/attribute.go | 7 +-- sdb/domain.go | 23 +++---- sdb/response.go | 2 - sdb/service.go | 41 +++++++------ sdb/util/sdb_main.go | 38 ++++++------ signer.go | 123 ++++++++++++++++++++----------------- sqs/consts.go | 1 - sqs/queue.go | 41 +++++++------ sqs/service.go | 33 +++++----- sqs/util/sqs_main.go | 40 ++++++------ util/common/common.go | 9 +-- util/main.go | 15 ++--- 28 files changed, 377 insertions(+), 377 deletions(-) diff --git a/consts.go b/consts.go index 33f5263..5f23ff0 100644 --- a/consts.go +++ b/consts.go @@ -1,8 +1,8 @@ package aws import ( - "os" - "http" + "errors" + "net/http" ) const ( @@ -10,13 +10,12 @@ const ( DEFAULT_SIGNATURE_METHOD = "HmacSHA256" ) +var ErrorNotFound = errors.New("Not found") +var ErrorUnexpectedResponse = errors.New("Unexpected response code") +var ErrorConflicts = errors.New("Conflicts with another resources") +var ErrorForbidden = errors.New("Access denied") -var ErrorNotFound os.Error = os.NewError("Not found") -var ErrorUnexpectedResponse os.Error = os.NewError("Unexpected response code") -var ErrorConflicts os.Error = os.NewError("Conflicts with another resources") -var ErrorForbidden os.Error = os.NewError("Access denied") - -func CodeToError(i int) (err os.Error) { +func CodeToError(i int) (err error) { switch i { case http.StatusOK: case http.StatusNotFound: diff --git a/dialer.go b/dialer.go index f35f9d3..9805a70 100644 --- a/dialer.go +++ b/dialer.go @@ -1,8 +1,8 @@ package aws import ( + "errors" "net" - "os" "sync" // "log" ) @@ -11,13 +11,13 @@ import ( // upper-case functions should use a defer lock.Unlock to ensure // underlying dialer/socket panics will not leave locks hanging. -var ErrUnderlyingNotconnected = os.NewError("Underlying socket is not connected") +var ErrUnderlyingNotconnected = errors.New("Underlying socket is not connected") // A Dialer is usually a closuer that // is pre-configured to the callers tastes. // // (see URLDialer for an example/default generator) -type Dialer func() (net.Conn, os.Error) +type Dialer func() (net.Conn, error) // A Reusable conn is a syncronized structure around a // Dialer / net.Conn pair. All net.Conn calls are wrapped @@ -48,7 +48,7 @@ func NewReusableConnection(d Dialer) (c *ReusableConn) { } // Dial is idempotent, and safe to call; -func (self *ReusableConn) Dial() (err os.Error) { +func (self *ReusableConn) Dial() (err error) { // log.Printf("Public Dial() called") self.lock.Lock() defer self.lock.Unlock() @@ -59,7 +59,7 @@ func (self *ReusableConn) Dial() (err os.Error) { // timeouts if they've been set by the caller. // // It simply returns nil if the socket appears already connected -func (self *ReusableConn) dial() (err os.Error) { +func (self *ReusableConn) dial() (err error) { // log.Printf("Private dial() called (%v)", self.conn) if self.conn == nil { self.conn, err = self.dialer() @@ -74,7 +74,7 @@ func (self *ReusableConn) dial() (err os.Error) { return } -func (self *ReusableConn) close() (err os.Error) { +func (self *ReusableConn) close() (err error) { if self.conn != nil { err = self.conn.Close() self.conn = nil @@ -84,7 +84,7 @@ func (self *ReusableConn) close() (err os.Error) { // Unlike close on a traditional socket, no error // is raised if you close a closed (nil) connection. -func (self *ReusableConn) Close() (err os.Error) { +func (self *ReusableConn) Close() (err error) { self.lock.Lock() defer self.lock.Unlock() return self.close() @@ -111,7 +111,7 @@ func (self *ReusableConn) LocalAddr() (a net.Addr) { return } -func (self *ReusableConn) read(in []byte) (n int, err os.Error) { +func (self *ReusableConn) read(in []byte) (n int, err error) { err = self.dial() if err == nil { n, err = self.conn.Read(in) @@ -122,7 +122,7 @@ func (self *ReusableConn) read(in []byte) (n int, err os.Error) { return } -func (self *ReusableConn) write(in []byte) (n int, err os.Error) { +func (self *ReusableConn) write(in []byte) (n int, err error) { err = self.dial() if err == nil { n, err = self.conn.Write(in) @@ -133,25 +133,23 @@ func (self *ReusableConn) write(in []byte) (n int, err os.Error) { return } - // Read from the underlying connection, triggering a dial if needed. // NB: For the expected case (HTTP), this shouldn't happen before the // first Write. -func (self *ReusableConn) Read(in []byte) (n int, err os.Error) { +func (self *ReusableConn) Read(in []byte) (n int, err error) { self.lock.Lock() defer self.lock.Unlock() return self.read(in) } // Write to the underlying connection, triggering a dial if needed. -func (self *ReusableConn) Write(out []byte) (n int, err os.Error) { +func (self *ReusableConn) Write(out []byte) (n int, err error) { self.lock.Lock() defer self.lock.Unlock() return self.write(out) } - -func (self *ReusableConn) setReadTimeout(t int64) (err os.Error) { +func (self *ReusableConn) setReadTimeout(t int64) (err error) { err = self.dial() if err == nil { err = self.conn.SetReadTimeout(t) @@ -162,7 +160,7 @@ func (self *ReusableConn) setReadTimeout(t int64) (err os.Error) { return } -func (self *ReusableConn) setWriteTimeout(t int64) (err os.Error) { +func (self *ReusableConn) setWriteTimeout(t int64) (err error) { err = self.dial() if err == nil { err = self.conn.SetWriteTimeout(t) @@ -173,10 +171,9 @@ func (self *ReusableConn) setWriteTimeout(t int64) (err os.Error) { return } - // Sets the read timeout on the underlying socket, as well // as an internal flag for any future re-opened connections. -func (self *ReusableConn) SetReadTimeout(t int64) (err os.Error) { +func (self *ReusableConn) SetReadTimeout(t int64) (err error) { self.lock.Lock() defer self.lock.Unlock() return self.setReadTimeout(t) @@ -184,14 +181,14 @@ func (self *ReusableConn) SetReadTimeout(t int64) (err os.Error) { // Sets the write timeout on the underlying socket, as well // as an internal flag for any future re-opened connections. -func (self *ReusableConn) SetWriteTimeout(t int64) (err os.Error) { +func (self *ReusableConn) SetWriteTimeout(t int64) (err error) { self.lock.Lock() defer self.lock.Unlock() return self.setWriteTimeout(t) } // Conveinience function for Set(read|write)timeout -func (self *ReusableConn) SetTimeout(t int64) (err os.Error) { +func (self *ReusableConn) SetTimeout(t int64) (err error) { err = self.SetReadTimeout(t) if err == nil { err = self.SetWriteTimeout(t) diff --git a/ec2/instance.go b/ec2/instance.go index 5c9750e..a2105c9 100644 --- a/ec2/instance.go +++ b/ec2/instance.go @@ -1,9 +1,9 @@ package ec2 - import ( - "xml" + "encoding/xml" ) + /* The XML package doesn't do deeply-nested types with reflection well, so much of the functionality provided is simply hacks @@ -27,7 +27,6 @@ type ReservationSet struct { Instances []Instance "instancesSet>item" } - // At the level of depth we're at, XML's // not happy with us type Instance struct { diff --git a/ec2/service.go b/ec2/service.go index 26018ce..2aec6e0 100644 --- a/ec2/service.go +++ b/ec2/service.go @@ -2,30 +2,31 @@ package ec2 import ( "aws" + "net/url" ) import ( - "http" + "encoding/xml" "log" + "net/http/httputil" "os" - "xml" ) type Service struct { conn *aws.Conn - URL *http.URL + URL *url.URL } -func NewService(url *http.URL) (s *Service) { +func NewService(url_ *url.URL) (s *Service) { return &Service{ - URL: url, - conn: aws.NewConn(aws.URLDialer(url, nil)), + URL: url_, + conn: aws.NewConn(aws.URLDialer(url_, nil)), } } -func (self *Service) DescribeInstances(id *aws.Signer, filter http.Values, ic chan Instance) (err os.Error) { +func (self *Service) DescribeInstances(id *aws.Signer, filter url.Values, ic chan Instance) (err error) { if filter == nil { - filter = http.Values{} + filter = url.Values{} } filter.Set("Action", "DescribeInstances") req := aws.NewRequest(self.URL, "GET", nil, filter) @@ -43,7 +44,7 @@ func (self *Service) DescribeInstances(id *aws.Signer, filter http.Values, ic ch } else { log.Printf("XERR == %+v", err) } - ob, _ := http.DumpResponse(resp, true) + ob, _ := httputil.DumpResponse(resp, true) os.Stdout.Write(ob) } @@ -51,6 +52,6 @@ func (self *Service) DescribeInstances(id *aws.Signer, filter http.Values, ic ch } // Closes the underlying connection -func (self *Service) Close() (err os.Error) { +func (self *Service) Close() (err error) { return self.conn.Close() } diff --git a/ec2/util/ec2_main.go b/ec2/util/ec2_main.go index aa7f51f..e3d2116 100644 --- a/ec2/util/ec2_main.go +++ b/ec2/util/ec2_main.go @@ -1,17 +1,16 @@ package ec2_util import ( - . "aws/util/common" - . "aws/flags" - "aws/ec2" "aws" + "aws/ec2" + . "aws/flags" + . "aws/util/common" + "net/url" ) import ( - "http" - "os" - "fmt" "flag" + "fmt" ) // Safety warning @@ -24,12 +23,12 @@ import ( var flag_endpoint_url string = "" // Convenience method to clean up calls. -func DefaultEC2Service() (id *aws.Signer, s *ec2.Service, err os.Error) { +func DefaultEC2Service() (id *aws.Signer, s *ec2.Service, err error) { id, err = DefaultSigner() if err == nil { - url, err := http.ParseURL(flag_endpoint_url) + url_, err := url.Parse(flag_endpoint_url) if err == nil { - s = ec2.NewService(url) + s = ec2.NewService(url_) } } return @@ -39,7 +38,7 @@ func init() { AddModule("ec2", func() { flag.StringVar(&flag_endpoint_url, "ec2-endpoint", "https://ec2.amazonaws.com/", "Endpoint to use for EC2 calls") }) - Modules["ec2"].Calls["instances"] = func(args []string) (err os.Error) { + Modules["ec2"].Calls["instances"] = func(args []string) (err error) { id, s, err := DefaultEC2Service() if err != nil { return diff --git a/elb/service.go b/elb/service.go index d266bef..96c2414 100644 --- a/elb/service.go +++ b/elb/service.go @@ -2,13 +2,15 @@ package elb import ( "aws" + "errors" + "net/url" ) import ( "crypto" - "http" + "encoding/xml" . "fmt" - "xml" + "net/http/httputil" "os" "strconv" ) @@ -19,14 +21,14 @@ const ( ) type Service struct { - URL *http.URL + URL *url.URL conn *aws.Conn } -func NewService(url *http.URL) *Service { +func NewService(url_ *url.URL) *Service { return &Service{ - URL: url, - conn: aws.NewConn(aws.URLDialer(url, nil)), + URL: url_, + conn: aws.NewConn(aws.URLDialer(url_, nil)), } } @@ -37,14 +39,14 @@ type Listener struct { SSLCertificateID string } -func (self Listener) SetValues(v http.Values, i int) { +func (self Listener) SetValues(v url.Values, i int) { v.Set(Sprintf("Listeners.members.%d.LoadBalancerPort", i), strconv.Itoa(self.LoadBalancerPort)) v.Set(Sprintf("Listeners.members.%d.InstancePort", i), strconv.Itoa(self.InstancePort)) v.Set(Sprintf("Listeners.members.%d.Protocol", i), self.Protocol) } -func (self *Service) CreateLoadBalancer(id *aws.Signer, name string, zones []string, listeners []Listener) (err os.Error) { - parms := http.Values{} +func (self *Service) CreateLoadBalancer(id *aws.Signer, name string, zones []string, listeners []Listener) (err error) { + parms := url.Values{} parms.Set("Action", "CreateLoadBalancer") parms.Set("LoadBalancerName", name) for zi := range zones { @@ -61,15 +63,15 @@ func (self *Service) CreateLoadBalancer(id *aws.Signer, name string, zones []str resp, err := self.conn.Request(req) if err == nil { defer resp.Body.Close() - ob, _ := http.DumpResponse(resp, true) + ob, _ := httputil.DumpResponse(resp, true) os.Stdout.Write(ob) } return } -func (self *Service) DescribeLoadBalancers(id *aws.Signer) (lbs []LoadBalancerDescription, err os.Error) { - parms := http.Values{} +func (self *Service) DescribeLoadBalancers(id *aws.Signer) (lbs []LoadBalancerDescription, err error) { + parms := url.Values{} parms.Set("Action", "DescribeLoadBalancers") req := aws.NewRequest(self.URL, "GET", nil, parms) err = id.SignRequestV2(req, aws.Canonicalize, DEFAULT_VERSION, 0) @@ -89,11 +91,10 @@ func (self *Service) DescribeLoadBalancers(id *aws.Signer) (lbs []LoadBalancerDe return } - // Users note: amazon will only return an error if the request is bad, // thus an error will not be raised when deleting a non-existent LB. -func (self *Service) DeleteLoadBalancer(id *aws.Signer, name string) (err os.Error) { - parms := http.Values{} +func (self *Service) DeleteLoadBalancer(id *aws.Signer, name string) (err error) { + parms := url.Values{} parms.Set("Action", "DeleteLoadBalancer") parms.Set("LoadBalancerName", name) req := aws.NewRequest(self.URL, "GET", nil, parms) @@ -113,13 +114,13 @@ func (self *Service) DeleteLoadBalancer(id *aws.Signer, name string) (err os.Err err = xml.Unmarshal(resp.Body, &qr) if err == nil { if qr.ErrorCode != "" { - err = os.NewError(qr.ErrorCode) + err = errors.New(qr.ErrorCode) } } return } // Closes the underlying connection -func (self *Service) Close() (err os.Error) { +func (self *Service) Close() (err error) { return self.conn.Close() } diff --git a/elb/util/elb_main.go b/elb/util/elb_main.go index c5ebb43..58601cb 100644 --- a/elb/util/elb_main.go +++ b/elb/util/elb_main.go @@ -1,17 +1,17 @@ package elb_util import ( + "aws" "aws/elb" . "aws/flags" . "aws/util/common" - "aws" + "errors" + "net/url" ) import ( "flag" "fmt" - "http" - "os" "strconv" "strings" ) @@ -28,36 +28,35 @@ var signer *aws.Signer var service *elb.Service // Convenience method to clean up calls. -func DefaultELBService() (id *aws.Signer, s *elb.Service, err os.Error) { +func DefaultELBService() (id *aws.Signer, s *elb.Service, err error) { id, err = DefaultSigner() if err == nil { - url, err := http.ParseURL(flag_endpoint_url) + url_, err := url.Parse(flag_endpoint_url) if err == nil { - s = elb.NewService(url) + s = elb.NewService(url_) } } return } - func init() { AddModule("elb", func() { flag.StringVar(&flag_endpoint_url, "elb-endpoint", "https://elasticloadbalancing.amazonaws.com/", "Endpoint to use for S3 calls") }) - Modules["elb"].Setup = func() (err os.Error) { + Modules["elb"].Setup = func() (err error) { signer, service, err = DefaultELBService() return } - Modules["elb"].Calls["destroy"] = func(args []string) (err os.Error) { + Modules["elb"].Calls["destroy"] = func(args []string) (err error) { if len(args) != 1 { - err = os.NewError("Usage: destroy lbname") + err = errors.New("Usage: destroy lbname") } err = service.DeleteLoadBalancer(signer, args[0]) return } - Modules["elb"].Calls["list"] = func(args []string) (err os.Error) { + Modules["elb"].Calls["list"] = func(args []string) (err error) { if len(args) != 0 { - err = os.NewError("Usage: list") + err = errors.New("Usage: list") } lbd, err := service.DescribeLoadBalancers(signer) if err == nil { @@ -68,15 +67,15 @@ func init() { return } - Modules["elb"].Calls["create"] = func(args []string) (err os.Error) { + Modules["elb"].Calls["create"] = func(args []string) (err error) { if len(args) != 3 { - return os.NewError("Usage: create name zone[,zone2] lbport,iport,proto") + return errors.New("Usage: create name zone[,zone2] lbport,iport,proto") } name := args[0] - zones := strings.Split(args[1], ",", -1) - triple := strings.Split(args[2], ",", 3) + zones := strings.Split(args[1], ",") + triple := strings.SplitN(args[2], ",", 3) if len(triple) != 3 { - return os.NewError("Invalid lbport/iport/proto triple") + return errors.New("Invalid lbport/iport/proto triple") } l := elb.Listener{} l.InstancePort, err = strconv.Atoi(triple[0]) diff --git a/escape.go b/escape.go index 41446a8..4c26826 100644 --- a/escape.go +++ b/escape.go @@ -1,7 +1,7 @@ package aws import ( - "http" + "net/url" "sort" ) @@ -12,12 +12,12 @@ import ( // // Sorted Escape also sorts the keys before joining them (needed // for canonicalization). -func SortedEscape(v http.Values) (out string) { +func SortedEscape(v url.Values) (out string) { keys := []string{} for k, _ := range v { keys = append(keys, k) } - sort.SortStrings(keys) + sort.Strings(keys) for k := range keys { if k > 0 { out += "&" diff --git a/flags/init.go b/flags/init.go index 928ee2f..6679e97 100644 --- a/flags/init.go +++ b/flags/init.go @@ -1,4 +1,5 @@ package flags + // The flags module is primarily a convenience module for those // who want to request the AWS identity on the command line // It should be noted that this approach is not particularly secure @@ -6,6 +7,7 @@ package flags import ( "aws" + "errors" ) import ( @@ -13,7 +15,6 @@ import ( "os" ) - var accessKey *string = flag.String("aws-access-key", os.Getenv("AWS_ACCESS_KEY_ID"), "AWS Access Key") @@ -21,12 +22,12 @@ var secretKey *string = flag.String("aws-secret-key", os.Getenv("AWS_SECRET_ACCESS_KEY"), "AWS Secret Key") // Returns the aws.Signer associated with the aws-*-key flags. -func DefaultSigner() (signer *aws.Signer, err os.Error) { +func DefaultSigner() (signer *aws.Signer, err error) { if accessKey == nil || secretKey == nil { flag.Parse() } if *accessKey == "" || *secretKey == "" { - err = os.NewError("No default access key provided") + err = errors.New("No default access key provided") } else { signer = aws.NewSigner(*accessKey, *secretKey) } diff --git a/http_dialer.go b/http_dialer.go index 8f18d0e..73ec26c 100644 --- a/http_dialer.go +++ b/http_dialer.go @@ -2,16 +2,17 @@ package aws import ( "crypto/tls" - "http" "net" - "os" + "net/http" + "net/http/httputil" + "net/url" ) // The conn structure represents a 'semi detached' http-client // It handles redialing & reconnecting on connection errors. type Conn struct { uc *ReusableConn - c *http.ClientConn + c *httputil.ClientConn } // Creates a new connection with the specified dialer function. @@ -22,23 +23,22 @@ func NewConn(d Dialer) *Conn { } } -func (self *Conn) dial() (err os.Error) { +func (self *Conn) dial() (err error) { if self.c == nil { // Get the underlying connection (or redial) err = self.uc.Dial() if err == nil { - self.c = http.NewClientConn(self.uc, nil) + self.c = httputil.NewClientConn(self.uc, nil) } } return } - // Closes the underlying connection // // NB: if you re-use the connection after // this, it will be redialed. -func (self *Conn) Close() (err os.Error) { +func (self *Conn) Close() (err error) { if self.c != nil { self.c.Close() self.c = nil @@ -51,7 +51,7 @@ func (self *Conn) Close() (err os.Error) { // Write a request and read the response; // This function will also fix-up req.Form for 'GET's -func (self *Conn) Request(req *http.Request) (resp *http.Response, err os.Error) { +func (self *Conn) Request(req *http.Request) (resp *http.Response, err error) { err = self.dial() if err == nil { if req.Form != nil && req.Method == "GET" { @@ -67,7 +67,7 @@ func (self *Conn) Request(req *http.Request) (resp *http.Response, err os.Error) } } if err != nil { - if err == http.ErrPersistEOF { + if err == httputil.ErrPersistEOF { err = nil } self.Close() @@ -75,9 +75,8 @@ func (self *Conn) Request(req *http.Request) (resp *http.Response, err os.Error) return } - // A generic Dialer to handle both TLS and non TLS http connections. -func URLDialer(u *http.URL, conf *tls.Config) (f func() (c net.Conn, err os.Error)) { +func URLDialer(u *url.URL, conf *tls.Config) (f func() (c net.Conn, err error)) { host, port, _ := net.SplitHostPort(u.Host) if port == "" { if u.Scheme == "http" { @@ -92,7 +91,7 @@ func URLDialer(u *http.URL, conf *tls.Config) (f func() (c net.Conn, err os.Erro } useTLS := (u.Scheme == "https") - f = func() (c net.Conn, err os.Error) { + f = func() (c net.Conn, err error) { if useTLS { return tls.Dial("tcp", host+":"+port, conf) } @@ -102,18 +101,20 @@ func URLDialer(u *http.URL, conf *tls.Config) (f func() (c net.Conn, err os.Erro } // Constructs a basic http.Request based off of a fully-qualified URL -func NewRequest(url *http.URL, method string, hdrs http.Header, params http.Values) (req *http.Request ){ +func NewRequest(url_ *url.URL, method string, hdrs http.Header, params url.Values) (req *http.Request) { req = &http.Request{ Method: method, - URL: &http.URL{ - Path: url.Path, - RawQuery: url.RawQuery, + URL: &url.URL{ + Path: url_.Path, + RawQuery: url_.RawQuery, }, - Host: url.Host, + Host: url_.Host, Header: hdrs, Form: params, } - if req.URL.RawQuery != "" { req.URL.RawQuery += "&" } - req.URL.RawQuery += params.Encode() - return + if req.URL.RawQuery != "" { + req.URL.RawQuery += "&" + } + req.URL.RawQuery += params.Encode() + return } diff --git a/s3/bucket_opers.go b/s3/bucket_opers.go index bbe7bdd..80ddb26 100644 --- a/s3/bucket_opers.go +++ b/s3/bucket_opers.go @@ -2,24 +2,26 @@ package s3 import ( "aws" + "errors" + "net/url" ) import ( "bytes" - "http" + "encoding/xml" "io" "io/ioutil" "net" + "net/http" + "net/http/httputil" "os" "path" - "xml" ) - // Represents a URL and connection to an S3 bucket. type Bucket struct { Name string - URL *http.URL + URL *url.URL conn *aws.Conn } @@ -32,15 +34,15 @@ type Bucket struct { // If you omit conn, the dialer used will be based off the VHost of your bucket (if possible), // to ensure best performance (e.g., endpoint associated w/ your bucket, and any // regional lb's) -func NewBucket(u *http.URL, Name string, conn *aws.Conn) (b *Bucket) { +func NewBucket(u *url.URL, Name string, conn *aws.Conn) (b *Bucket) { if u == nil { - u = &http.URL{Scheme: "https", Host: USEAST_HOST, Path: "/"} + u = &url.URL{Scheme: "https", Host: USEAST_HOST, Path: "/"} } if conn == nil { vname := VhostName(Name, u) addrs, err := net.LookupHost(vname) if err == nil && len(addrs) > 0 { - dial_url := &http.URL{ + dial_url := &url.URL{ Scheme: u.Scheme, Host: vname, Path: u.Path, @@ -59,22 +61,21 @@ func NewBucket(u *http.URL, Name string, conn *aws.Conn) (b *Bucket) { } // Returns the vhost name of the bucket (bucket.s3.amazonaws.com) -func VhostName(b string, ep *http.URL) string { +func VhostName(b string, ep *url.URL) string { return b + "." + ep.Host } -func (self *Bucket) key_url(key string) *http.URL { - return &http.URL{ +func (self *Bucket) key_url(key string) *url.URL { + return &url.URL{ Scheme: self.URL.Scheme, Host: self.URL.Host, Path: path.Join(self.URL.Path, self.Name, key), } } - // Will open a local file, size it, and upload it to the named key. // This is a convenience wrapper aroudn PutFile. -func (self *Bucket) PutLocalFile(id *aws.Signer, key, file string) (err os.Error) { +func (self *Bucket) PutLocalFile(id *aws.Signer, key, file string) (err error) { fp, err := os.Open(file) if err == nil { defer fp.Close() @@ -86,14 +87,14 @@ func (self *Bucket) PutLocalFile(id *aws.Signer, key, file string) (err os.Error // Will put an open file descriptor to the named key. Size is determined // by statting the fd (so a partially read file will not work). // TODO: ACL's & content-type/headers support -func (self *Bucket) PutFile(id *aws.Signer, key string, fp *os.File) (err os.Error) { +func (self *Bucket) PutFile(id *aws.Signer, key string, fp *os.File) (err error) { var resp *http.Response if fp == nil { - return os.NewError("invalid file descriptor") + return errors.New("invalid file descriptor") } fi, err := fp.Stat() if err == nil { - fsize := fi.Size + fsize := fi.Size() hdr := http.Header{} hreq := aws.NewRequest(self.key_url(key), "PUT", hdr, nil) hreq.ContentLength = fsize @@ -110,8 +111,7 @@ func (self *Bucket) PutFile(id *aws.Signer, key string, fp *os.File) (err os.Err return } - -func (self *Bucket) PutKeyBytes(id *aws.Signer, key string, buff []byte, hdr http.Header) (err os.Error) { +func (self *Bucket) PutKeyBytes(id *aws.Signer, key string, buff []byte, hdr http.Header) (err error) { var resp *http.Response hreq := aws.NewRequest(self.key_url(key), "PUT", hdr, nil) hreq.ContentLength = int64(len(buff)) @@ -130,7 +130,7 @@ func (self *Bucket) PutKeyBytes(id *aws.Signer, key string, buff []byte, hdr htt // NB: Length is required as we do not buffer the reader // NB(2): We do NOT close your reader (hence the io.Reader), // we wrap it with a NopCloser. -func (self *Bucket) PutKeyReader(id *aws.Signer, key string, r io.Reader, l int64, hdr http.Header) (err os.Error) { +func (self *Bucket) PutKeyReader(id *aws.Signer, key string, r io.Reader, l int64, hdr http.Header) (err error) { var resp *http.Response hreq := aws.NewRequest(self.key_url(key), "PUT", hdr, nil) hreq.ContentLength = l @@ -143,7 +143,7 @@ func (self *Bucket) PutKeyReader(id *aws.Signer, key string, r io.Reader, l int6 err = aws.CodeToError(resp.StatusCode) } if err == aws.ErrorUnexpectedResponse { - ob, _ := http.DumpResponse(resp, true) + ob, _ := httputil.DumpResponse(resp, true) os.Stdout.Write(ob) } } @@ -151,10 +151,10 @@ func (self *Bucket) PutKeyReader(id *aws.Signer, key string, r io.Reader, l int6 } // Deletes the named key from the bucket. To delete a bucket, see *Service.DeleteBucket() -func (self *Bucket) Delete(id *aws.Signer, key string) (err os.Error) { +func (self *Bucket) Delete(id *aws.Signer, key string) (err error) { var resp *http.Response if key == "" { - return os.NewError("Key cannot be empty!") + return errors.New("Key cannot be empty!") } hreq := aws.NewRequest(self.key_url(key), "DELETE", nil, nil) err = id.SignRequestV1(hreq, aws.CanonicalizeS3, 15) @@ -173,7 +173,7 @@ func (self *Bucket) Delete(id *aws.Signer, key string) (err os.Error) { // Opens the named key and copys it to the named io.Writer IFF the response.Status is 200. // Also returns the http headers for convenience (regardless of status code, as long as a resp is generated). -func (self *Bucket) GetKey(id *aws.Signer, key string, w io.Writer) (hdr http.Header, err os.Error) { +func (self *Bucket) GetKey(id *aws.Signer, key string, w io.Writer) (hdr http.Header, err error) { var resp *http.Response hreq := aws.NewRequest(self.key_url(key), "GET", nil, nil) err = id.SignRequestV1(hreq, aws.CanonicalizeS3, 15) @@ -196,14 +196,14 @@ func (self *Bucket) GetKey(id *aws.Signer, key string, w io.Writer) (hdr http.He // Performs a HEAD request on the bucket and returns nil of the key appears // valid (returns 200). -func (self *Bucket) Exists(id *aws.Signer, key string) (err os.Error) { +func (self *Bucket) Exists(id *aws.Signer, key string) (err error) { _, err = self.HeadKey(id, key) return } // Performs a HEAD request on the bucket and returns the response object. // The body is CLOSED, and it is an error to try and read from it. -func (self *Bucket) HeadKey(id *aws.Signer, key string) (resp *http.Response, err os.Error) { +func (self *Bucket) HeadKey(id *aws.Signer, key string) (resp *http.Response, err error) { hreq := aws.NewRequest(self.key_url(key), "HEAD", nil, nil) err = id.SignRequestV1(hreq, aws.CanonicalizeS3, 15) if err == nil { @@ -224,18 +224,20 @@ type owner struct { // Walks a bucket and writes the resulting strings to the channel. // * There is currently NO (correct) way to abort a running walk. func (self *Bucket) ListKeys(id *aws.Signer, -prefix, delim, marker string, out chan<- string) (err os.Error) { + prefix, delim, marker string, out chan<- string) (err error) { var done bool var resp *http.Response var last string - form := http.Values{"prefix": []string{prefix}, - "delimeter": []string{delim}, - "marker":[]string{marker}} + form := url.Values{"prefix": []string{prefix}, + "delimeter": []string{delim}, + "marker": []string{marker}} for err == nil && !done { result := listBucketResult{} result.Prefix = prefix result.Marker = marker - if last != "" {form.Set("marker", last) } + if last != "" { + form.Set("marker", last) + } hreq := aws.NewRequest(self.key_url("/"), "GET", nil, form) err = id.SignRequestV1(hreq, aws.CanonicalizeS3, 15) @@ -252,7 +254,7 @@ prefix, delim, marker string, out chan<- string) (err os.Error) { out <- result.Contents[i].Key } if len(result.Contents) > 0 { - last = result.Contents[len(result.Contents) - 1].Key + last = result.Contents[len(result.Contents)-1].Key } done = !result.IsTruncated } @@ -283,6 +285,6 @@ type keyItem struct { } // Closes the underlying connection -func (self *Bucket) Close() (err os.Error) { +func (self *Bucket) Close() (err error) { return self.conn.Close() } diff --git a/s3/consts.go b/s3/consts.go index cb24f29..06b24d4 100644 --- a/s3/consts.go +++ b/s3/consts.go @@ -4,7 +4,6 @@ import ( "crypto" ) - // Do S3 endpoints actually play any role? const ( USWEST_HOST = "us-west-1.s3.amazonaws.com" diff --git a/s3/service_opers.go b/s3/service_opers.go index 2e96eeb..66a87db 100644 --- a/s3/service_opers.go +++ b/s3/service_opers.go @@ -2,29 +2,29 @@ package s3 import ( "aws" + "net/url" ) import ( - "http" - "os" + "encoding/xml" + "net/http" "path" - "xml" ) type Service struct { - URL *http.URL + URL *url.URL conn *aws.Conn } // Initilalize a new Service object with a specific // S3 endpoint. If URL is omitted, it defaults to the // us-east endpoint over HTTPS (https://s3.amazonaws.com/) -func NewService(url *http.URL) (s *Service) { +func NewService(url_ *url.URL) (s *Service) { s = &Service{ - URL: url, + URL: url_, } if s.URL == nil { - s.URL, _ = http.ParseURL("https://" + USEAST_HOST + "/") + s.URL, _ = url.Parse("https://" + USEAST_HOST + "/") } s.conn = aws.NewConn(aws.URLDialer(s.URL, nil)) return @@ -45,8 +45,8 @@ func s3Path(bucket, key string) string { return path.Join("/", bucket, key) } -func (self *Service) bucket_url(bucket string) *http.URL { - return &http.URL{ +func (self *Service) bucket_url(bucket string) *url.URL { + return &url.URL{ Host: self.URL.Host, Path: path.Join(self.URL.Path, s3Path(bucket, "")), Scheme: self.URL.Scheme, @@ -54,7 +54,7 @@ func (self *Service) bucket_url(bucket string) *http.URL { } // Deletes the named bucket from the S3 service. -func (self *Service) DeleteBucket(id *aws.Signer, name string) (err os.Error) { +func (self *Service) DeleteBucket(id *aws.Signer, name string) (err error) { var resp *http.Response hreq := aws.NewRequest(self.bucket_url(name), "DELETE", nil, nil) err = id.SignRequestV1(hreq, aws.CanonicalizeS3, 15) @@ -76,7 +76,7 @@ func (self *Service) DeleteBucket(id *aws.Signer, name string) (err os.Error) { // Creates a new bucket // TODO: Will (probably) create the bucket in US-east no matter // what underlying endpoint you've chosen. -func (self *Service) CreateBucket(id *aws.Signer, name string) (err os.Error) { +func (self *Service) CreateBucket(id *aws.Signer, name string) (err error) { var resp *http.Response hreq := aws.NewRequest(self.bucket_url(name), "PUT", nil, nil) err = id.SignRequestV1(hreq, aws.CanonicalizeS3, 15) @@ -91,10 +91,9 @@ func (self *Service) CreateBucket(id *aws.Signer, name string) (err os.Error) { return } - // Returns a list of bucket names known by the endpoint. Depending on the // endpoint used, your list may be global or regional in nature. -func (self *Service) ListBuckets(id *aws.Signer) (out []string, err os.Error) { +func (self *Service) ListBuckets(id *aws.Signer) (out []string, err error) { var resp *http.Response hreq := aws.NewRequest(self.bucket_url(""), "GET", nil, nil) err = id.SignRequestV1(hreq, aws.CanonicalizeS3, 15) @@ -121,6 +120,6 @@ type listAllMyBucketsResult struct { } // Closes the underlying connection -func (self *Service) Close() (err os.Error) { +func (self *Service) Close() (err error) { return self.conn.Close() } diff --git a/s3/util/s3_main.go b/s3/util/s3_main.go index b6db931..3a85985 100644 --- a/s3/util/s3_main.go +++ b/s3/util/s3_main.go @@ -1,16 +1,17 @@ package s3_util import ( - "aws/s3" + "aws" . "aws/flags" + "aws/s3" . "aws/util/common" - "aws" + "errors" + "net/url" ) import ( "flag" "fmt" - "http" "os" "path" ) @@ -27,32 +28,31 @@ var signer *aws.Signer var service *s3.Service // Convenience method to clean up calls. -func DefaultS3Service() (id *aws.Signer, s *s3.Service, err os.Error) { +func DefaultS3Service() (id *aws.Signer, s *s3.Service, err error) { id, err = DefaultSigner() if err == nil { - url, err := http.ParseURL(flag_endpoint_url) + url_, err := url.Parse(flag_endpoint_url) if err == nil { - s = s3.NewService(url) + s = s3.NewService(url_) } } return } - func init() { AddModule("s3", func() { flag.StringVar(&flag_endpoint_url, "s3-endpoint", "https://s3.amazonaws.com/", "Endpoint to use for S3 calls") }) - Modules["s3"].Setup = func() (err os.Error) { + Modules["s3"].Setup = func() (err error) { signer, service, err = DefaultS3Service() return } // awstool.s3.ls - Modules["s3"].Calls["ls"] = func(args []string) (err os.Error) { + Modules["s3"].Calls["ls"] = func(args []string) (err error) { if len(args) != 1 { - return os.NewError("USAGE: ls BUCKET") + return errors.New("USAGE: ls BUCKET") } keys := make(chan string) go func() { @@ -68,9 +68,9 @@ func init() { } // awstool.s3.buckets - Modules["s3"].Calls["buckets"] = func(args []string) (err os.Error) { + Modules["s3"].Calls["buckets"] = func(args []string) (err error) { if len(args) != 0 { - return os.NewError("USAGE: buckets") + return errors.New("USAGE: buckets") } lb, err := service.ListBuckets(signer) if err == nil { @@ -81,16 +81,16 @@ func init() { return } - Modules["s3"].Calls["cat"] = func(args []string) (err os.Error) { + Modules["s3"].Calls["cat"] = func(args []string) (err error) { if len(args) != 2 { - return os.NewError("Usage: get BUCKET KEY") + return errors.New("Usage: get BUCKET KEY") } if err == nil { _, err = service.Bucket(args[0]).GetKey(signer, args[1], os.Stdout) } return } - Modules["s3"].Calls["exists"] = func(args []string) (err os.Error) { + Modules["s3"].Calls["exists"] = func(args []string) (err error) { if len(args) == 2 { fmt.Printf("Usage: exists BUCKET KEY\n") os.Exit(1) @@ -98,23 +98,23 @@ func init() { err = service.Bucket(args[0]).Exists(signer, args[1]) return } - Modules["s3"].Calls["drop"] = func(args []string) (err os.Error) { + Modules["s3"].Calls["drop"] = func(args []string) (err error) { if len(args) != 1 { - return os.NewError("Usage: drop BUCKET") + return errors.New("Usage: drop BUCKET") } err = service.DeleteBucket(signer, args[0]) return } - Modules["s3"].Calls["create"] = func(args []string) (err os.Error) { + Modules["s3"].Calls["create"] = func(args []string) (err error) { if len(args) != 1 { - return os.NewError("Usage: create BUCKET") + return errors.New("Usage: create BUCKET") } err = service.CreateBucket(signer, args[0]) return } - Modules["s3"].Calls["rm"] = func(args []string) (err os.Error) { + Modules["s3"].Calls["rm"] = func(args []string) (err error) { if len(args) < 2 { - return os.NewError("Usage: rm BUCKET KEY [KEY2...]") + return errors.New("Usage: rm BUCKET KEY [KEY2...]") } bucket := args[0] args = args[1:] @@ -126,9 +126,9 @@ func init() { } return } - Modules["s3"].Calls["put"] = func(args []string) (err os.Error) { + Modules["s3"].Calls["put"] = func(args []string) (err error) { if len(args) < 3 { - return os.NewError("Usage: put BUCKET PREFIX FILE [FILE2...]") + return errors.New("Usage: put BUCKET PREFIX FILE [FILE2...]") } bucket := args[0] prefix := args[1] diff --git a/samples/s3_proxy/config.go b/samples/s3_proxy/config.go index ab1351c..599ba57 100644 --- a/samples/s3_proxy/config.go +++ b/samples/s3_proxy/config.go @@ -1,16 +1,14 @@ package main import ( - . "aws/flags" "aws" + . "aws/flags" "aws/s3" + "errors" + "net/url" ) -import ( - "json" - "http" - "os" -) +import "encoding/json" type conf map[string]*proxyConf @@ -20,18 +18,18 @@ type proxyConf struct { Identity *aws.Signer } -func (self *proxyConf) UnmarshalJSON(in []byte) (err os.Error) { +func (self *proxyConf) UnmarshalJSON(in []byte) (err error) { confmap := map[string]string{} err = json.Unmarshal(in, &confmap) if err == nil { if _, ok := confmap["Bucket"]; !ok { - return os.NewError("Bucket is required") + return errors.New("Bucket is required") } self.Prefix = confmap["Prefix"] if self.Prefix == "" { self.Prefix = "/" } - self.Bucket = s3.NewBucket(&http.URL{ + self.Bucket = s3.NewBucket(&url.URL{ Scheme: "http", Host: "s3.amazonaws.com", Path: self.Prefix, diff --git a/samples/s3_proxy/main.go b/samples/s3_proxy/main.go index bfecebc..373eb4e 100644 --- a/samples/s3_proxy/main.go +++ b/samples/s3_proxy/main.go @@ -1,13 +1,13 @@ package main import ( - . "log" + "encoding/json" "flag" - "http" + . "log" "net" - "path" - "json" + "net/http" "os" + "path" "strconv" ) @@ -42,7 +42,7 @@ func (self Service) ServeHTTP(rw http.ResponseWriter, req *http.Request) { } // We're only copying the body in for 200's. if resp.ContentLength > 0 && err == nil { - rw.Header().Set("Content-Length", strconv.Itoa64(resp.ContentLength)) + rw.Header().Set("Content-Length", strconv.FormatInt(resp.ContentLength, 10)) } } outcode := http.StatusInternalServerError diff --git a/sdb/attribute.go b/sdb/attribute.go index 4771875..23c6800 100644 --- a/sdb/attribute.go +++ b/sdb/attribute.go @@ -1,7 +1,7 @@ package sdb import ( - "http" + "net/url" "strconv" ) @@ -26,8 +26,8 @@ const ( EXPECTED_LIST AttrListType = "Expected." ) -func (self AttributeList) Values(afix AttrListType) (v http.Values) { - v = http.Values{} +func (self AttributeList) Values(afix AttrListType) (v url.Values) { + v = url.Values{} for i := range self { prefix := string(afix) + strconv.Itoa(i+1) + "." v.Set(prefix+"Name", self[i].Name) @@ -52,7 +52,6 @@ func (self AttributeList) Values(afix AttrListType) (v http.Values) { return } - // miscelanious helper functions. func AttrMissing(name string) Attribute { f := false diff --git a/sdb/domain.go b/sdb/domain.go index 8d64e26..73e8695 100644 --- a/sdb/domain.go +++ b/sdb/domain.go @@ -2,17 +2,19 @@ package sdb import ( "aws" + "net/url" ) import ( + "encoding/xml" "fmt" - "http" + "net/http" + "net/http/httputil" "os" - "xml" ) type Domain struct { - URL *http.URL + URL *url.URL conn *aws.Conn Name string } @@ -20,8 +22,7 @@ type Domain struct { // if domain != "" { params["DomainName"] = domain } // params["Action"] = action - -func (self *Domain) DeleteAttribute(s *aws.Signer, item string, attrs, expected AttributeList) (err os.Error) { +func (self *Domain) DeleteAttribute(s *aws.Signer, item string, attrs, expected AttributeList) (err error) { var resp *http.Response vl := attrs.Values(ATTRIBUTE_LIST) @@ -46,7 +47,7 @@ func (self *Domain) DeleteAttribute(s *aws.Signer, item string, attrs, expected return } -func (self *Domain) GetAttribute(s *aws.Signer, item string, attrs AttributeList, consist bool) (a []Attribute, err os.Error) { +func (self *Domain) GetAttribute(s *aws.Signer, item string, attrs AttributeList, consist bool) (a []Attribute, err error) { var resp *http.Response vl := attrs.Values(ATTRIBUTE_LIST) @@ -70,7 +71,7 @@ func (self *Domain) GetAttribute(s *aws.Signer, item string, attrs AttributeList } if err == nil { var response getattributesresponse - ob, _ := http.DumpResponse(resp, true) + ob, _ := httputil.DumpResponse(resp, true) os.Stdout.Write(ob) err = xml.Unmarshal(resp.Body, &response) if err == nil { @@ -80,10 +81,10 @@ func (self *Domain) GetAttribute(s *aws.Signer, item string, attrs AttributeList return } -func (self *Domain) Select(id *aws.Signer, what, where string, consist bool, items chan<- Item) (err os.Error) { +func (self *Domain) Select(id *aws.Signer, what, where string, consist bool, items chan<- Item) (err error) { var resp *http.Response - vl := http.Values{} + vl := url.Values{} vl.Set("Action", "Select") if where != "" { @@ -107,7 +108,7 @@ func (self *Domain) Select(id *aws.Signer, what, where string, consist bool, ite resp, err = self.conn.Request(req) } if err == nil { - ob, _ := http.DumpResponse(resp, true) + ob, _ := httputil.DumpResponse(resp, true) os.Stdout.Write(ob) xresp := selectresponse{} err = xml.Unmarshal(resp.Body, &xresp) @@ -126,6 +127,6 @@ func (self *Domain) Select(id *aws.Signer, what, where string, consist bool, ite } // Closes the underlying connection -func (self *Domain) Close() (err os.Error) { +func (self *Domain) Close() (err error) { return self.conn.Close() } diff --git a/sdb/response.go b/sdb/response.go index bed14ba..d1a7a30 100644 --- a/sdb/response.go +++ b/sdb/response.go @@ -1,6 +1,5 @@ package sdb - type listdomainsresponse struct { Domains []string "ListDomainsResult>DomainName" NextToken string "ListDomainsResult>NextToken" @@ -10,7 +9,6 @@ type listdomainsresponse struct { ErrorCode string "Errors>Error>Code" } - type getattributesresponse struct { Attributes []Attribute "GetAttributesResult>Attribute" ErrorMessage string "Errors>Error>Message" diff --git a/sdb/service.go b/sdb/service.go index df582d4..9ae9c88 100644 --- a/sdb/service.go +++ b/sdb/service.go @@ -2,29 +2,32 @@ package sdb import ( "aws" + "errors" + "net/url" ) import ( - "http" + "encoding/xml" + "net/http" + "net/http/httputil" "os" - "xml" ) type Service struct { - URL *http.URL + URL *url.URL conn *aws.Conn } -func NewService(url *http.URL) *Service { +func NewService(url_ *url.URL) *Service { return &Service{ - URL: url, - conn: aws.NewConn(aws.URLDialer(url, nil)), + URL: url_, + conn: aws.NewConn(aws.URLDialer(url_, nil)), } } func (self *Service) Domain(name string) *Domain { return &Domain{ - URL: &http.URL{ + URL: &url.URL{ Scheme: self.URL.Scheme, Host: self.URL.Host, Path: self.URL.Path, @@ -34,9 +37,9 @@ func (self *Service) Domain(name string) *Domain { } } -func (self *Service) CreateDomain(id *aws.Signer, name string) (err os.Error) { +func (self *Service) CreateDomain(id *aws.Signer, name string) (err error) { var resp *http.Response - parms := http.Values{} + parms := url.Values{} parms.Set("DomainName", name) parms.Set("Action", "CreateDomain") req := aws.NewRequest(self.URL, "GET", nil, parms) @@ -46,15 +49,15 @@ func (self *Service) CreateDomain(id *aws.Signer, name string) (err os.Error) { } if err == nil { if resp.StatusCode != http.StatusOK { - err = os.NewError("Unexpected response") + err = errors.New("Unexpected response") } } return } -func (self *Service) DestroyDomain(id *aws.Signer, name string) (err os.Error) { +func (self *Service) DestroyDomain(id *aws.Signer, name string) (err error) { var resp *http.Response - parms := http.Values{} + parms := url.Values{} parms.Set("DomainName", name) parms.Set("Action", "DeleteDomain") req := aws.NewRequest(self.URL, "GET", nil, parms) @@ -69,15 +72,15 @@ func (self *Service) DestroyDomain(id *aws.Signer, name string) (err os.Error) { } if err == nil { if resp.StatusCode != http.StatusOK { - err = os.NewError("Unexpected response") + err = errors.New("Unexpected response") } } return } -func (self *Service) ListDomains(id *aws.Signer) (out []string, err os.Error) { +func (self *Service) ListDomains(id *aws.Signer) (out []string, err error) { var resp *http.Response - parms := http.Values{} + parms := url.Values{} parms.Set("Action", "ListDomains") parms.Set("MaxNumberOfDomains", "100") var done bool @@ -102,15 +105,15 @@ func (self *Service) ListDomains(id *aws.Signer) (out []string, err os.Error) { if err == nil { defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - err = os.NewError("Unexpected response") - ob, _ := http.DumpResponse(resp, true) + err = errors.New("Unexpected response") + ob, _ := httputil.DumpResponse(resp, true) os.Stdout.Write(ob) } if err == nil { err = xml.Unmarshal(resp.Body, &xmlresp) if err == nil { if xmlresp.ErrorCode != "" { - err = os.NewError(xmlresp.ErrorCode) + err = errors.New(xmlresp.ErrorCode) } if err == nil { for d := range xmlresp.Domains { @@ -127,6 +130,6 @@ func (self *Service) ListDomains(id *aws.Signer) (out []string, err os.Error) { } // Closes the underlying connection -func (self *Service) Close() (err os.Error) { +func (self *Service) Close() (err error) { return self.conn.Close() } diff --git a/sdb/util/sdb_main.go b/sdb/util/sdb_main.go index ee57988..52c6482 100644 --- a/sdb/util/sdb_main.go +++ b/sdb/util/sdb_main.go @@ -1,29 +1,29 @@ package sdb_util import ( - . "aws/flags" - . "aws/util/common" "aws" + . "aws/flags" "aws/sdb" + . "aws/util/common" + "errors" + "net/url" ) import ( "flag" "fmt" - "http" - "os" ) var flag_endpoint_url string var id *aws.Signer var service *sdb.Service -func DefaultSDBService() (id *aws.Signer, s *sdb.Service, err os.Error) { +func DefaultSDBService() (id *aws.Signer, s *sdb.Service, err error) { id, err = DefaultSigner() if err == nil { - url, err := http.ParseURL(flag_endpoint_url) + url_, err := url.Parse(flag_endpoint_url) if err == nil { - s = sdb.NewService(url) + s = sdb.NewService(url_) } } return @@ -34,13 +34,13 @@ func init() { flag.StringVar(&flag_endpoint_url, "sdb-endpoint", "https://sdb.amazonaws.com/", "Endpoint to use for S3 calls") }) - Modules["sdb"].Setup = func() (err os.Error) { + Modules["sdb"].Setup = func() (err error) { id, service, err = DefaultSDBService() return } - Modules["sdb"].Calls["rm"] = func(args []string) (err os.Error) { + Modules["sdb"].Calls["rm"] = func(args []string) (err error) { if len(args) < 2 { - return os.NewError("Usage: rm domain_name item [...]") + return errors.New("Usage: rm domain_name item [...]") } d := service.Domain(args[0]) args = args[1:] @@ -53,9 +53,9 @@ func init() { return } - Modules["sdb"].Calls["get"] = func(args []string) (err os.Error) { + Modules["sdb"].Calls["get"] = func(args []string) (err error) { if len(args) < 2 { - return os.NewError("Usage: get domain_name item [...]") + return errors.New("Usage: get domain_name item [...]") } d := service.Domain(args[0]) args = args[1:] @@ -69,23 +69,23 @@ func init() { } return } - Modules["sdb"].Calls["create"] = func(args []string) (err os.Error) { + Modules["sdb"].Calls["create"] = func(args []string) (err error) { if len(args) != 1 { - return os.NewError("Usage: create domain_name") + return errors.New("Usage: create domain_name") } err = service.CreateDomain(id, args[0]) return } - Modules["sdb"].Calls["drop"] = func(args []string) (err os.Error) { + Modules["sdb"].Calls["drop"] = func(args []string) (err error) { if len(args) != 0 { - return os.NewError("Usage: drop domain_name") + return errors.New("Usage: drop domain_name") } err = service.DestroyDomain(id, args[0]) return } - Modules["sdb"].Calls["select"] = func(args []string) (err os.Error) { + Modules["sdb"].Calls["select"] = func(args []string) (err error) { if len(args) < 2 || len(args) > 3 { - return os.NewError("Usage: service.lect ('*'|col,col2,...) domain_name [extended expression]") + return errors.New("Usage: service.lect ('*'|col,col2,...) domain_name [extended expression]") } colstr := args[0] d := service.Domain(args[1]) @@ -107,7 +107,7 @@ func init() { return } - Modules["sdb"].Calls["domains"] = func(args []string) (err os.Error) { + Modules["sdb"].Calls["domains"] = func(args []string) (err error) { doms, err := service.ListDomains(id) for i := range doms { fmt.Printf("%s\n", doms[i]) diff --git a/signer.go b/signer.go index a1ba19a..ee90ba4 100644 --- a/signer.go +++ b/signer.go @@ -5,12 +5,13 @@ import ( "crypto" "crypto/hmac" "encoding/base64" + "errors" "hash" - "http" - "os" + "net/http" + "net/url" + "strconv" "strings" - "strconv" - "time" + "time" ) // A signer simply holds the access & secret access keys @@ -26,19 +27,19 @@ func NewSigner(akid, sak string) *Signer { } // the core function of the Signer, generates the raw hmac of he bytes. -func (self *Signer) SignBytes(h crypto.Hash, buff []byte) (sig []byte, err os.Error) { +func (self *Signer) SignBytes(h crypto.Hash, buff []byte) (sig []byte, err error) { hh := hmac.New(func() hash.Hash { return h.New() }, self.secretAccessKey) _, err = hh.Write(buff) if err == nil { - sig = hh.Sum() + sig = hh.Sum(nil) } return } // Same as SignBytes, but with strings. -func (self *Signer) SignString(h crypto.Hash, s string) (os string, err os.Error) { +func (self *Signer) SignString(h crypto.Hash, s string) (os string, err error) { ob, err := self.SignBytes(h, bytes.NewBufferString(s).Bytes()) if err == nil { os = string(ob) @@ -47,7 +48,7 @@ func (self *Signer) SignString(h crypto.Hash, s string) (os string, err os.Error } // SignBytes, but will base64 encode based on the specified encoder. -func (self *Signer) SignEncoded(h crypto.Hash, s string, e *base64.Encoding) (out []byte, err os.Error) { +func (self *Signer) SignEncoded(h crypto.Hash, s string, e *base64.Encoding) (out []byte, err error) { ob, err := self.SignBytes(h, bytes.NewBufferString(s).Bytes()) if err == nil { out = make([]byte, e.EncodedLen(len(ob))) @@ -62,30 +63,34 @@ func (self *Signer) SignEncoded(h crypto.Hash, s string, e *base64.Encoding) (ou // so it is recommended you use this function. // // Final note: if exp is set to 0, a Timestamp will be used, otherwise an expiration. -func (self *Signer) SignRequestV2(req *http.Request, canon func(*http.Request)(string, os.Error), api_ver string, exp int64) (err os.Error) { +func (self *Signer) SignRequestV2(req *http.Request, canon func(*http.Request) (string, error), api_ver string, exp int64) (err error) { // log.Printf("Signing request...") - qstring, err := http.ParseQuery(req.URL.RawQuery) - if err != nil { return } - qstring["SignatureVersion"] = []string{DEFAULT_SIGNATURE_VERSION} - if _, ok := qstring["SignatureMethod"]; !ok || len(qstring["SignatureMethod"]) == 0 { - qstring["SignatureMethod"] = []string{DEFAULT_SIGNATURE_METHOD} - } - qstring["Version"] = []string{api_ver} - - if exp > 0 { - qstring["Expires"] = []string{strconv.Itoa64(time.Seconds()+exp)} - } else { - qstring["Timestamp"] = []string{time.UTC().Format(ISO8601TimestampFormat)} - } - qstring["Signature"] = nil, false - qstring["AWSAccessKeyId"] = []string{ self.AccessKey} + qstring, err := url.ParseQuery(req.URL.RawQuery) + if err != nil { + return + } + qstring["SignatureVersion"] = []string{DEFAULT_SIGNATURE_VERSION} + if _, ok := qstring["SignatureMethod"]; !ok || len(qstring["SignatureMethod"]) == 0 { + qstring["SignatureMethod"] = []string{DEFAULT_SIGNATURE_METHOD} + } + qstring["Version"] = []string{api_ver} + + if exp > 0 { + qstring["Expires"] = []string{strconv.FormatInt(time.Now()+exp, 10)} + } else { + qstring["Timestamp"] = []string{time.Now().UTC().Format(ISO8601TimestampFormat)} + } + delete(qstring, "Signature") + qstring["AWSAccessKeyId"] = []string{self.AccessKey} var sig []byte - req.URL.RawQuery = http.Values(qstring).Encode() - can, err := canon(req) - if err != nil { return } - //log.Printf("String-to-sign: '%s'", can) + req.URL.RawQuery = url.Values(qstring).Encode() + can, err := canon(req) + if err != nil { + return + } + //log.Printf("String-to-sign: '%s'", can) switch qstring["SignatureMethod"][0] { case "HmacSHA256": @@ -93,42 +98,44 @@ func (self *Signer) SignRequestV2(req *http.Request, canon func(*http.Request)(s case "HmacSHA1": sig, err = self.SignEncoded(crypto.SHA1, can, base64.StdEncoding) default: - err = os.NewError("Unknown SignatureMethod:" + req.Form.Get("SignatureMethod")) + err = errors.New("Unknown SignatureMethod:" + req.Form.Get("SignatureMethod")) } if err == nil { - req.URL.RawQuery += "&" + http.Values{"Signature": []string{string(sig)}}.Encode() + req.URL.RawQuery += "&" + url.Values{"Signature": []string{string(sig)}}.Encode() } return } // Used exclusively by S3 to the best of my knowledge... -func (self *Signer) SignRequestV1(req *http.Request, canon func(*http.Request) (string, os.Error), exp int64) (err os.Error) { - qstring, err := http.ParseQuery(req.URL.RawQuery) - - if err != nil { return } - - if exp > 0 { - qstring["Expires"] = []string{strconv.Itoa64(time.Seconds()+exp)} - } else { - qstring["Timestamp"] = []string{time.UTC().Format(ISO8601TimestampFormat)} - } - qstring["Signature"] = nil, false - qstring["AWSAccessKeyId"] = []string{ self.AccessKey} +func (self *Signer) SignRequestV1(req *http.Request, canon func(*http.Request) (string, error), exp int64) (err error) { + qstring, err := url.ParseQuery(req.URL.RawQuery) + if err != nil { + return + } - req.URL.RawQuery = http.Values(qstring).Encode() + if exp > 0 { + qstring["Expires"] = []string{strconv.FormatInt(time.Now()+exp, 10)} + } else { + qstring["Timestamp"] = []string{time.Now().UTC().Format(ISO8601TimestampFormat)} + } + delete(qstring, "Signature") + qstring["AWSAccessKeyId"] = []string{self.AccessKey} + req.URL.RawQuery = url.Values(qstring).Encode() - can, err := canon(req) - if err != nil { return } + can, err := canon(req) + if err != nil { + return + } var sig []byte sig, err = self.SignEncoded(crypto.SHA1, can, base64.StdEncoding) if err == nil { - req.URL.RawQuery += "&" + http.Values{"Signature": []string{string(sig)}}.Encode() + req.URL.RawQuery += "&" + url.Values{"Signature": []string{string(sig)}}.Encode() } return @@ -136,20 +143,20 @@ func (self *Signer) SignRequestV1(req *http.Request, canon func(*http.Request) ( // Generates the canonical string-to-sign for (most) AWS services. // You shouldn't need to use this directly. -func Canonicalize(req *http.Request) (out string, err os.Error) { - fv, err := http.ParseQuery(req.URL.RawQuery) - if err == nil { - out = strings.Join([]string{req.Method, req.Host, req.URL.Path, SortedEscape(fv)}, "\n") - } - return +func Canonicalize(req *http.Request) (out string, err error) { + fv, err := url.ParseQuery(req.URL.RawQuery) + if err == nil { + out = strings.Join([]string{req.Method, req.Host, req.URL.Path, SortedEscape(fv)}, "\n") + } + return } // Generates the canonical string-to-sign for S3 services. // You shouldn't need to use this directly unless you're pre-signing URL's. -func CanonicalizeS3(req *http.Request) (out string, err os.Error ){ - fv, err := http.ParseQuery(req.URL.RawQuery) - if err == nil || len(fv["Expires"]) != 1 { - out = strings.Join([]string{req.Method, req.Header.Get("Content-Md5"), req.Header.Get("Content-Type"), fv["Expires"][0], req.URL.Path}, "\n") - } - return +func CanonicalizeS3(req *http.Request) (out string, err error) { + fv, err := url.ParseQuery(req.URL.RawQuery) + if err == nil || len(fv["Expires"]) != 1 { + out = strings.Join([]string{req.Method, req.Header.Get("Content-Md5"), req.Header.Get("Content-Type"), fv["Expires"][0], req.URL.Path}, "\n") + } + return } diff --git a/sqs/consts.go b/sqs/consts.go index e7c63da..3b1419d 100644 --- a/sqs/consts.go +++ b/sqs/consts.go @@ -1,6 +1,5 @@ package sqs - const ( DEFAULT_VERSION = "2009-02-01" ) diff --git a/sqs/queue.go b/sqs/queue.go index 83798bc..7a8fc41 100644 --- a/sqs/queue.go +++ b/sqs/queue.go @@ -2,30 +2,31 @@ package sqs import ( "aws" + "errors" + "net/url" ) import ( - "http" - "os" + "encoding/xml" + "net/http" "strconv" - "xml" ) type Queue struct { - URL *http.URL + URL *url.URL conn *aws.Conn } -func NewQueue(url *http.URL) *Queue { +func NewQueue(url_ *url.URL) *Queue { return &Queue{ - URL: url, - conn: aws.NewConn(aws.URLDialer(url, nil)), + URL: url_, + conn: aws.NewConn(aws.URLDialer(url_, nil)), } } -func (self *Queue) DeleteQueue(id *aws.Signer) (err os.Error) { +func (self *Queue) DeleteQueue(id *aws.Signer) (err error) { var resp *http.Response - parms := http.Values{} + parms := url.Values{} parms.Set("Action", "DeleteQueue") req := aws.NewRequest(self.URL, "GET", nil, parms) @@ -35,7 +36,7 @@ func (self *Queue) DeleteQueue(id *aws.Signer) (err os.Error) { if err == nil { defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - err = os.NewError("Unexpected response") + err = errors.New("Unexpected response") } } } @@ -43,9 +44,9 @@ func (self *Queue) DeleteQueue(id *aws.Signer) (err os.Error) { return } -func (self *Queue) Push(id *aws.Signer, body []byte) (err os.Error) { +func (self *Queue) Push(id *aws.Signer, body []byte) (err error) { var resp *http.Response - parms := http.Values{} + parms := url.Values{} parms.Set("Action", "SendMessage") parms.Set("MessageBody", string(body)) req := aws.NewRequest(self.URL, "GET", nil, parms) @@ -55,7 +56,7 @@ func (self *Queue) Push(id *aws.Signer, body []byte) (err os.Error) { if err == nil { defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - err = os.NewError("Unexpected response") + err = errors.New("Unexpected response") } } } @@ -63,9 +64,9 @@ func (self *Queue) Push(id *aws.Signer, body []byte) (err os.Error) { } // Note: 0 is a valid timeout!! -func (self *Queue) Peek(id *aws.Signer, vt int) (body []byte, msgid string, err os.Error) { +func (self *Queue) Peek(id *aws.Signer, vt int) (body []byte, msgid string, err error) { var resp *http.Response - parms := http.Values{} + parms := url.Values{} parms.Set("Action", "ReceiveMessage") if vt >= 0 { parms.Set("VisibilityTimeout", strconv.Itoa(vt)) @@ -78,7 +79,7 @@ func (self *Queue) Peek(id *aws.Signer, vt int) (body []byte, msgid string, err defer resp.Body.Close() } if err == nil && resp.StatusCode != http.StatusOK { - err = os.NewError("Unexpected response") + err = errors.New("Unexpected response") } if err == nil { msg := message{} @@ -92,9 +93,9 @@ func (self *Queue) Peek(id *aws.Signer, vt int) (body []byte, msgid string, err } // Note: 0 is a valid timeout!! -func (self *Queue) Delete(id *aws.Signer, mid string) (err os.Error) { +func (self *Queue) Delete(id *aws.Signer, mid string) (err error) { var resp *http.Response - parms := http.Values{} + parms := url.Values{} parms.Set("Action", "DeleteMessage") parms.Set("ReceiptHandle", mid) req := aws.NewRequest(self.URL, "GET", nil, parms) @@ -105,7 +106,7 @@ func (self *Queue) Delete(id *aws.Signer, mid string) (err os.Error) { defer resp.Body.Close() } if resp.StatusCode != http.StatusOK { - err = os.NewError("Unexpected response") + err = errors.New("Unexpected response") } } return @@ -119,6 +120,6 @@ type message struct { } // Closes the underlying connection -func (self *Queue) Close() (err os.Error) { +func (self *Queue) Close() (err error) { return self.conn.Close() } diff --git a/sqs/service.go b/sqs/service.go index 519e9fa..b58b5fc 100644 --- a/sqs/service.go +++ b/sqs/service.go @@ -2,14 +2,15 @@ package sqs import ( "aws" + "errors" + "net/url" ) import ( "crypto" - "http" - "os" + "encoding/xml" + "net/http" "strconv" - "xml" ) const ( @@ -18,20 +19,20 @@ const ( ) type Service struct { - URL *http.URL + URL *url.URL conn *aws.Conn } -func NewService(url *http.URL) *Service { +func NewService(url_ *url.URL) *Service { return &Service{ - URL: url, - conn: aws.NewConn(aws.URLDialer(url, nil)), + URL: url_, + conn: aws.NewConn(aws.URLDialer(url_, nil)), } } -func (self *Service) ListQueues(id *aws.Signer, prefix string) (mq []string, err os.Error) { +func (self *Service) ListQueues(id *aws.Signer, prefix string) (mq []string, err error) { var resp *http.Response - parms := http.Values{} + parms := url.Values{} parms.Set("Action", "ListQueues") if prefix != "" { parms.Set("QueueNamePrefix", prefix) @@ -46,7 +47,7 @@ func (self *Service) ListQueues(id *aws.Signer, prefix string) (mq []string, err if resp.StatusCode == http.StatusOK { err = xml.Unmarshal(resp.Body, &xresp) } else { - err = os.NewError("Unexpected response code") + err = errors.New("Unexpected response code") } if err == nil { mq = xresp.QueueURL @@ -57,9 +58,9 @@ func (self *Service) ListQueues(id *aws.Signer, prefix string) (mq []string, err } // Create a queue, returning the Queue object. -func (self *Service) CreateQueue(id *aws.Signer, name string, dvtimeout int) (mq *Queue, err os.Error) { +func (self *Service) CreateQueue(id *aws.Signer, name string, dvtimeout int) (mq *Queue, err error) { var resp *http.Response - parms := http.Values{} + parms := url.Values{} parms.Set("Action", "CreateQueue") parms.Set("QueueName", name) parms.Set("DefaultVisibilityTimeout", strconv.Itoa(dvtimeout)) @@ -74,14 +75,14 @@ func (self *Service) CreateQueue(id *aws.Signer, name string, dvtimeout int) (mq xmlresp := createQueueResponse{} err = xml.Unmarshal(resp.Body, &xmlresp) if err == nil { - var qrl *http.URL - qrl, err = http.ParseURL(xmlresp.QueueURL) + var qrl *url.URL + qrl, err = url.Parse(xmlresp.QueueURL) if err == nil { mq = NewQueue(qrl) } } } else { - err = os.NewError("Unexpected response") + err = errors.New("Unexpected response") } } } @@ -100,6 +101,6 @@ type listQueuesResponse struct { } // Closes the underlying connection -func (self *Service) Close() (err os.Error) { +func (self *Service) Close() (err error) { return self.conn.Close() } diff --git a/sqs/util/sqs_main.go b/sqs/util/sqs_main.go index 49aa872..8646ee0 100644 --- a/sqs/util/sqs_main.go +++ b/sqs/util/sqs_main.go @@ -1,16 +1,17 @@ package sqs_util import ( - . "aws/flags" - . "aws/util/common" "aws" + . "aws/flags" "aws/sqs" + . "aws/util/common" + "errors" + "net/url" ) import ( "flag" "fmt" - "http" "io" "os" ) @@ -22,31 +23,30 @@ var flag_pop_timeout int var signer *aws.Signer var s *sqs.Service -func DefaultSQSService() (id *aws.Signer, s *sqs.Service, err os.Error) { +func DefaultSQSService() (id *aws.Signer, s *sqs.Service, err error) { id, err = DefaultSigner() if err == nil { - url, err := http.ParseURL(flag_endpoint_url) + url_, err := url.Parse(flag_endpoint_url) if err == nil { - s = sqs.NewService(url) + s = sqs.NewService(url_) } } return } - func init() { AddModule("sqs", func() { flag.StringVar(&flag_endpoint_url, "sqs-endpoint", "https://queue.amazonaws.com/", "Endpoint to use") flag.IntVar(&flag_default_timeout, "sqs-queue-timeout", 90, "Queue timeout (create/delete)") flag.IntVar(&flag_pop_timeout, "sqs-message-timeout", 90, "Queue timeout (pop/peek)") }) - Modules["sqs"].Setup = func() (err os.Error) { + Modules["sqs"].Setup = func() (err error) { signer, s, err = DefaultSQSService() return } - Modules["sqs"].Calls["create"] = func(args []string) (err os.Error) { + Modules["sqs"].Calls["create"] = func(args []string) (err error) { if len(args) != 1 { - return os.NewError("Usage: create QUEUE") + return errors.New("Usage: create QUEUE") } Q, err := s.CreateQueue(signer, args[0], flag_default_timeout) if err == nil { @@ -55,9 +55,9 @@ func init() { return } - Modules["sqs"].Calls["list"] = func(args []string) (err os.Error) { + Modules["sqs"].Calls["list"] = func(args []string) (err error) { if len(args) != 0 { - return os.NewError("Usage: list") + return errors.New("Usage: list") } qs, err := s.ListQueues(signer, "") if err == nil { @@ -68,9 +68,9 @@ func init() { return } - Modules["sqs"].Calls["drop"] = func(args []string) (err os.Error) { + Modules["sqs"].Calls["drop"] = func(args []string) (err error) { if len(args) != 1 { - return os.NewError("Usage: drop queue") + return errors.New("Usage: drop queue") } Q, err := s.CreateQueue(signer, args[0], flag_default_timeout) if err == nil { @@ -79,9 +79,9 @@ func init() { return } - Modules["sqs"].Calls["push"] = func(args []string) (err os.Error) { + Modules["sqs"].Calls["push"] = func(args []string) (err error) { if len(args) != 1 { - return os.NewError("Usage: push queuename") + return errors.New("Usage: push queuename") } Q, err := s.CreateQueue(signer, args[0], flag_default_timeout) if err == nil { @@ -96,9 +96,9 @@ func init() { } return } - Modules["sqs"].Calls["rm"] = func(args []string) (err os.Error) { + Modules["sqs"].Calls["rm"] = func(args []string) (err error) { if len(args) != 2 { - return os.NewError("Usage: rm queuename receipthandle") + return errors.New("Usage: rm queuename receipthandle") } Q, err := s.CreateQueue(signer, args[0], flag_default_timeout) if err == nil { @@ -106,9 +106,9 @@ func init() { } return } - Modules["sqs"].Calls["peek"] = func(args []string) (err os.Error) { + Modules["sqs"].Calls["peek"] = func(args []string) (err error) { if len(args) != 1 { - return os.NewError("Usage: peek queuename") + return errors.New("Usage: peek queuename") } Q, err := s.CreateQueue(signer, args[0], flag_default_timeout) var body []byte diff --git a/util/common/common.go b/util/common/common.go index 1ef4b97..54df7f9 100644 --- a/util/common/common.go +++ b/util/common/common.go @@ -1,12 +1,8 @@ package common -import ( - "os" -) - type FunctionModule struct { FlagFunc func() - Setup func() os.Error + Setup func() error Calls map[string]UserCall } @@ -34,8 +30,7 @@ func AddModule(mod string, ffunc func()) { // Common functionality to ease sub-modules -type UserCall func([]string) os.Error - +type UserCall func([]string) error func init() { Modules = make(map[string]*FunctionModule) diff --git a/util/main.go b/util/main.go index a1ee292..a741c54 100644 --- a/util/main.go +++ b/util/main.go @@ -1,19 +1,20 @@ package main import ( - . "aws/util/common" // AWS ID Flags - . "aws/flags" // AWS ID Flags "aws/ec2/ec2_util" "aws/elb/elb_util" + . "aws/flags" // AWS ID Flags "aws/s3/s3_util" - "aws/sqs/sqs_util" "aws/sdb/sdb_util" + "aws/sqs/sqs_util" + . "aws/util/common" + "errors" // AWS ID Flags ) import ( "flag" - "os" "fmt" + "os" ) func keys(in map[string]interface{}) (out []string) { @@ -32,7 +33,7 @@ func main() { module := flag.Arg(0) cmd := flag.Arg(1) os.Args = os.Args[2:] - var err os.Error + var err error modulenames := []string{} for k, _ := range Modules { modulenames = append(modulenames, k) @@ -46,11 +47,11 @@ func main() { err = c(flag.Args()) } } else { - err = os.NewError(fmt.Sprintf("Invalid subcommand: %s, expected one of %v", + err = errors.New(fmt.Sprintf("Invalid subcommand: %s, expected one of %v", cmd, m.Names())) } } else { - err = os.NewError(fmt.Sprintf("Invalid modulle : %s, expected one of %v", + err = errors.New(fmt.Sprintf("Invalid modulle : %s, expected one of %v", flag.Arg(0), modulenames)) } From b36e686caee86a7c09b06f609dbacafc2c863754 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 4 Jan 2013 22:42:24 +0000 Subject: [PATCH 2/6] Convert Timeouts into Deadlines for Go 1.0 change --- dialer.go | 65 +++++++++++++++++++++++++------------------------------ 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/dialer.go b/dialer.go index 9805a70..5689141 100644 --- a/dialer.go +++ b/dialer.go @@ -4,6 +4,7 @@ import ( "errors" "net" "sync" + "time" // "log" ) @@ -25,25 +26,19 @@ type Dialer func() (net.Conn, error) // up, and trigger closure of the underlying socket (to // be reopened on the next call) type ReusableConn struct { - lock *sync.Mutex - dialer Dialer - conn net.Conn - readTimeout int64 - writeTimeout int64 + lock *sync.Mutex + dialer Dialer + conn net.Conn + readDeadline time.Time + writeDeadline time.Time } -const ( - _UNSET_TIMEOUT int64 = -1 -) - // Create a new reusable connection with a sepcific dialer. func NewReusableConnection(d Dialer) (c *ReusableConn) { return &ReusableConn{ - dialer: d, - conn: nil, - lock: &sync.Mutex{}, - readTimeout: _UNSET_TIMEOUT, - writeTimeout: _UNSET_TIMEOUT, + dialer: d, + conn: nil, + lock: &sync.Mutex{}, } } @@ -56,18 +51,18 @@ func (self *ReusableConn) Dial() (err error) { } // Dial will redial if conn is nil, and set -// timeouts if they've been set by the caller. +// deadlines if they've been set by the caller. // // It simply returns nil if the socket appears already connected func (self *ReusableConn) dial() (err error) { // log.Printf("Private dial() called (%v)", self.conn) if self.conn == nil { self.conn, err = self.dialer() - if err == nil && self.readTimeout != _UNSET_TIMEOUT { - err = self.setReadTimeout(self.readTimeout) + if err == nil && !self.readDeadline.IsZero() { + err = self.setReadDeadline(self.readDeadline) } - if err == nil && self.writeTimeout != _UNSET_TIMEOUT { - err = self.setWriteTimeout(self.writeTimeout) + if err == nil && !self.writeDeadline.IsZero() { + err = self.setWriteDeadline(self.writeDeadline) } } // log.Printf("Private dial() complete (%v)", self.conn) @@ -149,49 +144,49 @@ func (self *ReusableConn) Write(out []byte) (n int, err error) { return self.write(out) } -func (self *ReusableConn) setReadTimeout(t int64) (err error) { +func (self *ReusableConn) setReadDeadline(t time.Time) (err error) { err = self.dial() if err == nil { - err = self.conn.SetReadTimeout(t) + err = self.conn.SetReadDeadline(t) if err == nil { - self.readTimeout = t + self.readDeadline = t } } return } -func (self *ReusableConn) setWriteTimeout(t int64) (err error) { +func (self *ReusableConn) setWriteDeadline(t time.Time) (err error) { err = self.dial() if err == nil { - err = self.conn.SetWriteTimeout(t) + err = self.conn.SetWriteDeadline(t) if err == nil { - self.writeTimeout = t + self.writeDeadline = t } } return } -// Sets the read timeout on the underlying socket, as well +// Sets the read deadline on the underlying socket, as well // as an internal flag for any future re-opened connections. -func (self *ReusableConn) SetReadTimeout(t int64) (err error) { +func (self *ReusableConn) SetReadDeadline(t time.Time) (err error) { self.lock.Lock() defer self.lock.Unlock() - return self.setReadTimeout(t) + return self.setReadDeadline(t) } -// Sets the write timeout on the underlying socket, as well +// Sets the write deadline on the underlying socket, as well // as an internal flag for any future re-opened connections. -func (self *ReusableConn) SetWriteTimeout(t int64) (err error) { +func (self *ReusableConn) SetWriteDeadline(t time.Time) (err error) { self.lock.Lock() defer self.lock.Unlock() - return self.setWriteTimeout(t) + return self.setWriteDeadline(t) } -// Conveinience function for Set(read|write)timeout -func (self *ReusableConn) SetTimeout(t int64) (err error) { - err = self.SetReadTimeout(t) +// Convenience function for Set(Read|Write)Deadline +func (self *ReusableConn) SetDeadline(t time.Time) (err error) { + err = self.SetReadDeadline(t) if err == nil { - err = self.SetWriteTimeout(t) + err = self.SetWriteDeadline(t) } return } From 860ac5e9bfad8a9276b841291bc9e9283eb63bb8 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 4 Jan 2013 22:44:29 +0000 Subject: [PATCH 3/6] Fix types mismatch - time.Time isn't an int64 any more --- signer.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/signer.go b/signer.go index ee90ba4..e293730 100644 --- a/signer.go +++ b/signer.go @@ -77,7 +77,7 @@ func (self *Signer) SignRequestV2(req *http.Request, canon func(*http.Request) ( qstring["Version"] = []string{api_ver} if exp > 0 { - qstring["Expires"] = []string{strconv.FormatInt(time.Now()+exp, 10)} + qstring["Expires"] = []string{strconv.FormatInt(time.Now().Unix()+exp, 10)} } else { qstring["Timestamp"] = []string{time.Now().UTC().Format(ISO8601TimestampFormat)} } @@ -117,7 +117,7 @@ func (self *Signer) SignRequestV1(req *http.Request, canon func(*http.Request) ( } if exp > 0 { - qstring["Expires"] = []string{strconv.FormatInt(time.Now()+exp, 10)} + qstring["Expires"] = []string{strconv.FormatInt(time.Now().Unix()+exp, 10)} } else { qstring["Timestamp"] = []string{time.Now().UTC().Format(ISO8601TimestampFormat)} } From 5c0823adedc1111822a9e06c289b8bcad4702b85 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 4 Jan 2013 23:16:19 +0000 Subject: [PATCH 4/6] Use Go 1.0 build system: tidy Makefiles & update README --- Makefile | 29 ++++++----------------------- README | 7 ++++--- ec2/Makefile | 16 ---------------- ec2/util/Makefile | 15 --------------- elb/Makefile | 24 ------------------------ elb/util/Makefile | 15 --------------- flags/Makefile | 12 ------------ s3/Makefile | 14 -------------- s3/util/Makefile | 15 --------------- samples/s3_proxy/Makefile | 8 -------- sdb/Makefile | 19 ------------------- sdb/util/Makefile | 15 --------------- sqs/Makefile | 14 -------------- sqs/util/Makefile | 15 --------------- util/Makefile | 18 ------------------ util/common/Makefile | 11 ----------- 16 files changed, 10 insertions(+), 237 deletions(-) delete mode 100644 ec2/Makefile delete mode 100644 ec2/util/Makefile delete mode 100644 elb/Makefile delete mode 100644 elb/util/Makefile delete mode 100644 flags/Makefile delete mode 100644 s3/Makefile delete mode 100644 s3/util/Makefile delete mode 100644 samples/s3_proxy/Makefile delete mode 100644 sdb/Makefile delete mode 100644 sdb/util/Makefile delete mode 100644 sqs/Makefile delete mode 100644 sqs/util/Makefile delete mode 100644 util/Makefile delete mode 100644 util/common/Makefile diff --git a/Makefile b/Makefile index 5f252b4..c94671d 100644 --- a/Makefile +++ b/Makefile @@ -1,25 +1,8 @@ -include $(GOROOT)/src/Make.inc +all: + go build ./... -TARG=aws -GOFILES=\ - consts.go\ - dialer.go\ - http_dialer.go\ - signer.go\ - escape.go\ - timeformats.go\ +clean: + go clean ./... -include $(GOROOT)/src/Make.pkg - -module.%: % - gomake -C $* - -module_install.%: module.% - gomake -C $* install - -module_clean.%: - gomake -C $* clean - -modules: module.sqs module.s3 module.sdb module.ec2 module.elb -modules_install: module_install.sqs module_install.s3 module_install.sdb module_install.ec2 module_install.elb -modules_clean: module_clean.sqs module_clean.s3 module_clean.sdb module_clean.elb module_clean.ec2 +install: + go install ./... diff --git a/README b/README index 9400b84..53aa11a 100644 --- a/README +++ b/README @@ -14,9 +14,10 @@ paths required for the command line tool. fully capable of basic administration of ELB, S3, SQS, and SimpleDB resources, but are intended primarily for testing and API usage examples. - This package should build/goinstall on its own, but to make use of the sub-modules, -you will need to run 'make modules modules_install'. (If anyone can submit a patch -to allow goinstall to do the entire project, it will be gladly accepted!) +Installation +============ + +go get github.com/abneptis/GoAWS Bugs/Notes ========== diff --git a/ec2/Makefile b/ec2/Makefile deleted file mode 100644 index 9cb3517..0000000 --- a/ec2/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -include $(GOROOT)/src/Make.inc - -TARG=aws/ec2 -GOFILES=\ - consts.go\ - instance.go\ - service.go\ - -DEPS=\ - ../ - #../\ - -CLEANFILES+=\ - -include $(GOROOT)/src/Make.pkg - diff --git a/ec2/util/Makefile b/ec2/util/Makefile deleted file mode 100644 index 989d0e7..0000000 --- a/ec2/util/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -include $(GOROOT)/src/Make.inc - -TARG=aws/ec2/ec2_util -GOFILES=ec2_main.go\ - -DEPS=\ - ../\ - ../../\ - ../../flags/\ - ../../util/common/\ - -CLEANFILES+=\ - -include $(GOROOT)/src/Make.pkg - diff --git a/elb/Makefile b/elb/Makefile deleted file mode 100644 index 331b7d2..0000000 --- a/elb/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -include $(GOROOT)/src/Make.inc - -TARG=aws/elb -GOFILES=\ - consts.go\ - response.go\ - service.go\ - -DEPS=../ - -CLEANFILES+=\ - tools/*.[568vq]\ - tools/simpledb - -include $(GOROOT)/src/Make.pkg - - -tools: tools/simpledb - -tools/simpledb.$(O): tools/simpledb.go - $(GC) -o $@ $^ - -tools/simpledb: tools/simpledb.$(O) - $(LD) -o $@ $^ diff --git a/elb/util/Makefile b/elb/util/Makefile deleted file mode 100644 index 1c28434..0000000 --- a/elb/util/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -include $(GOROOT)/src/Make.inc - -TARG=aws/elb/elb_util -GOFILES=elb_main.go\ - -DEPS=\ - ../\ - ../../\ - ../../flags/\ - ../../util/common/\ - -CLEANFILES+=\ - -include $(GOROOT)/src/Make.pkg - diff --git a/flags/Makefile b/flags/Makefile deleted file mode 100644 index 77a89e7..0000000 --- a/flags/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -include $(GOROOT)/src/Make.inc - -TARG=aws/flags -GOFILES=init.go\ - -DEPS=\ - ../\ - -CLEANFILES+=\ - -include $(GOROOT)/src/Make.pkg - diff --git a/s3/Makefile b/s3/Makefile deleted file mode 100644 index c4cc8bc..0000000 --- a/s3/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -include $(GOROOT)/src/Make.inc - -TARG=aws/s3 - -DEPS=\ - ../ - -GOFILES=\ - consts.go\ - service_opers.go\ - bucket_opers.go\ - -include $(GOROOT)/src/Make.pkg - diff --git a/s3/util/Makefile b/s3/util/Makefile deleted file mode 100644 index 1340d78..0000000 --- a/s3/util/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -include $(GOROOT)/src/Make.inc - -TARG=aws/s3/s3_util -GOFILES=s3_main.go\ - -DEPS=\ - ../\ - ../../\ - ../../flags/\ - ../../util/common/\ - -CLEANFILES+=\ - -include $(GOROOT)/src/Make.pkg - diff --git a/samples/s3_proxy/Makefile b/samples/s3_proxy/Makefile deleted file mode 100644 index 6cce25f..0000000 --- a/samples/s3_proxy/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -include $(GOROOT)/src/Make.inc - -TARG=s3_proxy -GOFILES=\ - config.go\ - main.go\ - -include $(GOROOT)/src/Make.cmd diff --git a/sdb/Makefile b/sdb/Makefile deleted file mode 100644 index cba8fa4..0000000 --- a/sdb/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -include $(GOROOT)/src/Make.inc - -TARG=aws/sdb -GOFILES=\ - service.go\ - consts.go\ - response.go\ - domain.go\ - attribute.go\ -# handler.go\ -# response.go\ - -DEPS=../ - -CLEANFILES+=\ - -include $(GOROOT)/src/Make.pkg - - diff --git a/sdb/util/Makefile b/sdb/util/Makefile deleted file mode 100644 index 8bb25fa..0000000 --- a/sdb/util/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -include $(GOROOT)/src/Make.inc - -TARG=aws/sdb/sdb_util -GOFILES=sdb_main.go\ - -DEPS=\ - ../\ - ../../\ - ../../flags/\ - ../../util/common/\ - -CLEANFILES+=\ - -include $(GOROOT)/src/Make.pkg - diff --git a/sqs/Makefile b/sqs/Makefile deleted file mode 100644 index 0299bb6..0000000 --- a/sqs/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -include $(GOROOT)/src/Make.inc - -TARG=aws/sqs -GOFILES=\ - \ - queue.go\ - service.go\ - consts.go\ - -DEPS=\ - ../\ - -include $(GOROOT)/src/Make.pkg - diff --git a/sqs/util/Makefile b/sqs/util/Makefile deleted file mode 100644 index 9d61207..0000000 --- a/sqs/util/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -include $(GOROOT)/src/Make.inc - -TARG=aws/sqs/sqs_util -GOFILES=sqs_main.go\ - -DEPS=\ - ../\ - ../../\ - ../../flags/\ - ../../util/common/\ - -CLEANFILES+=\ - -include $(GOROOT)/src/Make.pkg - diff --git a/util/Makefile b/util/Makefile deleted file mode 100644 index 1fb1dd3..0000000 --- a/util/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -include $(GOROOT)/src/Make.inc - -TARG=awstool -GOFILES=main.go\ - -DEPS=\ - ../s3/util/\ - ../sqs/util/\ - ../sdb/util/\ - ../ec2/util/\ - ../elb/util/\ - ../flags/\ - ./common/\ - -CLEANFILES+=\ - -include $(GOROOT)/src/Make.cmd - diff --git a/util/common/Makefile b/util/common/Makefile deleted file mode 100644 index 8db00ed..0000000 --- a/util/common/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -include $(GOROOT)/src/Make.inc - -TARG=aws/util/common -GOFILES=common.go\ - -DEPS=\ - -CLEANFILES+=\ - -include $(GOROOT)/src/Make.pkg - From 0e74bc792b1b40effb0060b36c4bb3170c1cbc2e Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 4 Jan 2013 23:42:38 +0000 Subject: [PATCH 5/6] Fix import paths and xml.Unmarshal --- ec2/service.go | 4 ++-- ec2/util/ec2_main.go | 8 ++++---- elb/service.go | 6 +++--- elb/util/elb_main.go | 8 ++++---- flags/init.go | 2 +- s3/bucket_opers.go | 4 ++-- s3/service_opers.go | 4 ++-- s3/util/s3_main.go | 8 ++++---- samples/s3_proxy/config.go | 6 +++--- sdb/domain.go | 6 +++--- sdb/service.go | 4 ++-- sdb/util/sdb_main.go | 8 ++++---- sqs/queue.go | 4 ++-- sqs/service.go | 6 +++--- sqs/util/sqs_main.go | 8 ++++---- timeformats.go | 1 - util/main.go | 14 +++++++------- 17 files changed, 50 insertions(+), 51 deletions(-) diff --git a/ec2/service.go b/ec2/service.go index 2aec6e0..c0f742b 100644 --- a/ec2/service.go +++ b/ec2/service.go @@ -1,7 +1,7 @@ package ec2 import ( - "aws" + aws ".." "net/url" ) @@ -38,7 +38,7 @@ func (self *Service) DescribeInstances(id *aws.Signer, filter url.Values, ic cha if err == nil { defer resp.Body.Close() xresp := describeInstancesResponse{} - err := xml.Unmarshal(resp.Body, &xresp) + err := xml.NewDecoder(resp.Body).Decode(&xresp) if err == nil { log.Printf("XRESP == %+v", xresp) } else { diff --git a/ec2/util/ec2_main.go b/ec2/util/ec2_main.go index e3d2116..5697bc7 100644 --- a/ec2/util/ec2_main.go +++ b/ec2/util/ec2_main.go @@ -1,10 +1,10 @@ package ec2_util import ( - "aws" - "aws/ec2" - . "aws/flags" - . "aws/util/common" + ec2 ".." + aws "../.." + . "../../flags" + . "../../util/common" "net/url" ) diff --git a/elb/service.go b/elb/service.go index 96c2414..4071677 100644 --- a/elb/service.go +++ b/elb/service.go @@ -1,7 +1,7 @@ package elb import ( - "aws" + aws ".." "errors" "net/url" ) @@ -82,7 +82,7 @@ func (self *Service) DescribeLoadBalancers(id *aws.Signer) (lbs []LoadBalancerDe if err == nil { qr := LoadBalancerQueryResult{} defer resp.Body.Close() - err = xml.Unmarshal(resp.Body, &qr) + err = xml.NewDecoder(resp.Body).Decode(&qr) if err == nil { lbs = qr.LoadBalancerDescription } @@ -111,7 +111,7 @@ func (self *Service) DeleteLoadBalancer(id *aws.Signer, name string) (err error) err = aws.CodeToError(resp.StatusCode) } qr := LoadBalancerQueryResult{} - err = xml.Unmarshal(resp.Body, &qr) + err = xml.NewDecoder(resp.Body).Decode(&qr) if err == nil { if qr.ErrorCode != "" { err = errors.New(qr.ErrorCode) diff --git a/elb/util/elb_main.go b/elb/util/elb_main.go index 58601cb..3867ceb 100644 --- a/elb/util/elb_main.go +++ b/elb/util/elb_main.go @@ -1,10 +1,10 @@ package elb_util import ( - "aws" - "aws/elb" - . "aws/flags" - . "aws/util/common" + elb ".." + aws "../.." + . "../../flags" + . "../../util/common" "errors" "net/url" ) diff --git a/flags/init.go b/flags/init.go index 6679e97..4f5333b 100644 --- a/flags/init.go +++ b/flags/init.go @@ -6,7 +6,7 @@ package flags // against a malicious root, but very little is. import ( - "aws" + aws ".." "errors" ) diff --git a/s3/bucket_opers.go b/s3/bucket_opers.go index 80ddb26..ce7dd29 100644 --- a/s3/bucket_opers.go +++ b/s3/bucket_opers.go @@ -1,7 +1,7 @@ package s3 import ( - "aws" + aws ".." "errors" "net/url" ) @@ -248,7 +248,7 @@ func (self *Bucket) ListKeys(id *aws.Signer, if err == nil { err = aws.CodeToError(resp.StatusCode) if err == nil { - err = xml.Unmarshal(resp.Body, &result) + err = xml.NewDecoder(resp.Body).Decode(&result) if err == nil { for i := range result.Contents { out <- result.Contents[i].Key diff --git a/s3/service_opers.go b/s3/service_opers.go index 66a87db..b20f8c7 100644 --- a/s3/service_opers.go +++ b/s3/service_opers.go @@ -1,7 +1,7 @@ package s3 import ( - "aws" + aws ".." "net/url" ) @@ -106,7 +106,7 @@ func (self *Service) ListBuckets(id *aws.Signer) (out []string, err error) { if err == nil { defer resp.Body.Close() result := listAllMyBucketsResult{} - err = xml.Unmarshal(resp.Body, &result) + err = xml.NewDecoder(resp.Body).Decode(&result) if err == nil { out = result.Buckets } diff --git a/s3/util/s3_main.go b/s3/util/s3_main.go index 3a85985..3c5ddf4 100644 --- a/s3/util/s3_main.go +++ b/s3/util/s3_main.go @@ -1,10 +1,10 @@ package s3_util import ( - "aws" - . "aws/flags" - "aws/s3" - . "aws/util/common" + s3 ".." + aws "../.." + . "../../flags" + . "../../util/common" "errors" "net/url" ) diff --git a/samples/s3_proxy/config.go b/samples/s3_proxy/config.go index 599ba57..01b1eef 100644 --- a/samples/s3_proxy/config.go +++ b/samples/s3_proxy/config.go @@ -1,9 +1,9 @@ package main import ( - "aws" - . "aws/flags" - "aws/s3" + aws "../.." + . "../../flags" + "../../s3" "errors" "net/url" ) diff --git a/sdb/domain.go b/sdb/domain.go index 73e8695..0bb969c 100644 --- a/sdb/domain.go +++ b/sdb/domain.go @@ -1,7 +1,7 @@ package sdb import ( - "aws" + aws ".." "net/url" ) @@ -73,7 +73,7 @@ func (self *Domain) GetAttribute(s *aws.Signer, item string, attrs AttributeList var response getattributesresponse ob, _ := httputil.DumpResponse(resp, true) os.Stdout.Write(ob) - err = xml.Unmarshal(resp.Body, &response) + err = xml.NewDecoder(resp.Body).Decode(&response) if err == nil { a = response.Attributes } @@ -111,7 +111,7 @@ func (self *Domain) Select(id *aws.Signer, what, where string, consist bool, ite ob, _ := httputil.DumpResponse(resp, true) os.Stdout.Write(ob) xresp := selectresponse{} - err = xml.Unmarshal(resp.Body, &xresp) + err = xml.NewDecoder(resp.Body).Decode(&xresp) if err == nil { fmt.Printf("XML == %+v", xresp) for i := range xresp.Items { diff --git a/sdb/service.go b/sdb/service.go index 9ae9c88..0369fca 100644 --- a/sdb/service.go +++ b/sdb/service.go @@ -1,7 +1,7 @@ package sdb import ( - "aws" + aws ".." "errors" "net/url" ) @@ -110,7 +110,7 @@ func (self *Service) ListDomains(id *aws.Signer) (out []string, err error) { os.Stdout.Write(ob) } if err == nil { - err = xml.Unmarshal(resp.Body, &xmlresp) + err = xml.NewDecoder(resp.Body).Decode(&xmlresp) if err == nil { if xmlresp.ErrorCode != "" { err = errors.New(xmlresp.ErrorCode) diff --git a/sdb/util/sdb_main.go b/sdb/util/sdb_main.go index 52c6482..6ece1e2 100644 --- a/sdb/util/sdb_main.go +++ b/sdb/util/sdb_main.go @@ -1,10 +1,10 @@ package sdb_util import ( - "aws" - . "aws/flags" - "aws/sdb" - . "aws/util/common" + sdb ".." + aws "../.." + . "../../flags" + . "../../util/common" "errors" "net/url" ) diff --git a/sqs/queue.go b/sqs/queue.go index 7a8fc41..71fca48 100644 --- a/sqs/queue.go +++ b/sqs/queue.go @@ -1,7 +1,7 @@ package sqs import ( - "aws" + aws ".." "errors" "net/url" ) @@ -83,7 +83,7 @@ func (self *Queue) Peek(id *aws.Signer, vt int) (body []byte, msgid string, err } if err == nil { msg := message{} - err = xml.Unmarshal(resp.Body, &msg) + err = xml.NewDecoder(resp.Body).Decode(&msg) if err == nil { body, msgid = msg.Body, msg.ReceiptHandle } diff --git a/sqs/service.go b/sqs/service.go index b58b5fc..e480fda 100644 --- a/sqs/service.go +++ b/sqs/service.go @@ -1,7 +1,7 @@ package sqs import ( - "aws" + aws ".." "errors" "net/url" ) @@ -45,7 +45,7 @@ func (self *Service) ListQueues(id *aws.Signer, prefix string) (mq []string, err defer resp.Body.Close() xresp := listQueuesResponse{} if resp.StatusCode == http.StatusOK { - err = xml.Unmarshal(resp.Body, &xresp) + err = xml.NewDecoder(resp.Body).Decode(&xresp) } else { err = errors.New("Unexpected response code") } @@ -73,7 +73,7 @@ func (self *Service) CreateQueue(id *aws.Signer, name string, dvtimeout int) (mq defer resp.Body.Close() if resp.StatusCode == http.StatusOK { xmlresp := createQueueResponse{} - err = xml.Unmarshal(resp.Body, &xmlresp) + err = xml.NewDecoder(resp.Body).Decode(&xmlresp) if err == nil { var qrl *url.URL qrl, err = url.Parse(xmlresp.QueueURL) diff --git a/sqs/util/sqs_main.go b/sqs/util/sqs_main.go index 8646ee0..f1b392e 100644 --- a/sqs/util/sqs_main.go +++ b/sqs/util/sqs_main.go @@ -1,10 +1,10 @@ package sqs_util import ( - "aws" - . "aws/flags" - "aws/sqs" - . "aws/util/common" + aws "../.." + . "../../flags" + "../../sqs" + . "../../util/common" "errors" "net/url" ) diff --git a/timeformats.go b/timeformats.go index 07732e4..60e092c 100644 --- a/timeformats.go +++ b/timeformats.go @@ -7,4 +7,3 @@ package aws var SQSTimestampFormat = "2006-01-02T15:04:05MST" var ISO8601TimestampFormat = "2006-01-02T15:04:05Z" - diff --git a/util/main.go b/util/main.go index a741c54..efbd074 100644 --- a/util/main.go +++ b/util/main.go @@ -1,13 +1,13 @@ package main import ( - "aws/ec2/ec2_util" - "aws/elb/elb_util" - . "aws/flags" // AWS ID Flags - "aws/s3/s3_util" - "aws/sdb/sdb_util" - "aws/sqs/sqs_util" - . "aws/util/common" + ec2_util "../ec2/util" + elb_util "../elb/util" + . "../flags" // AWS ID Flags + s3_util "../s3/util" + sdb_util "../sdb/util" + sqs_util "../sqs/util" + . "../util/common" "errors" // AWS ID Flags ) From 6f1e256e03039d39282ace55d2c8b02563657776 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sat, 5 Jan 2013 00:10:56 +0000 Subject: [PATCH 6/6] Use absolute paths in imports to avoid non local import error --- ec2/service.go | 2 +- ec2/util/ec2_main.go | 8 ++++---- elb/service.go | 2 +- elb/util/elb_main.go | 8 ++++---- flags/init.go | 2 +- s3/bucket_opers.go | 2 +- s3/service_opers.go | 2 +- s3/util/s3_main.go | 8 ++++---- samples/s3_proxy/config.go | 6 +++--- sdb/domain.go | 2 +- sdb/service.go | 2 +- sdb/util/sdb_main.go | 8 ++++---- sqs/queue.go | 2 +- sqs/service.go | 2 +- sqs/util/sqs_main.go | 8 ++++---- util/main.go | 14 +++++++------- 16 files changed, 39 insertions(+), 39 deletions(-) diff --git a/ec2/service.go b/ec2/service.go index c0f742b..b09fb99 100644 --- a/ec2/service.go +++ b/ec2/service.go @@ -1,7 +1,7 @@ package ec2 import ( - aws ".." + "github.com/abneptis/GoAWS" "net/url" ) diff --git a/ec2/util/ec2_main.go b/ec2/util/ec2_main.go index 5697bc7..63f8852 100644 --- a/ec2/util/ec2_main.go +++ b/ec2/util/ec2_main.go @@ -1,10 +1,10 @@ package ec2_util import ( - ec2 ".." - aws "../.." - . "../../flags" - . "../../util/common" + "github.com/abneptis/GoAWS" + "github.com/abneptis/GoAWS/ec2" + . "github.com/abneptis/GoAWS/flags" + . "github.com/abneptis/GoAWS/util/common" "net/url" ) diff --git a/elb/service.go b/elb/service.go index 4071677..4b41ed9 100644 --- a/elb/service.go +++ b/elb/service.go @@ -1,8 +1,8 @@ package elb import ( - aws ".." "errors" + "github.com/abneptis/GoAWS" "net/url" ) diff --git a/elb/util/elb_main.go b/elb/util/elb_main.go index 3867ceb..c0fd014 100644 --- a/elb/util/elb_main.go +++ b/elb/util/elb_main.go @@ -1,11 +1,11 @@ package elb_util import ( - elb ".." - aws "../.." - . "../../flags" - . "../../util/common" "errors" + "github.com/abneptis/GoAWS" + "github.com/abneptis/GoAWS/elb" + . "github.com/abneptis/GoAWS/flags" + . "github.com/abneptis/GoAWS/util/common" "net/url" ) diff --git a/flags/init.go b/flags/init.go index 4f5333b..12bbcd0 100644 --- a/flags/init.go +++ b/flags/init.go @@ -6,8 +6,8 @@ package flags // against a malicious root, but very little is. import ( - aws ".." "errors" + "github.com/abneptis/GoAWS" ) import ( diff --git a/s3/bucket_opers.go b/s3/bucket_opers.go index ce7dd29..6b8995f 100644 --- a/s3/bucket_opers.go +++ b/s3/bucket_opers.go @@ -1,8 +1,8 @@ package s3 import ( - aws ".." "errors" + "github.com/abneptis/GoAWS" "net/url" ) diff --git a/s3/service_opers.go b/s3/service_opers.go index b20f8c7..6fc65d9 100644 --- a/s3/service_opers.go +++ b/s3/service_opers.go @@ -1,7 +1,7 @@ package s3 import ( - aws ".." + "github.com/abneptis/GoAWS" "net/url" ) diff --git a/s3/util/s3_main.go b/s3/util/s3_main.go index 3c5ddf4..2cc3e9c 100644 --- a/s3/util/s3_main.go +++ b/s3/util/s3_main.go @@ -1,11 +1,11 @@ package s3_util import ( - s3 ".." - aws "../.." - . "../../flags" - . "../../util/common" "errors" + "github.com/abneptis/GoAWS" + . "github.com/abneptis/GoAWS/flags" + "github.com/abneptis/GoAWS/s3" + . "github.com/abneptis/GoAWS/util/common" "net/url" ) diff --git a/samples/s3_proxy/config.go b/samples/s3_proxy/config.go index 01b1eef..509c10d 100644 --- a/samples/s3_proxy/config.go +++ b/samples/s3_proxy/config.go @@ -1,10 +1,10 @@ package main import ( - aws "../.." - . "../../flags" - "../../s3" "errors" + "github.com/abneptis/GoAWS" + . "github.com/abneptis/GoAWS/flags" + "github.com/abneptis/GoAWS/s3" "net/url" ) diff --git a/sdb/domain.go b/sdb/domain.go index 0bb969c..a24345e 100644 --- a/sdb/domain.go +++ b/sdb/domain.go @@ -1,7 +1,7 @@ package sdb import ( - aws ".." + "github.com/abneptis/GoAWS" "net/url" ) diff --git a/sdb/service.go b/sdb/service.go index 0369fca..51cfd04 100644 --- a/sdb/service.go +++ b/sdb/service.go @@ -1,8 +1,8 @@ package sdb import ( - aws ".." "errors" + "github.com/abneptis/GoAWS" "net/url" ) diff --git a/sdb/util/sdb_main.go b/sdb/util/sdb_main.go index 6ece1e2..282541a 100644 --- a/sdb/util/sdb_main.go +++ b/sdb/util/sdb_main.go @@ -1,11 +1,11 @@ package sdb_util import ( - sdb ".." - aws "../.." - . "../../flags" - . "../../util/common" "errors" + "github.com/abneptis/GoAWS" + . "github.com/abneptis/GoAWS/flags" + "github.com/abneptis/GoAWS/sdb" + . "github.com/abneptis/GoAWS/util/common" "net/url" ) diff --git a/sqs/queue.go b/sqs/queue.go index 71fca48..ea17863 100644 --- a/sqs/queue.go +++ b/sqs/queue.go @@ -1,8 +1,8 @@ package sqs import ( - aws ".." "errors" + "github.com/abneptis/GoAWS" "net/url" ) diff --git a/sqs/service.go b/sqs/service.go index e480fda..01fd639 100644 --- a/sqs/service.go +++ b/sqs/service.go @@ -1,8 +1,8 @@ package sqs import ( - aws ".." "errors" + "github.com/abneptis/GoAWS" "net/url" ) diff --git a/sqs/util/sqs_main.go b/sqs/util/sqs_main.go index f1b392e..84927ed 100644 --- a/sqs/util/sqs_main.go +++ b/sqs/util/sqs_main.go @@ -1,11 +1,11 @@ package sqs_util import ( - aws "../.." - . "../../flags" - "../../sqs" - . "../../util/common" "errors" + "github.com/abneptis/GoAWS" + . "github.com/abneptis/GoAWS/flags" + "github.com/abneptis/GoAWS/sqs" + . "github.com/abneptis/GoAWS/util/common" "net/url" ) diff --git a/util/main.go b/util/main.go index efbd074..03ebfd0 100644 --- a/util/main.go +++ b/util/main.go @@ -1,14 +1,14 @@ package main import ( - ec2_util "../ec2/util" - elb_util "../elb/util" - . "../flags" // AWS ID Flags - s3_util "../s3/util" - sdb_util "../sdb/util" - sqs_util "../sqs/util" - . "../util/common" "errors" // AWS ID Flags + ec2_util "github.com/abneptis/GoAWS/ec2/util" + elb_util "github.com/abneptis/GoAWS/elb/util" + . "github.com/abneptis/GoAWS/flags" // AWS ID Flags + s3_util "github.com/abneptis/GoAWS/s3/util" + sdb_util "github.com/abneptis/GoAWS/sdb/util" + sqs_util "github.com/abneptis/GoAWS/sqs/util" + . "github.com/abneptis/GoAWS/util/common" ) import (