diff --git a/blobserver/go/Makefile b/blobserver/go/Makefile index 1e9f2a9ce..b3267912e 100644 --- a/blobserver/go/Makefile +++ b/blobserver/go/Makefile @@ -1,8 +1,4 @@ -main: - echo "I've using gofr to build this now: http://bitbucket.org/kylelemons/gofr/wiki/Home" - exit 999 - -include $(GOROOT)/src/Make.$(GOARCH) +include $(GOROOT)/src/Make.inc TARG=camlistored GOFILES=\ @@ -14,6 +10,7 @@ GOFILES=\ http_util.go\ preupload.go\ temp_testing.go\ + range.go\ upload.go\ include $(GOROOT)/src/Make.cmd diff --git a/blobserver/go/auth.go b/blobserver/go/auth.go index b6e2faeca..1516f130a 100644 --- a/blobserver/go/auth.go +++ b/blobserver/go/auth.go @@ -17,7 +17,7 @@ func isAuthorized(req *http.Request) bool { if !present { return false } - matches := kBasicAuthPattern.MatchStrings(auth) + matches := kBasicAuthPattern.FindStringSubmatch(auth) if len(matches) != 2 { return false } diff --git a/blobserver/go/blobref.go b/blobserver/go/blobref.go index 0f763e9d9..707febbf7 100644 --- a/blobserver/go/blobref.go +++ b/blobserver/go/blobref.go @@ -29,7 +29,7 @@ func blobIfValid(hashname, digest string) *BlobRef { } func blobFromPattern(r *regexp.Regexp, s string) *BlobRef { - matches := r.MatchStrings(s) + matches := r.FindStringSubmatch(s) if len(matches) != 3 { return nil } diff --git a/blobserver/go/range.go b/blobserver/go/range.go index 83f624bfb..85eb5ea2e 100644 --- a/blobserver/go/range.go +++ b/blobserver/go/range.go @@ -29,7 +29,7 @@ func getRequestedRange(req *http.Request) *requestedRange { } func getRequestedRangeFromString(rrange string) *requestedRange { - matches := rangePattern.MatchStrings(rrange) + matches := rangePattern.FindStringSubmatch(rrange) if len(matches) == 0 { return wholeRange; } diff --git a/blobserver/go/run.sh b/blobserver/go/run.sh index e66d0fe20..4a37c3195 100755 --- a/blobserver/go/run.sh +++ b/blobserver/go/run.sh @@ -2,6 +2,4 @@ mkdir /tmp/camliroot export CAMLI_PASSWORD=foo -gofr && ./camlistored - - +make && ./camlistored diff --git a/blobserver/go/upload.go b/blobserver/go/upload.go index 22042f210..da81e29b4 100644 --- a/blobserver/go/upload.go +++ b/blobserver/go/upload.go @@ -8,11 +8,6 @@ import ( "os" ) -// For `make`: -//import "./util/_obj/util" -// For `gofr`: -import "util/util" - func handleMultiPartUpload(conn *http.Conn, req *http.Request) { if !(req.Method == "POST" && req.URL.Path == "/camli/upload") { badRequestError(conn, "Inconfigured handler.") @@ -77,7 +72,7 @@ func receiveBlob(blobRef *BlobRef, source io.Reader) (ok bool, err os.Error) { hash := blobRef.Hash() var written int64 - written, err = io.Copy(util.NewTee(hash, tempFile), source) + written, err = io.Copy(io.MultiWriter(hash, tempFile), source) if err != nil { return } diff --git a/blobserver/go/util/.gitignore b/blobserver/go/util/.gitignore deleted file mode 100644 index bcb5fce93..000000000 --- a/blobserver/go/util/.gitignore +++ /dev/null @@ -1 +0,0 @@ -_obj diff --git a/blobserver/go/util/Makefile b/blobserver/go/util/Makefile deleted file mode 100644 index 169c27ece..000000000 --- a/blobserver/go/util/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -include $(GOROOT)/src/Make.$(GOARCH) - -TARG=util -GOFILES=tee.go - -include $(GOROOT)/src/Make.pkg - diff --git a/blobserver/go/util/tee.go b/blobserver/go/util/tee.go deleted file mode 100644 index ba3cfe954..000000000 --- a/blobserver/go/util/tee.go +++ /dev/null @@ -1,34 +0,0 @@ -package util - -import ( - "io" - "os" -) - -type teeWriter struct { - writers []io.Writer -} - -// Writes to all writers in the tee. Note that the return value -// doesn't actually capture the failure state well, unable to convey -// where the error occurred and which writers got how much data. -// But on success, written == len(p) and err is nil. -func (t *teeWriter) Write(p []byte) (written int, err os.Error) { - for _, w := range t.writers { - nw, ew := w.Write(p) - if ew != nil { - err = ew - return - } - if nw != len(p) { - written = nw - err = io.ErrShortWrite - return - } - } - return len(p), nil -} - -func NewTee(writers ...io.Writer) io.Writer { - return &teeWriter{writers} -} diff --git a/blobserver/go/util/tee_test.go b/blobserver/go/util/tee_test.go deleted file mode 100644 index e889cf801..000000000 --- a/blobserver/go/util/tee_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package util - -import ( - "bytes" - "crypto/sha1" - "fmt" - "io" - "strings" - "testing" -) - -func TestTee(t *testing.T) { - sha1 := sha1.New() - sink := new(bytes.Buffer) - tee := NewTee(sha1, sink) - - sourceString := "My input text." - source := strings.NewReader(sourceString) - written, err := io.Copy(tee, source) - - if written != int64(len(sourceString)) { - t.Errorf("short write of %d, not %d", written, len(sourceString)) - } - - if err != nil { - t.Errorf("unexpected error: %v", err) - } - - sha1hex := fmt.Sprintf("%x", sha1.Sum()) - if sha1hex != "01cb303fa8c30a64123067c5aa6284ba7ec2d31b" { - t.Error("Bogus sha1 value") - } - - if sink.String() != sourceString { - t.Error("Unexpected sink output: %v", sink.String()) - } -}