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
58cc8183
Commit
58cc8183
authored
Jan 07, 2022
by
suyanlong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add two api function
parent
278041a9
Pipeline
#8428
failed with stages
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
38 additions
and
8 deletions
+38
-8
api.go
api/api.go
+20
-1
server.go
api/server.go
+7
-2
http.go
cmd/sidecar/client/http.go
+2
-0
sidecar.go
internal/app/sidecar.go
+1
-1
appchain.go
internal/appchain/appchain.go
+3
-3
manager.go
internal/appchain/manager.go
+5
-1
No files found.
api/api.go
View file @
58cc8183
...
...
@@ -37,11 +37,30 @@ func (g *Server) sendTransaction(c *gin.Context) {
}
// TODO
c
.
JSON
(
http
.
StatusOK
,
res
)
panic
(
"implement me"
)
}
// GET 127.0.0.1:80/api/QueryOuterMeta/:did
func
(
g
*
Server
)
QueryOuterMeta
(
c
*
gin
.
Context
)
{
did
:=
c
.
Param
(
"did"
)
data
:=
g
.
mg
.
AppChain
(
did
)
.
QueryOuterMeta
()
c
.
JSON
(
http
.
StatusOK
,
data
)
}
// GET 127.0.0.1:80/api/QueryIBTP/:did/:to/:id
func
(
g
*
Server
)
QueryIBTP
(
c
*
gin
.
Context
)
{
id
:=
c
.
Param
(
"id"
)
to
:=
c
.
Param
(
"to"
)
did
:=
c
.
Param
(
"did"
)
ib
,
err
:=
g
.
mg
.
AppChain
(
did
)
.
QueryIBTP
(
to
,
id
)
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
NewError
(
http
.
StatusOK
,
http
.
StatusInternalServerError
,
err
.
Error
()))
}
else
{
c
.
JSON
(
http
.
StatusOK
,
ib
)
}
}
// GET 127.0.0.1:80/api/getTransaction/:hash
func
(
g
*
Server
)
getTransaction
(
c
*
gin
.
Context
)
{
panic
(
"implement me"
)
...
...
api/server.go
View file @
58cc8183
...
...
@@ -16,6 +16,7 @@ import (
"github.com/sirupsen/logrus"
"gitlab.33.cn/link33/sidecar/cmd/sidecar/client"
"gitlab.33.cn/link33/sidecar/internal/appchain"
"gitlab.33.cn/link33/sidecar/internal/repo"
"gitlab.33.cn/link33/sidecar/internal/router"
"gitlab.33.cn/link33/sidecar/model/pb"
...
...
@@ -30,13 +31,14 @@ type Server struct {
ctx
context
.
Context
cancel
context
.
CancelFunc
router
router
.
Router
mg
*
appchain
.
Manager
}
type
response
struct
{
Data
[]
byte
`json:"data"`
}
func
NewServer
(
config
*
repo
.
Config
,
router
router
.
Router
,
logger
logrus
.
FieldLogger
)
*
Server
{
func
NewServer
(
config
*
repo
.
Config
,
router
router
.
Router
,
mg
*
appchain
.
Manager
,
logger
logrus
.
FieldLogger
)
*
Server
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
// load the casbin model and policy from files, database is also supported.
...
...
@@ -59,12 +61,15 @@ func NewServer(config *repo.Config, router router.Router, logger logrus.FieldLog
func
(
g
*
Server
)
Start
()
error
{
g
.
engine
.
Use
(
gin
.
Recovery
())
v1
:=
g
.
engine
.
Group
(
"/v1"
)
v1
:=
g
.
engine
.
Group
(
"/v1
/api
"
)
// g.engine.Use(gin.Recovery())
{
v1
.
POST
(
client
.
RegisterAppchainUrl
,
g
.
registerAppchain
)
v1
.
POST
(
client
.
UpdateAppchainUrl
,
g
.
updateAppchain
)
v1
.
GET
(
client
.
GetAppchainUrl
,
g
.
getAppchain
)
v1
.
GET
(
"/QueryOuterMeta/:did"
,
g
.
QueryOuterMeta
)
v1
.
GET
(
"/QueryIBTP/:did/:to/:id"
,
g
.
QueryIBTP
)
}
go
func
()
{
...
...
cmd/sidecar/client/http.go
View file @
58cc8183
...
...
@@ -18,6 +18,8 @@ const (
AuditAppchainUrl
=
"appchain/audit"
GetAppchainUrl
=
"appchain/get"
RegisterRuleUrl
=
"rule/register"
QueryOuterMeta
=
"QueryOuterMeta"
QueryIBTP
=
"QueryIBTP"
)
func
httpGet
(
url
string
)
([]
byte
,
error
)
{
...
...
internal/app/sidecar.go
View file @
58cc8183
...
...
@@ -68,7 +68,7 @@ func NewSidecar(repoRoot string, config *repo.Config) (internal.Launcher, error)
r
.
Adds
(
managerPort
.
Ports
())
tool
.
Asset
(
err
)
apiServer
:=
api
.
NewServer
(
config
,
r
,
loggers
.
Logger
(
loggers
.
ApiServer
))
apiServer
:=
api
.
NewServer
(
config
,
r
,
managerPort
,
loggers
.
Logger
(
loggers
.
ApiServer
))
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
return
&
App
{
storage
:
store
,
...
...
internal/appchain/appchain.go
View file @
58cc8183
...
...
@@ -47,11 +47,11 @@ func newAppchain(ctx context.Context, client plugins.Client, cryptor txcrypto.Cr
}
}
func
newAppchains
(
ctx
context
.
Context
,
clients
[]
plugins
.
Client
,
cryptor
txcrypto
.
Cryptor
,
logger
logrus
.
FieldLogger
)
[
]
*
appChain
{
var
ps
[]
*
appChain
func
newAppchains
(
ctx
context
.
Context
,
clients
[]
plugins
.
Client
,
cryptor
txcrypto
.
Cryptor
,
logger
logrus
.
FieldLogger
)
map
[
string
]
*
appChain
{
ps
:=
make
(
map
[
string
]
*
appChain
)
for
_
,
c
:=
range
clients
{
p
:=
newAppchain
(
ctx
,
c
,
cryptor
,
logger
)
ps
=
append
(
ps
,
p
)
ps
[
p
.
ID
()]
=
p
}
return
ps
...
...
internal/appchain/manager.go
View file @
58cc8183
...
...
@@ -15,7 +15,7 @@ type Manager struct {
ctx
context
.
Context
cancel
context
.
CancelFunc
g
*
tool
.
Group
appChains
[
]
*
appChain
appChains
map
[
string
]
*
appChain
}
func
NewManager
(
clients
[]
plugins
.
Client
,
cryptor
txcrypto
.
Cryptor
,
logger
logrus
.
FieldLogger
)
*
Manager
{
...
...
@@ -57,3 +57,7 @@ func (m *Manager) Ports() []port.Port {
}
return
ports
}
func
(
m
*
Manager
)
AppChain
(
id
string
)
AppChain
{
return
m
.
appChains
[
id
]
}
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