mirror of
https://github.com/VaalaCat/frp-panel.git
synced 2026-04-22 23:17:23 +08:00
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
bizserver "github.com/VaalaCat/frp-panel/biz/server"
|
|
"github.com/VaalaCat/frp-panel/conf"
|
|
"github.com/VaalaCat/frp-panel/pb"
|
|
"github.com/VaalaCat/frp-panel/services/api"
|
|
"github.com/VaalaCat/frp-panel/services/rpcclient"
|
|
"github.com/VaalaCat/frp-panel/watcher"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/sourcegraph/conc"
|
|
)
|
|
|
|
func runServer(clientID, clientSecret string) {
|
|
logrus.Infof("start to run server")
|
|
|
|
if len(clientID) == 0 {
|
|
logrus.Fatal("client id cannot be empty")
|
|
}
|
|
|
|
router := bizserver.NewRouter()
|
|
api.MustInitApiService(conf.ServerAPIListenAddr(), router)
|
|
|
|
a := api.GetAPIService()
|
|
defer a.Stop()
|
|
|
|
rpcclient.MustInitClientRPCSerivce(
|
|
clientID,
|
|
clientSecret,
|
|
pb.Event_EVENT_REGISTER_SERVER,
|
|
bizserver.HandleServerMessage,
|
|
)
|
|
|
|
r := rpcclient.GetClientRPCSerivce()
|
|
defer r.Stop()
|
|
|
|
w := watcher.NewClient(bizserver.PullConfig, clientID, clientSecret)
|
|
defer w.Stop()
|
|
|
|
initServerOnce(clientID, clientSecret)
|
|
|
|
var wg conc.WaitGroup
|
|
wg.Go(r.Run)
|
|
wg.Go(w.Run)
|
|
wg.Go(a.Run)
|
|
wg.Wait()
|
|
}
|
|
|
|
func initServerOnce(clientID, clientSecret string) {
|
|
err := bizserver.PullConfig(clientID, clientSecret)
|
|
if err != nil {
|
|
logrus.WithError(err).Errorf("cannot pull server config, wait for retry")
|
|
}
|
|
}
|