1234567891011121314151617181920212223242526272829303132333435363738 |
- package util
- import (
- "bytes"
- "fmt"
- "io"
- "io/ioutil"
- "net/http"
- "ordonnance/logger"
- "os"
- )
- func ReadFile(fileName string) (data []byte, err error) {
- f, err := os.OpenFile(fileName, os.O_RDONLY, 0600)
- defer f.Close()
- if err != nil {
- return
- } else {
- data, err = ioutil.ReadAll(f)
- return
- }
- }
- // 下载头像
- func DownLoadHeadImg(uid int, path string) {
- resp, err := http.Get(path)
- if !logger.LogErr(err, "DownLoadHeadImg %d", uid) {
- return
- }
- body, _ := ioutil.ReadAll(resp.Body)
- destPath := fmt.Sprintf("./uploads/head/%d.jpg", uid)
- out, err1 := os.Create(destPath)
- if !logger.LogErr(err1, "create file") {
- return
- }
- io.Copy(out, bytes.NewReader(body))
- out.Close()
- }
|