package main

import (
	"errors"
	"log"
	"net/http"

	"github.com/pingcap-inc/lark-bots/v2/feishubot"
	"github.com/pingcap-inc/lark-bots/v2/pkg/config"
	"github.com/pingcap-inc/lark-bots/v2/pkg/util"
)

// we recommend use https://open.feishu.cn/tool/cardbuilder to build card body
// and then generate to struct with [Paste JSON as Code](https://app.quicktype.io/)
func main() {
	config.InitConfig("config", "yml", "./etc")

	app := feishubot.NewApp()
	app.OnStarUp()
	feishubot.RegisterRoute(app)

	go func() {
		if err := app.Server.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
			log.Fatalf("Listen failed : %s\n", err)
		}
	}()

	util.GracefulShutdown(nil, nil)
	log.Println("Server exiting")
}
