Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sidecar
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
sidecar
Commits
88993240
Commit
88993240
authored
Nov 24, 2021
by
suyanlong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.Add Router interface function.
2.Fixed bug for Manger
parent
7277a275
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
32 additions
and
28 deletions
+32
-28
server.go
api/server.go
+15
-20
sidecar.go
internal/app/sidecar.go
+3
-4
manager.go
internal/manger/manager.go
+8
-2
interface.go
internal/router/interface.go
+4
-0
json.go
pkg/json/json.go
+0
-2
tool.go
tool/tool.go
+2
-0
No files found.
api/server.go
View file @
88993240
...
...
@@ -2,7 +2,6 @@ package api
import
(
"context"
"encoding/json"
"fmt"
"net/http"
"path/filepath"
...
...
@@ -13,44 +12,43 @@ import (
"github.com/sirupsen/logrus"
"gitlab.33.cn/link33/sidecar/cmd/sidecar/client"
"gitlab.33.cn/link33/sidecar/internal/peermgr"
"gitlab.33.cn/link33/sidecar/internal/repo"
"gitlab.33.cn/link33/sidecar/internal/r
ulemg
r"
"gitlab.33.cn/link33/sidecar/internal/r
oute
r"
"gitlab.33.cn/link33/sidecar/model/pb"
"gitlab.33.cn/link33/sidecar/pkg/json"
"gitlab.33.cn/link33/sidecar/tool"
)
type
Server
struct
{
router
*
gin
.
Engine
engine
*
gin
.
Engine
config
*
repo
.
Config
logger
logrus
.
FieldLogger
ctx
context
.
Context
cancel
context
.
CancelFunc
peerMgr
peermgr
.
PeerManager
rule
*
rulemgr
.
RuleMgr
router
router
.
Router
}
type
response
struct
{
Data
[]
byte
`json:"data"`
}
func
NewServer
(
config
*
repo
.
Config
,
peerMgr
peermgr
.
PeerManager
,
rule
*
rulemgr
.
RuleMg
r
,
logger
logrus
.
FieldLogger
)
*
Server
{
func
NewServer
(
config
*
repo
.
Config
,
router
router
.
Route
r
,
logger
logrus
.
FieldLogger
)
*
Server
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
gin
.
SetMode
(
gin
.
ReleaseMode
)
r
outer
:=
gin
.
New
()
r
:=
gin
.
New
()
return
&
Server
{
router
:
route
r
,
engine
:
r
,
config
:
config
,
logger
:
logger
,
ctx
:
ctx
,
cancel
:
cancel
,
peerMgr
:
peerMgr
,
rule
:
rule
,
router
:
router
,
}
}
func
(
g
*
Server
)
Start
()
error
{
g
.
router
.
Use
(
gin
.
Recovery
())
v1
:=
g
.
router
.
Group
(
"/v1"
)
g
.
engine
.
Use
(
gin
.
Recovery
())
v1
:=
g
.
engine
.
Group
(
"/v1"
)
{
v1
.
POST
(
client
.
RegisterAppchainUrl
,
g
.
registerAppchain
)
v1
.
POST
(
client
.
UpdateAppchainUrl
,
g
.
updateAppchain
)
...
...
@@ -59,14 +57,11 @@ func (g *Server) Start() error {
go
func
()
{
go
func
()
{
err
:=
g
.
router
.
Run
(
fmt
.
Sprintf
(
":%d"
,
g
.
config
.
Port
.
Http
))
if
err
!=
nil
{
panic
(
err
)
}
tool
.
Asset
(
g
.
engine
.
Run
(
fmt
.
Sprintf
(
":%d"
,
g
.
config
.
Port
.
Http
)))
}()
<-
g
.
ctx
.
Done
()
}()
return
g
.
peerMgr
.
RegisterMsgHandler
(
pb
.
Message_RULE_DEPLOY
,
g
.
rule
.
HandleRule
)
return
nil
}
func
(
g
*
Server
)
Stop
()
error
{
...
...
@@ -99,7 +94,7 @@ func (g *Server) sendAppchain(c *gin.Context, appchainType pb.Message_Type) {
}
msg
:=
pb
.
Msg
(
appchainType
,
true
,
data
)
ackMsg
,
err
:=
g
.
peerMgr
.
SendByID
(
sidecarID
,
msg
)
ackMsg
,
err
:=
g
.
router
.
Send
(
sidecarID
,
msg
)
if
err
!=
nil
{
res
.
Data
=
[]
byte
(
err
.
Error
())
c
.
JSON
(
http
.
StatusInternalServerError
,
res
)
...
...
@@ -150,7 +145,7 @@ func (g *Server) getAppchain(c *gin.Context) {
}
msg
:=
pb
.
Msg
(
pb
.
Message_APPCHAIN_GET
,
true
,
data
)
ackMsg
,
err
:=
g
.
peerMgr
.
SendByID
(
targetSidecarID
,
msg
)
ackMsg
,
err
:=
g
.
router
.
Send
(
targetSidecarID
,
msg
)
if
err
!=
nil
{
res
.
Data
=
[]
byte
(
err
.
Error
())
c
.
JSON
(
http
.
StatusInternalServerError
,
res
)
...
...
internal/app/sidecar.go
View file @
88993240
...
...
@@ -66,12 +66,11 @@ func NewSidecar(repoRoot string, config *repo.Config) (internal.Launcher, error)
cryptor
:=
txcrypto
.
NewCryptor
(
nil
,
appchainMgr
,
privateKey
)
clientPort
:=
appchain
.
NewPorts
(
clients
,
cryptor
,
logger
)
r
.
Adds
(
clientPort
)
mg
,
err
:=
manger
.
NewManager
(
addr
.
String
(),
pm
,
appchainMgr
,
loggers
.
Logger
(
loggers
.
Manger
))
tool
.
Asset
(
err
)
rule
,
err
:=
rulemgr
.
New
(
store
,
loggers
.
Logger
(
loggers
.
Rule
))
tool
.
Asset
(
err
)
apiServer
:=
api
.
NewServer
(
config
,
pm
,
rule
,
loggers
.
Logger
(
loggers
.
ApiServer
))
mg
,
err
:=
manger
.
NewManager
(
addr
.
String
(),
pm
,
appchainMgr
,
rule
,
loggers
.
Logger
(
loggers
.
Manger
))
tool
.
Asset
(
err
)
apiServer
:=
api
.
NewServer
(
config
,
r
,
loggers
.
Logger
(
loggers
.
ApiServer
))
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
return
&
App
{
storage
:
store
,
...
...
internal/manger/manager.go
View file @
88993240
...
...
@@ -6,6 +6,7 @@ import (
"gitlab.33.cn/link33/sidecar/internal/peermgr"
"gitlab.33.cn/link33/sidecar/internal/port"
"gitlab.33.cn/link33/sidecar/internal/rulemgr"
"gitlab.33.cn/link33/sidecar/model/pb"
"gitlab.33.cn/link33/sidecar/pkg/json"
)
...
...
@@ -14,6 +15,7 @@ type Manager struct {
logger
logrus
.
FieldLogger
appchainMgr
appchainmgr
.
AppchainMgr
pm
peermgr
.
PeerManager
rule
*
rulemgr
.
RuleMgr
// router router.Router
}
...
...
@@ -25,11 +27,12 @@ func (mgr *Manager) Stop() error {
return
mgr
.
pm
.
Stop
()
}
func
NewManager
(
addr
string
,
pm
peermgr
.
PeerManager
,
Mgr
appchainmgr
.
AppchainMgr
,
logger
logrus
.
FieldLogger
)
(
*
Manager
,
error
)
{
func
NewManager
(
addr
string
,
pm
peermgr
.
PeerManager
,
Mgr
appchainmgr
.
AppchainMgr
,
rule
*
rulemgr
.
RuleMgr
,
logger
logrus
.
FieldLogger
)
(
*
Manager
,
error
)
{
am
:=
&
Manager
{
appchainMgr
:
Mgr
,
logger
:
logger
,
pm
:
pm
,
rule
:
rule
,
}
err
:=
pm
.
RegisterMultiMsgHandler
([]
pb
.
Message_Type
{
...
...
@@ -40,7 +43,10 @@ func NewManager(addr string, pm peermgr.PeerManager, Mgr appchainmgr.AppchainMgr
if
err
!=
nil
{
return
nil
,
err
}
err
=
pm
.
RegisterMsgHandler
(
pb
.
Message_RULE_DEPLOY
,
rule
.
HandleRule
)
if
err
!=
nil
{
return
nil
,
err
}
return
am
,
nil
}
...
...
internal/router/interface.go
View file @
88993240
...
...
@@ -18,6 +18,10 @@ type Router interface {
Load
(
key
string
)
(
value
port
.
Port
,
ok
bool
)
Send
(
id
string
,
msg
*
pb
.
Message
)
(
*
pb
.
Message
,
error
)
AsyncSend
(
id
string
,
msg
*
pb
.
Message
)
error
// InPut(ibtp *pb.IBTP) chan *pb.IBTP
// OutPut(ibtp *pb.IBTP) chan *pb.IBTP
// 代替上面两个方法
...
...
pkg/json/json.go
View file @
88993240
...
...
@@ -6,5 +6,3 @@ var (
Marshal
=
json
.
Marshal
Unmarshal
=
json
.
Unmarshal
)
tool/tool.go
View file @
88993240
...
...
@@ -76,3 +76,5 @@ func Exist(path string) bool {
//https://github.com/zricethezav/gitleaks
//https://github.com/casbin/casbin
//https://github.com/casbin/casbin
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment