feat(rmi): support receive rmi connection (#5)

This commit is contained in:
Li4n0
2021-04-23 17:58:46 +08:00
committed by GitHub
parent 72c6150517
commit 5e24f9530d
25 changed files with 1101 additions and 20 deletions
+3 -1
View File
@@ -4,6 +4,7 @@ import (
"github.com/li4n0/revsuit/pkg/dns"
"github.com/li4n0/revsuit/pkg/mysql"
"github.com/li4n0/revsuit/pkg/rhttp"
"github.com/li4n0/revsuit/pkg/rmi"
)
type noticeConfig struct {
@@ -21,5 +22,6 @@ type Config struct {
Notice noticeConfig
rhttp.Config
DNS dns.Config
Mysql mysql.Config
MySQL mysql.Config
RMI rmi.Config
}
+11 -2
View File
@@ -9,6 +9,7 @@ import (
"github.com/li4n0/revsuit/pkg/dns"
"github.com/li4n0/revsuit/pkg/mysql"
"github.com/li4n0/revsuit/pkg/rhttp"
"github.com/li4n0/revsuit/pkg/rmi"
log "unknwon.dev/clog/v2"
)
@@ -52,10 +53,13 @@ func (revsuit *Revsuit) registerHttpRouter() {
httpGroup.GET("", rhttp.ListRecords)
dnsGroup := recordGroup.Group("/dns")
dnsGroup.GET("", dns.List)
dnsGroup.GET("", dns.ListRecords)
mysqlGroup := recordGroup.Group("/mysql")
mysqlGroup.GET("", mysql.List)
mysqlGroup.GET("", mysql.ListRecords)
rmiGroup := recordGroup.Group("/rmi")
rmiGroup.GET("", rmi.ListRecords)
// init rule router group
ruleGroup := revsuit.http.ApiGroup.Group("/rule")
@@ -75,6 +79,11 @@ func (revsuit *Revsuit) registerHttpRouter() {
mysqlGroup.POST("", mysql.UpsertRules)
mysqlGroup.DELETE("", mysql.DeleteRules)
rmiGroup = ruleGroup.Group("/rmi")
rmiGroup.GET("", rmi.ListRules)
rmiGroup.POST("", rmi.UpsertRules)
rmiGroup.DELETE("", rmi.DeleteRules)
// init file router group
fileGroup := revsuit.http.ApiGroup.Group("/file")
fileGroup.GET("/mysql/:id", mysql.GetFile)
+19 -2
View File
@@ -7,6 +7,7 @@ import (
"github.com/li4n0/revsuit/pkg/dns"
"github.com/li4n0/revsuit/pkg/mysql"
http "github.com/li4n0/revsuit/pkg/rhttp"
"github.com/li4n0/revsuit/pkg/rmi"
"gorm.io/gorm/logger"
log "unknwon.dev/clog/v2"
)
@@ -15,6 +16,7 @@ type Revsuit struct {
http *http.Server
dns *dns.Server
mysql *mysql.Server
rmi *rmi.Server
}
func initDatabase(dsn string) {
@@ -51,6 +53,14 @@ func initDatabase(dsn string) {
if err != nil {
log.Fatal(err.Error())
}
err = database.DB.AutoMigrate(&rmi.Record{})
if err != nil {
log.Fatal(err.Error())
}
err = database.DB.AutoMigrate(&rmi.Rule{})
if err != nil {
log.Fatal(err.Error())
}
}
@@ -122,9 +132,13 @@ func New(c *Config) *Revsuit {
if c.DNS.Enable {
s.dns = dns.GetServer()
}
if c.Mysql.Enable {
if c.MySQL.Enable {
s.mysql = mysql.GetServer()
s.mysql.Config = c.Mysql
s.mysql.Config = c.MySQL
}
if c.RMI.Enable {
s.rmi = rmi.GetServer()
s.rmi.Config = c.RMI
}
if c.Addr != "" {
@@ -149,6 +163,9 @@ func (revsuit *Revsuit) Run() {
if revsuit.mysql != nil {
go revsuit.mysql.Run()
}
if revsuit.rmi != nil {
go revsuit.rmi.Run()
}
revsuit.http.Run()
}