package main

import (
	"fmt"
	"gateway/core/node"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
	"os"
	"os/signal"
	"syscall"
)

func main() {
	var serverCode string = "gatewayDemo"
	var serverPort int = 8099
	closeNotify, err := node.NewNode().Register(serverCode, fmt.Sprintf("%d", serverPort))
	if err != nil {
		panic(err)
	}

	go func() {
		server := g.Server()
		server.SetPort(serverPort)
		server.BindHandler("POST:/gatewayDemo/{page}", func(r *ghttp.Request) {
			r.Response.Write(map[string]interface{}{
				"code": 1,
				"func": r.Get("page"),
			})
		})
		server.Run()
	}()

	quit := make(chan os.Signal, 1)
	signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
	<-quit
	closeNotify()
}
