52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
|
|
package main
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"net/http"
|
||
|
|
|
||
|
|
"repositories.action2quare.com/ayo/gocommon/flagx"
|
||
|
|
"repositories.action2quare.com/ayo/gocommon/wshandler"
|
||
|
|
"repositories.action2quare.com/ayo/social/core"
|
||
|
|
|
||
|
|
"repositories.action2quare.com/ayo/gocommon"
|
||
|
|
"repositories.action2quare.com/ayo/gocommon/logger"
|
||
|
|
"repositories.action2quare.com/ayo/gocommon/session"
|
||
|
|
)
|
||
|
|
|
||
|
|
var prefix = flagx.String("prefix", "", "")
|
||
|
|
|
||
|
|
func main() {
|
||
|
|
flagx.Parse()
|
||
|
|
|
||
|
|
ctx, cancel := context.WithCancel(context.Background())
|
||
|
|
var config core.SocialConfig
|
||
|
|
if err := gocommon.LoadConfig(&config); err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
|
||
|
|
consumer, err := session.NewConsumerWithConfig(ctx, config.SessionConfig)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
|
||
|
|
wsh, err := wshandler.NewWebsocketHandler(consumer, config.RedisURL)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
|
||
|
|
if so, err := core.New(ctx, wsh, &config); err != nil {
|
||
|
|
panic(err)
|
||
|
|
} else {
|
||
|
|
serveMux := http.NewServeMux()
|
||
|
|
wsh.RegisterHandlers(serveMux, *prefix)
|
||
|
|
so.RegisterHandlers(ctx, serveMux, *prefix)
|
||
|
|
server := gocommon.NewHTTPServer(serveMux)
|
||
|
|
logger.Println("social is started")
|
||
|
|
wsh.Start(ctx)
|
||
|
|
server.Start()
|
||
|
|
cancel()
|
||
|
|
so.Cleanup()
|
||
|
|
wsh.Cleanup()
|
||
|
|
}
|
||
|
|
}
|