Work with latest release of Go. No code changes.

This commit is contained in:
Brad Fitzpatrick 2010-09-07 22:02:20 -07:00
parent ffce0fe9fe
commit b64d6607e8
10 changed files with 7 additions and 96 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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
}

View File

@ -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;
}

View File

@ -2,6 +2,4 @@
mkdir /tmp/camliroot
export CAMLI_PASSWORD=foo
gofr && ./camlistored
make && ./camlistored

View File

@ -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
}

View File

@ -1 +0,0 @@
_obj

View File

@ -1,7 +0,0 @@
include $(GOROOT)/src/Make.$(GOARCH)
TARG=util
GOFILES=tee.go
include $(GOROOT)/src/Make.pkg

View File

@ -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}
}

View File

@ -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())
}
}