2 Star 0 Fork 338

hxchjm / go-zero

forked from kevwan / go-zero 
Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
main.go 1.16 KB
Copy Edit Raw Blame History
kevwan authored 2020-08-08 16:40 . update package reference
package main
import (
"flag"
"math"
"net/http"
"time"
"github.com/tal-tech/go-zero/core/logx"
"github.com/tal-tech/go-zero/core/service"
"github.com/tal-tech/go-zero/rest"
"github.com/tal-tech/go-zero/rest/httpx"
)
var (
port = flag.Int("port", 3333, "the port to listen")
timeout = flag.Int64("timeout", 1000, "timeout of milliseconds")
cpu = flag.Int64("cpu", 500, "cpu threshold")
)
type Request struct {
User string `form:"user,optional"`
}
func handle(w http.ResponseWriter, r *http.Request) {
var req Request
err := httpx.Parse(r, &req)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
var result float64
for i := 0; i < 30000; i++ {
result += math.Sqrt(float64(i))
}
time.Sleep(time.Millisecond * 5)
httpx.OkJson(w, result)
}
func main() {
flag.Parse()
logx.Disable()
engine := rest.MustNewServer(rest.RestConf{
ServiceConf: service.ServiceConf{
Log: logx.LogConf{
Mode: "console",
},
},
Port: *port,
Timeout: *timeout,
CpuThreshold: *cpu,
})
defer engine.Stop()
engine.AddRoute(rest.Route{
Method: http.MethodGet,
Path: "/",
Handler: handle,
})
engine.Start()
}
Go
1
https://gitee.com/hxchjm/go-zero.git
git@gitee.com:hxchjm/go-zero.git
hxchjm
go-zero
go-zero
3eb88c4e4bf1

Search