diff --git a/db.go b/db.go index 1baace5..020668a 100644 --- a/db.go +++ b/db.go @@ -428,7 +428,9 @@ func (this *HoTimeDB) Select(table string, qu ...interface{}) []Map { qs = append(qs, resWhere...) res := this.Query(query, qs...) - + if res == nil { + return []Map{} + } return res } diff --git a/dri/download/download.go b/dri/download/download.go new file mode 100644 index 0000000..1ef1e19 --- /dev/null +++ b/dri/download/download.go @@ -0,0 +1,35 @@ +package download + +import ( + "bytes" + "go.hoteas.com/hotime" + "io" + "io/ioutil" + "net/http" + "os" +) + +//下载文件 +func Down(url, path, name string) bool { + + os.MkdirAll(path, os.ModeDir) + if hotime.Substr(path, len(path)-1, len(path)) != "/" { + path = path + "/" + } + out, err := os.Create(path + name) + e := hotime.Error{} + if err != nil { + e.SetError(err) + return false + } + defer out.Close() + resp, err := http.Get(url) + defer resp.Body.Close() + pix, err := ioutil.ReadAll(resp.Body) + _, err = io.Copy(out, bytes.NewReader(pix)) + if err != nil { + e.SetError(err) + return false + } + return true +}