package main

import (
	"sparrow/pkg/mysql"
	"sparrow/pkg/rpcs"
	"sparrow/pkg/server"
)

func main() {
	// init server
	err := server.Init(rpcs.RegistryServerName)
	if err != nil {
		server.Log.Fatal(err)
		return
	}

	err = mysql.MigrateDatabase(*confDBHost, *confDBPort, *confDBName, *confDBUser, *confDBPass)
	if err != nil {
		server.Log.Fatal(err)
		return
	}

	// register a rpc service
	r, err := NewRegistry()
	if err != nil {
		server.Log.Fatal(err)
		return
	}
	err = server.RegisterRPCHandler(r)
	if err != nil {
		server.Log.Errorf("Register RPC service Error: %s", err)
		return
	}

	// start to run
	err = server.Run()
	if err != nil {
		server.Log.Fatal(err)
	}
}
