|
@@ -5,14 +5,14 @@ import (
|
|
|
"gateway/core/node"
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
|
"github.com/gogf/gf/v2/net/ghttp"
|
|
|
- "github.com/gogf/gf/v2/util/guid"
|
|
|
+ "github.com/gogf/gf/v2/os/gproc"
|
|
|
"os"
|
|
|
"os/signal"
|
|
|
- "strings"
|
|
|
"syscall"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
-func main() {
|
|
|
+func main111() {
|
|
|
//node.NewNode().Register("usermodule", "8888", "http://127.0.0.1")
|
|
|
|
|
|
var serverCode string = "gatewayDemo"
|
|
@@ -25,13 +25,18 @@ func main() {
|
|
|
go func() {
|
|
|
server := g.Server()
|
|
|
server.SetPort(serverPort)
|
|
|
- server.BindHandler("POST:/gatewayDemo/{page}", func(r *ghttp.Request) {
|
|
|
- r.Response.Header().Set("deductNum", "6")
|
|
|
- r.Response.Header().Set("ids", strings.Join(getIdArr(20000), ","))
|
|
|
+ server.BindHandler("/gatewayDemo/{page}", func(r *ghttp.Request) {
|
|
|
+ //r.Response.Header().Set("deductNum", "6")
|
|
|
+ //r.Response.Header().Set("ids", strings.Join(getIdArr(20000), ","))
|
|
|
r.Response.Write(map[string]interface{}{
|
|
|
"code": 1,
|
|
|
"func": r.Get("page"),
|
|
|
- "body": r.GetBodyString(),
|
|
|
+ "param": map[string]interface{}{
|
|
|
+ "name": r.Get("name").String(),
|
|
|
+ "age": r.Get("age").Int64(),
|
|
|
+ "eId": r.Get("entId").Int64(),
|
|
|
+ "uId": r.Get("userId").String(),
|
|
|
+ },
|
|
|
})
|
|
|
})
|
|
|
server.Run()
|
|
@@ -43,12 +48,24 @@ func main() {
|
|
|
closeNotify()
|
|
|
}
|
|
|
|
|
|
-func getIdArr(count int) []string {
|
|
|
- r := make([]string, 0, count)
|
|
|
- for i := 0; i < count; i++ {
|
|
|
- r = append(r, guid.S())
|
|
|
- }
|
|
|
- //id := primitive.NewObjectID().String()
|
|
|
- //fmt.Println(id)
|
|
|
- return r
|
|
|
+func main() {
|
|
|
+ s := g.Server()
|
|
|
+ gc := ghttp.NewConfig()
|
|
|
+ gc.Graceful = true
|
|
|
+ gc.GracefulTimeout = 20
|
|
|
+ s.SetConfig(gc)
|
|
|
+ s.BindHandler("/", func(r *ghttp.Request) {
|
|
|
+ r.Response.Writeln("哈喽!")
|
|
|
+ })
|
|
|
+ s.BindHandler("/pid", func(r *ghttp.Request) {
|
|
|
+ r.Response.Writeln(gproc.Pid())
|
|
|
+ })
|
|
|
+ s.BindHandler("/sleep", func(r *ghttp.Request) {
|
|
|
+ r.Response.Writeln(gproc.Pid())
|
|
|
+ time.Sleep(10 * time.Second)
|
|
|
+ r.Response.Writeln(gproc.Pid())
|
|
|
+ })
|
|
|
+ s.EnableAdmin("/jyGateway/admin/api")
|
|
|
+ s.SetPort(8199)
|
|
|
+ s.Run()
|
|
|
}
|