加入响应时间

This commit is contained in:
lingling 2023-04-01 14:51:08 +08:00
parent 313b4c747d
commit e343a50003
1 changed files with 7 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package main
import ( import (
"net/http" "net/http"
"time"
"github.com/idoubi/goz" "github.com/idoubi/goz"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
@ -15,8 +16,9 @@ type server struct {
type result struct { type result struct {
// 通过json标签指定json字段名 // 通过json标签指定json字段名
Sataus int `json:"sataus"` Sataus int `json:"sataus"`
Code int `json:"code"` Code int `json:"code"`
Time string `json:"time"`
} }
func main() { func main() {
@ -41,7 +43,10 @@ func textserver(c echo.Context) error {
// 通过结构体对象就可以访问json参数 // 通过结构体对象就可以访问json参数
json := new(result) json := new(result)
json.Code = http.StatusOK json.Code = http.StatusOK
start := time.Now()
json.Sataus = text_url(u.Url) json.Sataus = text_url(u.Url)
elapsed := time.Since(start)
json.Time = elapsed.String()
return c.JSON(http.StatusOK, json) return c.JSON(http.StatusOK, json)
} }
func text_url(url string) int { func text_url(url string) int {