Skip to content

Commit

Permalink
update #82 send-file demo
Browse files Browse the repository at this point in the history
  • Loading branch information
guonaihong committed Nov 9, 2019
1 parent 95934b6 commit 781462f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 25 deletions.
51 changes: 51 additions & 0 deletions _example/14-send-file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package main

import (
"bytes"
"fmt"
"github.com/gin-gonic/gin"
"github.com/guonaihong/gout"
"io"
"os"
"time"
)

func server() {
router := gin.New()
router.POST("/send/file", func(c *gin.Context) {
var file bytes.Buffer
io.Copy(&file, c.Request.Body)
fmt.Printf("server:file size = %d\n", file.Len())
})

router.Run()
}

func main() {
go server()
time.Sleep(time.Millisecond * 500) //sleep下等服务端真正起好

fmt.Printf("=====3.=====send file========\n")
fd, err := os.Open("./14-send-file.go")
if err != nil {
fmt.Printf("%s\n", err)
return
}
defer fd.Close()

err = gout.POST(":8080/send/file").
SetBody(fd). // send file
Do()

if err != nil {
fmt.Printf("%s\n", err)
return
}

fi, err := fd.Stat()
if err != nil {
return
}

fmt.Printf("client:file size:%d\n", fi.Size())
}
24 changes: 0 additions & 24 deletions _example/send-file.go

This file was deleted.

2 changes: 1 addition & 1 deletion group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestGroupNew(t *testing.T) {

type data struct {
Id int `json:"id" xml:"id"`
Data string `json:"data xml:"data""`
Data string `json:"data" xml:"data"`
}

type BindTest struct {
Expand Down

0 comments on commit 781462f

Please sign in to comment.