// Code scaffolded by goctl. Safe to edit.
// goctl 1.10.1

package main

import (
	"flag"
	"fmt"

	"juwan-backend/app/users/api/internal/config"
	"juwan-backend/app/users/api/internal/handler"
	"juwan-backend/app/users/api/internal/svc"
	"juwan-backend/common/middlewares"

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

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

func main() {
	flag.Parse()

	var c config.Config
	conf.MustLoad(*configFile, &c, conf.UseEnv())

	server := rest.MustNewServer(c.RestConf)
	server.Use(middlewares.NewHeaderExtractorMiddleware().Handle)
	server.Use(middlewares.NewRequestMiddleware().Handle)
	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()
}
