Skip to content
Browse files

-a takes a uri

  • Loading branch information...
1 parent 823da64 commit e04d7868013f7d602324db0861da2e0e8fc31c06 @bmizerany bmizerany committed with kr
Showing with 34 additions and 14 deletions.
  1. +2 −14 cmd/doozer/doozer.go
  2. +32 −0 conn.go
View
16 cmd/doozer/doozer.go
@@ -11,7 +11,7 @@ import (
)
var (
- addr = flag.String("a", "127.0.0.1:8046", "the address to bind to")
+ uri = flag.String("a", "doozer:?ca=127.0.0.1:8046", "the address to bind to")
rrev = flag.Int64("r", -1, "request rev")
showHelp = flag.Bool("h", false, "show help")
showVersion = flag.Bool("v", false, "print version string")
@@ -38,11 +38,6 @@ The exit status is 0 on success, 1 for a rev mismatch, and 2 otherwise.
Global Options:
`
usage2 = `
-Environment:
-
- DOOZER_SECRET
-
- Set the capability token for access to the server if needed.
Commands:
`
@@ -94,17 +89,10 @@ func mustAtoi64(arg string) int64 {
func dial() *doozer.Conn {
- c, err := doozer.Dial(*addr)
+ c, err := doozer.DialUri(*uri)
if err != nil {
bail(err)
}
-
- if token := os.Getenv("DOOZER_SECRET"); token != "" {
- err := c.Access(token)
- if err != nil {
- bail(err)
- }
- }
return c
}
View
32 conn.go
@@ -5,10 +5,22 @@ import (
"encoding/binary"
"github.com/kr/pretty.go"
"goprotobuf.googlecode.com/hg/proto"
+ "http"
"io"
"log"
"net"
"os"
+ "rand"
+ "strings"
+)
+
+
+var (
+ uriPrefix = "doozer:?"
+)
+
+var (
+ ErrInvalidUri = os.NewError("invalid uri")
)
@@ -52,6 +64,26 @@ func Dial(addr string) (*Conn, os.Error) {
}
+func DialUri(uri string) (*Conn, os.Error) {
+ if !strings.HasPrefix(uri, uriPrefix) {
+ return nil, ErrInvalidUri
+ }
+
+ q := uri[len(uriPrefix):]
+ p, err := http.ParseQuery(q)
+ if err != nil {
+ return nil, err
+ }
+
+ addrs, ok := p["ca"]
+ if !ok {
+ return nil, ErrInvalidUri
+ }
+
+ c := Dial(addrs[rand.Int()%len(addrs)])
+}
+
+
func (c *Conn) call(t *txn) os.Error {
t.done = make(chan bool)
select {

0 comments on commit e04d786

Please sign in to comment.
Something went wrong with that request. Please try again.