package core

import (
	"chathub/chface/http"
	"fmt"

	"github.com/gin-gonic/gin"
)

var sApp = struct {
	Running bool
}{
	Running: false,
}

func AppPrepare() {

}

func AppStart() {

	if sApp.Running {
		return
	}

	sApp.Running = true

	eg := gin.Default()

	http.FaceHttpEntry(eg)

	eg.GET("/ping", func(c *gin.Context) { // /ping是路由
		//输出json结果给调用方
		c.JSON(200, gin.H{
			"message": "pong",
		})
	})

	go eg.Run(":8082") // 可以从本地的127.0.0.1:8081访问，不填的话，默认是8080端口

	fmt.Println("face AppStart started")
}

func AppStop() {
	if !sApp.Running {
		return
	}
	sApp.Running = false
}

func AppIsRunning() bool {
	return sApp.Running
}
