正文
要求在頁面查詢到5000條數據,為了方便插入,用shell腳本寫curl命令調用自己寫的代碼接口;
腳本如下:
#!/bin/bash
a=0
while [ $a -le 10 ]; do
# length of ts is 13 required,Through the following way like this
ts=`date +%s%N`
ts=${ts:0:13}
json='{"name" : "'$1$a'", "age" : '$2', "ts" : '$ts'}'
a=$((a+1))
curl -k -H 'Content-Type:application/json;charset=utf-8' http://192.168.2.5:8080 -X POST -d "'$json'"
done
執行腳本
sh batch_curl.sh gege 21
執行結果
該接口是用go語言提供的demo接口:如下:
- 目錄結構:
- app.conf
copyrequestbody = true
- controller.go
package controller
import (
"github.com/astaxie/beego"
"fmt"
)
type SayHelloController struct {
beego.Controller
}
func (this *SayHelloController) SayHello(){
fmt.Println("RequestBody is ", string(this.Ctx.Input.RequestBody))
this.Ctx.Output.Header("Content-type", "application/json;charset=utf-8")
this.Ctx.Output.SetStatus(200)
this.Ctx.Output.Body(this.Ctx.Input.RequestBody)
}
- router.go
package router
import (
"github.com/astaxie/beego"
"sayHello/controller"
)
var hello = controller.SayHelloController{}
func init() {
beego.Router("/", &hello, "POST:SayHello")
}
- main.go
package main
import (
"github.com/astaxie/beego"
_ "sayHello/router"
"fmt"
)
func main() {
fmt.Println(beego.BConfig.CopyRequestBody)
beego.Run()
}
本公眾號免費提供csdn下載服務,海量IT學習資源,如果你准備入IT坑,勵志成為優秀的程序猿,那么這些資源很適合你,包括但不限於java、go、python、springcloud、elk、嵌入式 、大數據、面試資料、前端 等資源。同時我們組建了一個技術交流群,里面有很多大佬,會不定時分享技術文章,如果你想來一起學習提高,可以公眾號后台回復【2】,免費邀請加技術交流群互相學習提高,會不定期分享編程IT相關資源。
掃碼關注,精彩內容第一時間推給你