Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

gofix 2011.11.09 #7

Closed
wants to merge 1 commit into from

2 participants

@bgentry

No description provided.

@bgentry bgentry commented on the diff
@@ -37,9 +34,8 @@ func newError(t *txn) *Error {
}
}
-
-func (e *Error) String() (s string) {
- s = e.Err.String()
+func (e *Error) Error() (s string) {
+ s = e.Err.Error()
@bgentry
bgentry added a note

Adheres to the new error interface

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@bgentry bgentry commented on the diff
msg.pb.go
@@ -110,7 +109,7 @@ func newResponse_Err(x response_Err) *response_Err {
e := response_Err(x)
return &e
}
-func (x response_Err) String() string {
+func (x response_Err) Error() string {
@bgentry
bgentry added a note

Adheres to the new error interface

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mreiferson
Owner

OBE see #21

@mreiferson mreiferson closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 19, 2011
  1. @bgentry

    gofix for weekly.2011.11.09

    bgentry authored
This page is out of date. Refresh to see the latest.
View
2  cmd/doozer/doozer.go
@@ -73,7 +73,7 @@ func usage() {
}
-func bail(e os.Error) {
+func bail(e error) {
fmt.Fprintln(os.Stderr, "Error:", e)
if e == doozer.ErrOldRev {
os.Exit(1)
View
7 cmd/doozer/find.go
@@ -6,7 +6,6 @@ import (
"os"
)
-
func init() {
cmds["find"] = cmd{find, "<path>", "list files"}
cmdHelp["find"] = `Prints the tree rooted at <path>
@@ -15,12 +14,11 @@ Prints the path for each file or directory, one per line.
`
}
-
func find(path string) {
c := dial()
if *rrev == -1 {
- var err os.Error
+ var err error
*rrev, err = c.Rev()
if err != nil {
bail(err)
@@ -28,7 +26,7 @@ func find(path string) {
}
v := make(vis)
- errs := make(chan os.Error)
+ errs := make(chan error)
go func() {
doozer.Walk(c, *rrev, path, v, errs)
close(v)
@@ -47,7 +45,6 @@ func find(path string) {
}
}
-
type vis chan string
func (v vis) VisitDir(path string, f *doozer.FileInfo) bool {
View
4 cmd/doozer/wait.go
@@ -5,7 +5,6 @@ import (
"os"
)
-
func init() {
cmds["wait"] = cmd{wait, "<glob>", "wait for a change"}
cmdHelp["wait"] = `Prints the next change to a file matching <glob>.
@@ -27,12 +26,11 @@ bytes in the body, and LF is an ASCII line-feed char.
`
}
-
func wait(path string) {
c := dial()
if *rrev == -1 {
- var err os.Error
+ var err error
*rrev, err = c.Rev()
if err != nil {
bail(err)
View
4 cmd/doozer/watch.go
@@ -5,7 +5,6 @@ import (
"os"
)
-
func init() {
cmds["watch"] = cmd{watch, "<glob>", "watch for a change"}
cmdHelp["watch"] = `Prints changes to any file matching <glob>.
@@ -27,12 +26,11 @@ Here, <path> is the file's path, <rev> is the revision of the change,
`
}
-
func watch(glob string) {
c := dial()
if *rrev == -1 {
- var err os.Error
+ var err error
*rrev, err = c.Rev()
if err != nil {
bail(err)
View
60 conn.go
@@ -2,16 +2,16 @@ package doozer
import (
"encoding/binary"
+ "errors"
"github.com/kr/pretty.go"
"goprotobuf.googlecode.com/hg/proto"
"io"
"log"
+ "math/rand"
"net"
- "os"
- "rand"
+ "net/url"
"strings"
- "url"
)
var (
@@ -19,13 +19,13 @@ var (
)
var (
- ErrInvalidUri = os.NewError("invalid uri")
+ ErrInvalidUri = errors.New("invalid uri")
)
type txn struct {
req request
resp *response
- err os.Error
+ err error
done chan bool
}
@@ -34,15 +34,15 @@ type Conn struct {
conn net.Conn
send chan *txn
msg chan []byte
- err os.Error
+ err error
stop chan bool
stopped chan bool
}
// Dial connects to a single doozer server.
-func Dial(addr string) (*Conn, os.Error) {
+func Dial(addr string) (*Conn, error) {
var c Conn
- var err os.Error
+ var err error
c.addr = addr
c.conn, err = net.Dial("tcp", addr)
if err != nil {
@@ -53,7 +53,7 @@ func Dial(addr string) (*Conn, os.Error) {
c.msg = make(chan []byte)
c.stop = make(chan bool, 1)
c.stopped = make(chan bool)
- errch := make(chan os.Error, 1)
+ errch := make(chan error, 1)
go c.mux(errch)
go c.readAll(errch)
return &c, nil
@@ -62,7 +62,7 @@ func Dial(addr string) (*Conn, os.Error) {
// DialUri connects to one of the doozer servers given in `uri`. If `uri`
// contains a cluster name, it will lookup addrs to try in `buri`. If `uri`
// contains a secret key, then DialUri will call `Access` with the secret.
-func DialUri(uri, buri string) (*Conn, os.Error) {
+func DialUri(uri, buri string) (*Conn, error) {
if !strings.HasPrefix(uri, uriPrefix) {
return nil, ErrInvalidUri
}
@@ -112,7 +112,7 @@ func DialUri(uri, buri string) (*Conn, os.Error) {
}
// Find possible addresses for cluster named name.
-func lookup(b *Conn, name string) (as []string, err os.Error) {
+func lookup(b *Conn, name string) (as []string, err error) {
rev, err := b.Rev()
if err != nil {
return nil, err
@@ -137,7 +137,7 @@ func lookup(b *Conn, name string) (as []string, err os.Error) {
return as, nil
}
-func (c *Conn) call(t *txn) os.Error {
+func (c *Conn) call(t *txn) error {
t.done = make(chan bool)
select {
case <-c.stopped:
@@ -162,10 +162,10 @@ func (c *Conn) Close() {
}
}
-func (c *Conn) mux(errch chan os.Error) {
+func (c *Conn) mux(errch chan error) {
txns := make(map[int32]*txn)
var n int32 // next tag
- var err os.Error
+ var err error
for {
select {
@@ -211,7 +211,7 @@ func (c *Conn) mux(errch chan os.Error) {
continue
}
- txns[*r.Tag] = nil, false
+ delete(txns, *r.Tag)
t.resp = &r
t.done <- true
case err = <-errch:
@@ -232,7 +232,7 @@ error:
close(c.stopped)
}
-func (c *Conn) readAll(errch chan os.Error) {
+func (c *Conn) readAll(errch chan error) {
for {
buf, err := c.read()
if err != nil {
@@ -244,7 +244,7 @@ func (c *Conn) readAll(errch chan os.Error) {
}
}
-func (c *Conn) read() ([]byte, os.Error) {
+func (c *Conn) read() ([]byte, error) {
var size int32
err := binary.Read(c.conn, binary.BigEndian, &size)
if err != nil {
@@ -260,7 +260,7 @@ func (c *Conn) read() ([]byte, os.Error) {
return buf, nil
}
-func (c *Conn) write(buf []byte) os.Error {
+func (c *Conn) write(buf []byte) error {
err := binary.Write(c.conn, binary.BigEndian, int32(len(buf)))
if err != nil {
return err
@@ -271,7 +271,7 @@ func (c *Conn) write(buf []byte) os.Error {
}
// Attempts access to the store
-func (c *Conn) Access(token string) os.Error {
+func (c *Conn) Access(token string) error {
var t txn
t.req.Verb = newRequest_Verb(request_ACCESS)
t.req.Value = []byte(token)
@@ -279,7 +279,7 @@ func (c *Conn) Access(token string) os.Error {
}
// Sets the contents of file to body, if it hasn't been modified since oldRev.
-func (c *Conn) Set(file string, oldRev int64, body []byte) (newRev int64, err os.Error) {
+func (c *Conn) Set(file string, oldRev int64, body []byte) (newRev int64, err error) {
var t txn
t.req.Verb = newRequest_Verb(request_SET)
t.req.Path = &file
@@ -295,7 +295,7 @@ func (c *Conn) Set(file string, oldRev int64, body []byte) (newRev int64, err os
}
// Deletes file, if it hasn't been modified since rev.
-func (c *Conn) Del(file string, rev int64) os.Error {
+func (c *Conn) Del(file string, rev int64) error {
var t txn
t.req.Verb = newRequest_Verb(request_DEL)
t.req.Path = &file
@@ -303,7 +303,7 @@ func (c *Conn) Del(file string, rev int64) os.Error {
return c.call(&t)
}
-func (c *Conn) Nop() os.Error {
+func (c *Conn) Nop() error {
var t txn
t.req.Verb = newRequest_Verb(request_NOP)
return c.call(&t)
@@ -312,7 +312,7 @@ func (c *Conn) Nop() os.Error {
// Returns the body and revision of the file at path,
// as of store revision *rev.
// If rev is nil, uses the current state.
-func (c *Conn) Get(file string, rev *int64) ([]byte, int64, os.Error) {
+func (c *Conn) Get(file string, rev *int64) ([]byte, int64, error) {
var t txn
t.req.Verb = newRequest_Verb(request_GET)
t.req.Path = &file
@@ -329,7 +329,7 @@ func (c *Conn) Get(file string, rev *int64) ([]byte, int64, os.Error) {
// Getdir reads up to lim names from dir, at revision rev, into an array.
// Names are read in lexicographical order, starting at position off.
// A negative lim means to read until the end.
-func (c *Conn) Getdir(dir string, rev int64, off, lim int) (names []string, err os.Error) {
+func (c *Conn) Getdir(dir string, rev int64, off, lim int) (names []string, err error) {
for lim != 0 {
var t txn
t.req.Verb = newRequest_Verb(request_GETDIR)
@@ -355,7 +355,7 @@ func (c *Conn) Getdir(dir string, rev int64, off, lim int) (names []string, err
// Files are read in lexicographical order, starting at position off.
// A negative lim means to read until the end.
// Getdirinfo returns the array and an error, if any.
-func (c *Conn) Getdirinfo(dir string, rev int64, off, lim int) (a []FileInfo, err os.Error) {
+func (c *Conn) Getdirinfo(dir string, rev int64, off, lim int) (a []FileInfo, err error) {
names, err := c.Getdir(dir, rev, off, lim)
if err != nil {
return nil, err
@@ -380,7 +380,7 @@ func (c *Conn) Getdirinfo(dir string, rev int64, off, lim int) (a []FileInfo, er
// Statinfo returns metadata about the file or directory at path,
// in revision *storeRev. If storeRev is nil, uses the current
// revision.
-func (c *Conn) Statinfo(rev int64, path string) (f *FileInfo, err os.Error) {
+func (c *Conn) Statinfo(rev int64, path string) (f *FileInfo, err error) {
f = new(FileInfo)
f.Len, f.Rev, err = c.Stat(path, &rev)
if err != nil {
@@ -398,7 +398,7 @@ func (c *Conn) Statinfo(rev int64, path string) (f *FileInfo, err os.Error) {
// Stat returns metadata about the file or directory at path,
// in revision *storeRev. If storeRev is nil, uses the current
// revision.
-func (c *Conn) Stat(path string, storeRev *int64) (len int, fileRev int64, err os.Error) {
+func (c *Conn) Stat(path string, storeRev *int64) (len int, fileRev int64, err error) {
var t txn
t.req.Verb = newRequest_Verb(request_STAT)
t.req.Path = &path
@@ -416,7 +416,7 @@ func (c *Conn) Stat(path string, storeRev *int64) (len int, fileRev int64, err o
// Entries are read in lexicographical order, starting at position off.
// A negative lim means to read until the end.
// Conn.Walk will be removed in a future release. Use Walk instead.
-func (c *Conn) Walk(glob string, rev int64, off, lim int) (info []Event, err os.Error) {
+func (c *Conn) Walk(glob string, rev int64, off, lim int) (info []Event, err error) {
for lim != 0 {
var t txn
t.req.Verb = newRequest_Verb(request_WALK)
@@ -443,7 +443,7 @@ func (c *Conn) Walk(glob string, rev int64, off, lim int) (info []Event, err os.
}
// Waits for the first change, on or after rev, to any file matching glob.
-func (c *Conn) Wait(glob string, rev int64) (ev Event, err os.Error) {
+func (c *Conn) Wait(glob string, rev int64) (ev Event, err error) {
var t txn
t.req.Verb = newRequest_Verb(request_WAIT)
t.req.Path = &glob
@@ -462,7 +462,7 @@ func (c *Conn) Wait(glob string, rev int64) (ev Event, err os.Error) {
}
// Rev returns the current revision of the store.
-func (c *Conn) Rev() (int64, os.Error) {
+func (c *Conn) Rev() (int64, error) {
var t txn
t.req.Verb = newRequest_Verb(request_REV)
View
18 err.go
@@ -1,17 +1,16 @@
package doozer
import (
+ "errors"
"goprotobuf.googlecode.com/hg/proto"
- "os"
)
var (
- ErrNoAddrs = os.NewError("no known address")
- ErrBadTag = os.NewError("bad tag")
- ErrClosed = os.NewError("closed")
+ ErrNoAddrs = errors.New("no known address")
+ ErrBadTag = errors.New("bad tag")
+ ErrClosed = errors.New("closed")
)
-
var (
ErrOther response_Err = response_OTHER
ErrNotDir response_Err = response_NOTDIR
@@ -23,13 +22,11 @@ var (
ErrReadonly response_Err = response_READONLY
)
-
type Error struct {
- Err os.Error
+ Err error
Detail string
}
-
func newError(t *txn) *Error {
return &Error{
Err: *t.resp.ErrCode,
@@ -37,9 +34,8 @@ func newError(t *txn) *Error {
}
}
-
-func (e *Error) String() (s string) {
- s = e.Err.String()
+func (e *Error) Error() (s string) {
+ s = e.Err.Error()
@bgentry
bgentry added a note

Adheres to the new error interface

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
if e.Detail != "" {
s += ": " + e.Detail
}
View
5 msg.pb.go
@@ -5,12 +5,11 @@ package doozer
import proto "goprotobuf.googlecode.com/hg/proto"
import "math"
-import "os"
// Reference proto, math & os imports to suppress error if they are not otherwise used.
var _ = proto.GetString
var _ = math.Inf
-var _ os.Error
+var _ error
type request_Verb int32
@@ -110,7 +109,7 @@ func newResponse_Err(x response_Err) *response_Err {
e := response_Err(x)
return &e
}
-func (x response_Err) String() string {
+func (x response_Err) Error() string {
@bgentry
bgentry added a note

Adheres to the new error interface

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
return proto.EnumName(response_Err_name, int32(x))
}
View
10 walk.go
@@ -1,18 +1,13 @@
package doozer
-import (
- "os"
-)
-
type Visitor interface {
VisitDir(path string, f *FileInfo) bool
VisitFile(path string, f *FileInfo)
}
-
// Walk walks the file tree in revision rev, rooted at root,
// analogously to Walk in package path/filepath.
-func Walk(c *Conn, rev int64, root string, v Visitor, errors chan<- os.Error) {
+func Walk(c *Conn, rev int64, root string, v Visitor, errors chan<- error) {
f, err := c.Statinfo(rev, root)
if err != nil {
if errors != nil {
@@ -23,8 +18,7 @@ func Walk(c *Conn, rev int64, root string, v Visitor, errors chan<- os.Error) {
walk(c, rev, root, f, v, errors)
}
-
-func walk(c *Conn, r int64, path string, f *FileInfo, v Visitor, errors chan<- os.Error) {
+func walk(c *Conn, r int64, path string, f *FileInfo, v Visitor, errors chan<- error) {
if !f.IsDir {
v.VisitFile(path, f)
return
Something went wrong with that request. Please try again.