package main

import (
	"flag"
	"fmt"
	"net/http"
	"time"

	"fusenapi/utils/auth"
	"fusenapi/utils/fsconfig"

	"fusenapi/server/shopping-cart/internal/config"
	"fusenapi/server/shopping-cart/internal/handler"
	"fusenapi/server/shopping-cart/internal/svc"

	"github.com/zeromicro/go-zero/rest"
)

var configFile = flag.String("f", "etc/shopping-cart.yaml", "the config file")

func main() {
	flag.Parse()

	var c config.Config
	fsconfig.StartNacosConfig(*configFile, &c, nil)

	c.Timeout = int64(time.Second * 15)
	server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
	}))
	defer server.Stop()

	ctx := svc.NewServiceContext(c)
	handler.RegisterHandlers(server, ctx)

	fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
	server.Start()
}