Browse Source
compatible with Go1
compatible with Go1
git-svn-id: https://weed-fs.googlecode.com/svn/trunk@46 282b0af5-e82d-9cf1-ede4-77906d7719d0pull/2/head
chris.lu@gmail.com
13 years ago
17 changed files with 148 additions and 693 deletions
-
19weed-fs/build
-
39weed-fs/src/cmd/weedmaster/Makefile
-
90weed-fs/src/cmd/weedmaster/weedmaster.go
-
37weed-fs/src/cmd/weedvolume/Makefile
-
37weed-fs/src/cmd/weedvolume/fix_volume_index/Makefile
-
59weed-fs/src/cmd/weedvolume/fix_volume_index/fix_volume_index.go
-
168weed-fs/src/cmd/weedvolume/weedvolume.go
-
36weed-fs/src/pkg/directory/Makefile
-
12weed-fs/src/pkg/directory/file_id.go
-
23weed-fs/src/pkg/directory/volume_mapping.go
-
37weed-fs/src/pkg/storage/Makefile
-
75weed-fs/src/pkg/storage/needle.go
-
36weed-fs/src/pkg/storage/needle_map.go
-
82weed-fs/src/pkg/storage/store.go
-
15weed-fs/src/pkg/storage/volume.go
-
32weed-fs/src/pkg/util/Makefile
-
34weed-fs/src/pkg/util/post.go
@ -1,19 +0,0 @@ |
|||
# Build script generated by gb: http://go-gb.googlecode.com |
|||
# gb provides configuration-free building and distributing |
|||
|
|||
echo "Build script generated by gb: http://go-gb.googlecode.com" |
|||
if [ "$1" = "goinstall" ]; then |
|||
echo Running goinstall \ |
|||
|
|||
else |
|||
echo Building \ |
|||
&& echo "(in src/pkg/util)" gomake $1 && cd src/pkg/util && gomake $1 && cd - > /dev/null \ |
|||
&& echo "(in src/pkg/storage)" gomake $1 && cd src/pkg/storage && gomake $1 && cd - > /dev/null \ |
|||
&& echo "(in src/cmd/weedvolume/fix_volume_index)" gomake $1 && cd src/cmd/weedvolume/fix_volume_index && gomake $1 && cd - > /dev/null \ |
|||
&& echo "(in src/cmd/weedvolume)" gomake $1 && cd src/cmd/weedvolume && gomake $1 && cd - > /dev/null \ |
|||
&& echo "(in src/pkg/directory)" gomake $1 && cd src/pkg/directory && gomake $1 && cd - > /dev/null \ |
|||
&& echo "(in src/cmd/weedmaster)" gomake $1 && cd src/cmd/weedmaster && gomake $1 && cd - > /dev/null \ |
|||
|
|||
fi |
|||
|
|||
# The makefiles above are invoked in topological dependence order |
@ -1,39 +0,0 @@ |
|||
# Makefile generated by gb: http://go-gb.googlecode.com
|
|||
# gb provides configuration-free building and distributing
|
|||
|
|||
include $(GOROOT)/src/Make.inc |
|||
|
|||
TARG=weedmaster |
|||
GOFILES=\
|
|||
weedmaster.go\
|
|||
|
|||
# gb: this is the local install
|
|||
GBROOT=../../.. |
|||
|
|||
# gb: compile/link against local install
|
|||
GCIMPORTS+= -I $(GBROOT)/_obj |
|||
LDIMPORTS+= -L $(GBROOT)/_obj |
|||
|
|||
# gb: compile/link against GOPATH entries
|
|||
GOPATHSEP=: |
|||
ifeq ($(GOHOSTOS),windows) |
|||
GOPATHSEP=; |
|||
endif |
|||
GCIMPORTS+=-I $(subst $(GOPATHSEP),/pkg/$(GOOS)_$(GOARCH) -I , $(GOPATH))/pkg/$(GOOS)_$(GOARCH) |
|||
LDIMPORTS+=-L $(subst $(GOPATHSEP),/pkg/$(GOOS)_$(GOARCH) -L , $(GOPATH))/pkg/$(GOOS)_$(GOARCH) |
|||
|
|||
# gb: default target is in GBROOT this way
|
|||
command: |
|||
|
|||
include $(GOROOT)/src/Make.cmd |
|||
|
|||
# gb: copy to local install
|
|||
$(GBROOT)/bin/$(TARG): $(TARG) |
|||
mkdir -p $(dir $@); cp -f $< $@ |
|||
command: $(GBROOT)/bin/$(TARG) |
|||
|
|||
# gb: local dependencies
|
|||
$(TARG): $(GBROOT)/_obj/storage.a |
|||
|
|||
$(TARG): $(GBROOT)/_obj/directory.a |
|||
|
@ -1,90 +0,0 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"storage" |
|||
"directory" |
|||
"flag" |
|||
"fmt" |
|||
"http" |
|||
"json" |
|||
"log" |
|||
"strconv" |
|||
"strings" |
|||
) |
|||
|
|||
var ( |
|||
port = flag.Int("port", 9333, "http listen port") |
|||
metaFolder = flag.String("mdir", "/tmp", "data directory to store mappings") |
|||
capacity = flag.Int("capacity", 100, "maximum number of volumes to hold") |
|||
mapper *directory.Mapper |
|||
IsDebug = flag.Bool("debug", false, "verbose debug information") |
|||
volumeSizeLimitMB = flag.Uint("volumeSizeLimitMB", 32*1024, "Default Volume Size in MegaBytes") |
|||
) |
|||
|
|||
func dirLookupHandler(w http.ResponseWriter, r *http.Request) { |
|||
vid := r.FormValue("volumeId") |
|||
commaSep := strings.Index(vid, ",") |
|||
if commaSep > 0 { |
|||
vid = vid[0:commaSep] |
|||
} |
|||
volumeId, _ := strconv.Atoui64(vid) |
|||
machine, e := mapper.Get(uint32(volumeId)) |
|||
if e == nil { |
|||
writeJson(w, r, machine.Server) |
|||
} else { |
|||
log.Println("Invalid volume id", volumeId) |
|||
writeJson(w, r, map[string]string{"error": "volume id " + strconv.Uitoa64(volumeId) + " not found"}) |
|||
} |
|||
} |
|||
func dirAssignHandler(w http.ResponseWriter, r *http.Request) { |
|||
fid, machine, err := mapper.PickForWrite() |
|||
if err == nil { |
|||
writeJson(w, r, map[string]string{"fid": fid, "url": machine.Url}) |
|||
} else { |
|||
log.Println(err) |
|||
writeJson(w, r, map[string]string{"error": err.String()}) |
|||
} |
|||
} |
|||
func dirJoinHandler(w http.ResponseWriter, r *http.Request) { |
|||
s := r.RemoteAddr[0:strings.Index(r.RemoteAddr, ":")+1] + r.FormValue("port") |
|||
publicUrl := r.FormValue("publicUrl") |
|||
volumes := new([]storage.VolumeInfo) |
|||
json.Unmarshal([]byte(r.FormValue("volumes")), volumes) |
|||
if *IsDebug { |
|||
log.Println(s, "volumes", r.FormValue("volumes")) |
|||
} |
|||
mapper.Add(*directory.NewMachine(s, publicUrl, *volumes)) |
|||
} |
|||
func dirStatusHandler(w http.ResponseWriter, r *http.Request) { |
|||
writeJson(w, r, mapper) |
|||
} |
|||
func writeJson(w http.ResponseWriter, r *http.Request, obj interface{}) { |
|||
w.Header().Set("Content-Type", "application/javascript") |
|||
bytes, _ := json.Marshal(obj) |
|||
callback := r.FormValue("callback") |
|||
if callback == "" { |
|||
w.Write(bytes) |
|||
} else { |
|||
w.Write([]uint8(callback)) |
|||
w.Write([]uint8("(")) |
|||
fmt.Fprint(w, string(bytes)) |
|||
w.Write([]uint8(")")) |
|||
} |
|||
} |
|||
|
|||
func main() { |
|||
flag.Parse() |
|||
log.Println("Volume Size Limit is", *volumeSizeLimitMB, "MB") |
|||
mapper = directory.NewMapper(*metaFolder, "directory", uint64(*volumeSizeLimitMB)*1024*1024) |
|||
http.HandleFunc("/dir/assign", dirAssignHandler) |
|||
http.HandleFunc("/dir/lookup", dirLookupHandler) |
|||
http.HandleFunc("/dir/join", dirJoinHandler) |
|||
http.HandleFunc("/dir/status", dirStatusHandler) |
|||
|
|||
log.Println("Start directory service at http://127.0.0.1:" + strconv.Itoa(*port)) |
|||
e := http.ListenAndServe(":"+strconv.Itoa(*port), nil) |
|||
if e != nil { |
|||
log.Fatalf("Fail to start:", e.String()) |
|||
} |
|||
|
|||
} |
@ -1,37 +0,0 @@ |
|||
# Makefile generated by gb: http://go-gb.googlecode.com
|
|||
# gb provides configuration-free building and distributing
|
|||
|
|||
include $(GOROOT)/src/Make.inc |
|||
|
|||
TARG=weedvolume |
|||
GOFILES=\
|
|||
weedvolume.go\
|
|||
|
|||
# gb: this is the local install
|
|||
GBROOT=../../.. |
|||
|
|||
# gb: compile/link against local install
|
|||
GCIMPORTS+= -I $(GBROOT)/_obj |
|||
LDIMPORTS+= -L $(GBROOT)/_obj |
|||
|
|||
# gb: compile/link against GOPATH entries
|
|||
GOPATHSEP=: |
|||
ifeq ($(GOHOSTOS),windows) |
|||
GOPATHSEP=; |
|||
endif |
|||
GCIMPORTS+=-I $(subst $(GOPATHSEP),/pkg/$(GOOS)_$(GOARCH) -I , $(GOPATH))/pkg/$(GOOS)_$(GOARCH) |
|||
LDIMPORTS+=-L $(subst $(GOPATHSEP),/pkg/$(GOOS)_$(GOARCH) -L , $(GOPATH))/pkg/$(GOOS)_$(GOARCH) |
|||
|
|||
# gb: default target is in GBROOT this way
|
|||
command: |
|||
|
|||
include $(GOROOT)/src/Make.cmd |
|||
|
|||
# gb: copy to local install
|
|||
$(GBROOT)/bin/$(TARG): $(TARG) |
|||
mkdir -p $(dir $@); cp -f $< $@ |
|||
command: $(GBROOT)/bin/$(TARG) |
|||
|
|||
# gb: local dependencies
|
|||
$(TARG): $(GBROOT)/_obj/storage.a |
|||
|
@ -1,37 +0,0 @@ |
|||
# Makefile generated by gb: http://go-gb.googlecode.com
|
|||
# gb provides configuration-free building and distributing
|
|||
|
|||
include $(GOROOT)/src/Make.inc |
|||
|
|||
TARG=fix_volume_index |
|||
GOFILES=\
|
|||
fix_volume_index.go\
|
|||
|
|||
# gb: this is the local install
|
|||
GBROOT=../../../.. |
|||
|
|||
# gb: compile/link against local install
|
|||
GCIMPORTS+= -I $(GBROOT)/_obj |
|||
LDIMPORTS+= -L $(GBROOT)/_obj |
|||
|
|||
# gb: compile/link against GOPATH entries
|
|||
GOPATHSEP=: |
|||
ifeq ($(GOHOSTOS),windows) |
|||
GOPATHSEP=; |
|||
endif |
|||
GCIMPORTS+=-I $(subst $(GOPATHSEP),/pkg/$(GOOS)_$(GOARCH) -I , $(GOPATH))/pkg/$(GOOS)_$(GOARCH) |
|||
LDIMPORTS+=-L $(subst $(GOPATHSEP),/pkg/$(GOOS)_$(GOARCH) -L , $(GOPATH))/pkg/$(GOOS)_$(GOARCH) |
|||
|
|||
# gb: default target is in GBROOT this way
|
|||
command: |
|||
|
|||
include $(GOROOT)/src/Make.cmd |
|||
|
|||
# gb: copy to local install
|
|||
$(GBROOT)/bin/$(TARG): $(TARG) |
|||
mkdir -p $(dir $@); cp -f $< $@ |
|||
command: $(GBROOT)/bin/$(TARG) |
|||
|
|||
# gb: local dependencies
|
|||
$(TARG): $(GBROOT)/_obj/storage.a |
|||
|
@ -1,59 +0,0 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"storage" |
|||
"flag" |
|||
"log" |
|||
"os" |
|||
"path" |
|||
"strconv" |
|||
) |
|||
|
|||
var ( |
|||
dir = flag.String("dir", "/tmp", "data directory to store files") |
|||
volumeId = flag.Int("volumeId", -1, "a non-negative volume id. The volume should already exist in the dir. The volume index file should not exist.") |
|||
IsDebug = flag.Bool("debug", false, "enable debug mode") |
|||
|
|||
store *storage.Store |
|||
) |
|||
|
|||
func main() { |
|||
flag.Parse() |
|||
|
|||
if *volumeId == -1 { |
|||
flag.Usage() |
|||
return |
|||
} |
|||
|
|||
fileName := strconv.Itoa(*volumeId) |
|||
dataFile, e := os.OpenFile(path.Join(*dir, fileName+".dat"), os.O_RDONLY, 0644) |
|||
if e != nil { |
|||
log.Fatalf("Read Volume [ERROR] %s\n", e) |
|||
} |
|||
defer dataFile.Close() |
|||
indexFile, ie := os.OpenFile(path.Join(*dir, fileName+".idx"), os.O_WRONLY|os.O_CREATE, 0644) |
|||
if ie != nil { |
|||
log.Fatalf("Create Volume Index [ERROR] %s\n", ie) |
|||
} |
|||
defer indexFile.Close() |
|||
|
|||
//skip the volume super block
|
|||
dataFile.Seek(storage.SuperBlockSize, 0) |
|||
|
|||
n, length := storage.ReadNeedle(dataFile) |
|||
nm := storage.NewNeedleMap(indexFile) |
|||
offset := uint32(storage.SuperBlockSize) |
|||
for n != nil { |
|||
if *IsDebug { |
|||
log.Println("key", n.Key, "volume offset", offset, "data_size", n.Size, "length", length) |
|||
} |
|||
if n.Size > 0 { |
|||
count, pe := nm.Put(n.Key, offset/8, n.Size) |
|||
if *IsDebug { |
|||
log.Println("saved", count, "with error", pe) |
|||
} |
|||
} |
|||
offset += length |
|||
n, length = storage.ReadNeedle(dataFile) |
|||
} |
|||
} |
@ -1,168 +0,0 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"storage" |
|||
"flag" |
|||
"fmt" |
|||
"http" |
|||
"json" |
|||
"log" |
|||
"mime" |
|||
"rand" |
|||
"strconv" |
|||
"strings" |
|||
"time" |
|||
) |
|||
|
|||
var ( |
|||
port = flag.Int("port", 8080, "http listen port") |
|||
chunkFolder = flag.String("dir", "/tmp", "data directory to store files") |
|||
volumes = flag.String("volumes", "0,1-3,4", "comma-separated list of volume ids or range of ids") |
|||
publicUrl = flag.String("publicUrl", "localhost:8080", "public url to serve data read") |
|||
metaServer = flag.String("mserver", "localhost:9333", "master directory server to store mappings") |
|||
IsDebug = flag.Bool("debug", false, "enable debug mode") |
|||
pulse = flag.Int("pulseSeconds", 5, "number of seconds between heartbeats") |
|||
|
|||
store *storage.Store |
|||
) |
|||
|
|||
func statusHandler(w http.ResponseWriter, r *http.Request) { |
|||
writeJson(w, r, store.Status()) |
|||
} |
|||
func addVolumeHandler(w http.ResponseWriter, r *http.Request) { |
|||
store.AddVolume(r.FormValue("volume")) |
|||
writeJson(w, r, store.Status()) |
|||
} |
|||
func storeHandler(w http.ResponseWriter, r *http.Request) { |
|||
switch r.Method { |
|||
case "GET": |
|||
GetHandler(w, r) |
|||
case "DELETE": |
|||
DeleteHandler(w, r) |
|||
case "POST": |
|||
PostHandler(w, r) |
|||
} |
|||
} |
|||
func GetHandler(w http.ResponseWriter, r *http.Request) { |
|||
n := new(storage.Needle) |
|||
vid, fid, ext := parseURLPath(r.URL.Path) |
|||
volumeId, _ := strconv.Atoui64(vid) |
|||
n.ParsePath(fid) |
|||
|
|||
if *IsDebug { |
|||
log.Println("volume", volumeId, "reading", n) |
|||
} |
|||
cookie := n.Cookie |
|||
count, e := store.Read(volumeId, n) |
|||
if *IsDebug { |
|||
log.Println("read bytes", count, "error", e) |
|||
} |
|||
if n.Cookie != cookie { |
|||
log.Println("request with unmaching cookie from ", r.RemoteAddr, "agent", r.UserAgent()) |
|||
return |
|||
} |
|||
if ext != "" { |
|||
w.Header().Set("Content-Type", mime.TypeByExtension(ext)) |
|||
} |
|||
w.Write(n.Data) |
|||
} |
|||
func PostHandler(w http.ResponseWriter, r *http.Request) { |
|||
vid, _, _ := parseURLPath(r.URL.Path) |
|||
volumeId, e := strconv.Atoui64(vid) |
|||
if e != nil { |
|||
writeJson(w, r, e) |
|||
} else { |
|||
ret := store.Write(volumeId, storage.NewNeedle(r)) |
|||
m := make(map[string]uint32) |
|||
m["size"] = ret |
|||
writeJson(w, r, m) |
|||
} |
|||
} |
|||
func DeleteHandler(w http.ResponseWriter, r *http.Request) { |
|||
n := new(storage.Needle) |
|||
vid, fid, _ := parseURLPath(r.URL.Path) |
|||
volumeId, _ := strconv.Atoui64(vid) |
|||
n.ParsePath(fid) |
|||
|
|||
if *IsDebug { |
|||
log.Println("deleting", n) |
|||
} |
|||
|
|||
cookie := n.Cookie |
|||
count, ok := store.Read(volumeId, n) |
|||
|
|||
if ok!=nil { |
|||
m := make(map[string]uint32) |
|||
m["size"] = 0 |
|||
writeJson(w, r, m) |
|||
return |
|||
} |
|||
|
|||
if n.Cookie != cookie { |
|||
log.Println("delete with unmaching cookie from ", r.RemoteAddr, "agent", r.UserAgent()) |
|||
return |
|||
} |
|||
|
|||
n.Size = 0 |
|||
store.Delete(volumeId, n) |
|||
m := make(map[string]uint32) |
|||
m["size"] = uint32(count) |
|||
writeJson(w, r, m) |
|||
} |
|||
func writeJson(w http.ResponseWriter, r *http.Request, obj interface{}) { |
|||
w.Header().Set("Content-Type", "application/javascript") |
|||
bytes, _ := json.Marshal(obj) |
|||
callback := r.FormValue("callback") |
|||
if callback == "" { |
|||
w.Write(bytes) |
|||
} else { |
|||
w.Write([]uint8(callback)) |
|||
w.Write([]uint8("(")) |
|||
fmt.Fprint(w, string(bytes)) |
|||
w.Write([]uint8(")")) |
|||
} |
|||
//log.Println("JSON Response", string(bytes))
|
|||
} |
|||
func parseURLPath(path string) (vid, fid, ext string) { |
|||
sepIndex := strings.LastIndex(path, "/") |
|||
commaIndex := strings.LastIndex(path[sepIndex:], ",") |
|||
if commaIndex <= 0 { |
|||
log.Println("unknown file id", path[sepIndex+1:]) |
|||
return |
|||
} |
|||
dotIndex := strings.LastIndex(path[sepIndex:], ".") |
|||
vid = path[sepIndex+1 : commaIndex] |
|||
fid = path[commaIndex+1:] |
|||
ext = "" |
|||
if dotIndex > 0 { |
|||
fid = path[commaIndex+1 : dotIndex] |
|||
ext = path[dotIndex+1:] |
|||
} |
|||
return |
|||
} |
|||
|
|||
func main() { |
|||
flag.Parse() |
|||
//TODO: now default to 1G, this value should come from server?
|
|||
store = storage.NewStore(*port, *publicUrl, *chunkFolder, *volumes) |
|||
defer store.Close() |
|||
http.HandleFunc("/", storeHandler) |
|||
http.HandleFunc("/status", statusHandler) |
|||
http.HandleFunc("/add_volume", addVolumeHandler) |
|||
|
|||
go func() { |
|||
for { |
|||
store.Join(*metaServer) |
|||
ns := int64(*pulse) * 1e9 |
|||
time.Sleep(ns + rand.Int63()%ns) |
|||
} |
|||
}() |
|||
log.Println("store joined at", *metaServer) |
|||
|
|||
log.Println("Start storage service at http://127.0.0.1:"+strconv.Itoa(*port), "public url", *publicUrl) |
|||
e := http.ListenAndServe(":"+strconv.Itoa(*port), nil) |
|||
if e != nil { |
|||
log.Fatalf("Fail to start:", e.String()) |
|||
} |
|||
|
|||
} |
@ -1,36 +0,0 @@ |
|||
# Makefile generated by gb: http://go-gb.googlecode.com
|
|||
# gb provides configuration-free building and distributing
|
|||
|
|||
include $(GOROOT)/src/Make.inc |
|||
|
|||
TARG=directory |
|||
GOFILES=\
|
|||
file_id.go\
|
|||
volume_mapping.go\
|
|||
|
|||
# gb: this is the local install
|
|||
GBROOT=../../.. |
|||
|
|||
# gb: compile/link against local install
|
|||
GCIMPORTS+= -I $(GBROOT)/_obj |
|||
LDIMPORTS+= -L $(GBROOT)/_obj |
|||
|
|||
# gb: compile/link against GOPATH entries
|
|||
GOPATHSEP=: |
|||
ifeq ($(GOHOSTOS),windows) |
|||
GOPATHSEP=; |
|||
endif |
|||
GCIMPORTS+=-I $(subst $(GOPATHSEP),/pkg/$(GOOS)_$(GOARCH) -I , $(GOPATH))/pkg/$(GOOS)_$(GOARCH) |
|||
LDIMPORTS+=-L $(subst $(GOPATHSEP),/pkg/$(GOOS)_$(GOARCH) -L , $(GOPATH))/pkg/$(GOOS)_$(GOARCH) |
|||
|
|||
# gb: copy to local install
|
|||
$(GBROOT)/_obj/$(TARG).a: _obj/$(TARG).a |
|||
mkdir -p $(dir $@); cp -f $< $@ |
|||
|
|||
package: $(GBROOT)/_obj/$(TARG).a |
|||
|
|||
include $(GOROOT)/src/Make.pkg |
|||
|
|||
# gb: local dependencies
|
|||
_obj/$(TARG).a: $(GBROOT)/_obj/storage.a |
|||
_obj/$(TARG).a: $(GBROOT)/_obj/util.a |
@ -1,37 +0,0 @@ |
|||
# Makefile generated by gb: http://go-gb.googlecode.com
|
|||
# gb provides configuration-free building and distributing
|
|||
|
|||
include $(GOROOT)/src/Make.inc |
|||
|
|||
TARG=storage |
|||
GOFILES=\
|
|||
needle.go\
|
|||
needle_map.go\
|
|||
store.go\
|
|||
volume.go\
|
|||
|
|||
# gb: this is the local install
|
|||
GBROOT=../../.. |
|||
|
|||
# gb: compile/link against local install
|
|||
GCIMPORTS+= -I $(GBROOT)/_obj |
|||
LDIMPORTS+= -L $(GBROOT)/_obj |
|||
|
|||
# gb: compile/link against GOPATH entries
|
|||
GOPATHSEP=: |
|||
ifeq ($(GOHOSTOS),windows) |
|||
GOPATHSEP=; |
|||
endif |
|||
GCIMPORTS+=-I $(subst $(GOPATHSEP),/pkg/$(GOOS)_$(GOARCH) -I , $(GOPATH))/pkg/$(GOOS)_$(GOARCH) |
|||
LDIMPORTS+=-L $(subst $(GOPATHSEP),/pkg/$(GOOS)_$(GOARCH) -L , $(GOPATH))/pkg/$(GOOS)_$(GOARCH) |
|||
|
|||
# gb: copy to local install
|
|||
$(GBROOT)/_obj/$(TARG).a: _obj/$(TARG).a |
|||
mkdir -p $(dir $@); cp -f $< $@ |
|||
|
|||
package: $(GBROOT)/_obj/$(TARG).a |
|||
|
|||
include $(GOROOT)/src/Make.pkg |
|||
|
|||
# gb: local dependencies
|
|||
_obj/$(TARG).a: $(GBROOT)/_obj/util.a |
@ -1,32 +0,0 @@ |
|||
# Makefile generated by gb: http://go-gb.googlecode.com
|
|||
# gb provides configuration-free building and distributing
|
|||
|
|||
include $(GOROOT)/src/Make.inc |
|||
|
|||
TARG=util |
|||
GOFILES=\
|
|||
bytes.go\
|
|||
post.go\
|
|||
|
|||
# gb: this is the local install
|
|||
GBROOT=../../.. |
|||
|
|||
# gb: compile/link against local install
|
|||
GCIMPORTS+= -I $(GBROOT)/_obj |
|||
LDIMPORTS+= -L $(GBROOT)/_obj |
|||
|
|||
# gb: compile/link against GOPATH entries
|
|||
GOPATHSEP=: |
|||
ifeq ($(GOHOSTOS),windows) |
|||
GOPATHSEP=; |
|||
endif |
|||
GCIMPORTS+=-I $(subst $(GOPATHSEP),/pkg/$(GOOS)_$(GOARCH) -I , $(GOPATH))/pkg/$(GOOS)_$(GOARCH) |
|||
LDIMPORTS+=-L $(subst $(GOPATHSEP),/pkg/$(GOOS)_$(GOARCH) -L , $(GOPATH))/pkg/$(GOOS)_$(GOARCH) |
|||
|
|||
# gb: copy to local install
|
|||
$(GBROOT)/_obj/$(TARG).a: _obj/$(TARG).a |
|||
mkdir -p $(dir $@); cp -f $< $@ |
|||
|
|||
package: $(GBROOT)/_obj/$(TARG).a |
|||
|
|||
include $(GOROOT)/src/Make.pkg |
@ -1,23 +1,23 @@ |
|||
package util |
|||
|
|||
import ( |
|||
"http" |
|||
"io/ioutil" |
|||
"url" |
|||
"log" |
|||
"io/ioutil" |
|||
"log" |
|||
"net/http" |
|||
"net/url" |
|||
) |
|||
|
|||
func Post(url string, values url.Values)[]byte{ |
|||
r, err := http.PostForm(url, values) |
|||
if err != nil { |
|||
log.Println("post:", err) |
|||
return nil |
|||
} |
|||
defer r.Body.Close() |
|||
b, err := ioutil.ReadAll(r.Body) |
|||
if err != nil { |
|||
log.Println("post:", err) |
|||
return nil |
|||
} |
|||
return b |
|||
func Post(url string, values url.Values) []byte { |
|||
r, err := http.PostForm(url, values) |
|||
if err != nil { |
|||
log.Println("post:", err) |
|||
return nil |
|||
} |
|||
defer r.Body.Close() |
|||
b, err := ioutil.ReadAll(r.Body) |
|||
if err != nil { |
|||
log.Println("post:", err) |
|||
return nil |
|||
} |
|||
return b |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue