Skip to content

Commit

Permalink
Merge pull request #105 from devfeel/develop
Browse files Browse the repository at this point in the history
Version 1.4.6 BUG Fixed & dotweb.Version
  • Loading branch information
devfeel committed Jan 21, 2018
2 parents 9d628d2 + f348c80 commit 73a14f5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
12 changes: 8 additions & 4 deletions README.md
Expand Up @@ -272,15 +272,19 @@ type NotFoundHandle func(http.ResponseWriter, *http.Request)
websocket - golang.org/x/net/websocket
<br>
redis - github.com/garyburd/redigo/redis

<br>
yaml - gopkg.in/yaml.v2

## 相关项目
#### <a href="https://github.com/devfeel/tokenserver" target="_blank">TokenServer</a>
项目简介:token服务,提供token一致性服务以及相关的全局ID生成服务等

#### <a href="https://github.com/devfeel/longweb" target="_blank">LongWeb</a>
项目简介:http长连接网关服务,提供Websocket及长轮询服务

#### <a href="https://github.com/yulibaozi/yulibaozi.com" target="_blank">yulibaozi.com</a>
项目简介:基于dotweb与mapper的一款go的博客程序

#### <a href="https://github.com/devfeel/tokenserver" target="_blank">TokenServer</a>
项目简介:token服务,提供token一致性服务以及相关的全局ID生成服务等

## 贡献名单
目前已经有几位朋友在为框架一起做努力,我们将在合适的时间向大家展现,谢谢他们的支持!

Expand Down
5 changes: 5 additions & 0 deletions consts.go
@@ -1,5 +1,10 @@
package dotweb

//dotweb const
const (
Version = "1.4.5.1"
)

//Log define
const (
LogTarget_Default = "dotweb_default"
Expand Down
23 changes: 10 additions & 13 deletions uploadfile.go
Expand Up @@ -3,6 +3,7 @@ package dotweb
import (
"bytes"
"errors"
"io"
"mime/multipart"
"os"
"path/filepath"
Expand All @@ -14,7 +15,6 @@ type UploadFile struct {
fileExt string //file extensions
fileName string
fileSize int64
content []byte
}

func NewUploadFile(file multipart.File, header *multipart.FileHeader) *UploadFile {
Expand All @@ -23,7 +23,6 @@ func NewUploadFile(file multipart.File, header *multipart.FileHeader) *UploadFil
Header: header,
fileName: header.Filename,
fileExt: filepath.Ext(header.Filename), //update for issue #99
content: parseFileToBytes(file),
}
}

Expand All @@ -47,8 +46,10 @@ func (f *UploadFile) Size() int64 {
return f.fileSize
}

//save file in server-local with filename
func (f *UploadFile) SaveFile(fileName string) (size int, err error) {
// SaveFile save file in server-local with filename
// special:
// if you SaveFile, it's will cause empty data when use ReadBytes
func (f *UploadFile) SaveFile(fileName string) (size int64, err error) {
size = 0
if fileName == "" {
return size, errors.New("filename not allow empty")
Expand All @@ -59,9 +60,7 @@ func (f *UploadFile) SaveFile(fileName string) (size int, err error) {
return size, err
}
defer fileWriter.Close()
f.File.Read(f.content)
//size, err = io.Copy(fileWriter, f.File)
size, err = fileWriter.Write(f.content)
size, err = io.Copy(fileWriter, f.File)
return size, err
}

Expand All @@ -71,12 +70,10 @@ func (f *UploadFile) GetFileExt() string {
}

// Bytes returns a slice of byte hoding the UploadFile.File
func (f *UploadFile) Bytes() []byte {
return f.content
}

func parseFileToBytes(file multipart.File) []byte {
// special:
// if you read bytes, it's will cause empty data in UploadFile.File, so you use SaveFile will no any data to save
func (f *UploadFile) ReadBytes() []byte {
buf := new(bytes.Buffer)
buf.ReadFrom(file)
buf.ReadFrom(f.File)
return buf.Bytes()
}
6 changes: 6 additions & 0 deletions version.MD
@@ -1,5 +1,11 @@
## dotweb版本记录:

#### Version 1.4.6
* BUG Fixed: UploadFile废弃Bytes接口,新增ReadBytes接口,用于返回上传文件本身
* 需要特别注意,由于io.read具有一次性特性,UploadFile.SaveFile与UploadFile.ReadBytes只能使用其中一个,另外一个将无法正常获取数据
* 增加dotweb.Version,用于输出框架版本号
* 2018-01-21 09:00

#### Version 1.4.5
* 新增yaml格式配置文件支持,具体参考 example/config/dotweb.yaml
* config新增UnmarshalYaml\MarshalYaml\MarshalYamlString,提供针对Yaml的常规处理
Expand Down

0 comments on commit 73a14f5

Please sign in to comment.