Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
rudern
物联大师
提交
dc8f0222
物
物联大师
项目概览
rudern
/
物联大师
通知
4
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
物
物联大师
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
GitCode(gitcode.net)2024年7月9日维护升级公告
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
dc8f0222
编写于
9月 29, 2020
作者:
J
Jason
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加路由
上级
e0e9f005
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
425 addition
and
129 deletion
+425
-129
internal/model/model.go
internal/model/model.go
+6
-47
internal/model/parser.go
internal/model/parser.go
+0
-75
web/api/model.go
web/api/model.go
+366
-0
web/api/router.go
web/api/router.go
+53
-7
未找到文件。
internal/model/model.go
浏览文件 @
dc8f0222
package
model
import
(
"git.zgwit.com/zgwit/iot-admin/interfaces"
"git.zgwit.com/zgwit/iot-admin/types"
"github.com/robertkrimen/otto"
)
type
_link
struct
{
linker
interfaces
.
Linker
Protocol
string
}
type
_variable
struct
{
Link
*
_link
Type
types
.
DataType
Addr
string
Default
string
Writable
bool
//可写,用于输出(如开关)
//TODO 采样:无、定时、轮询
Cron
string
Children
map
[
string
]
_variable
}
type
_batchResult
struct
{
Offset
int
Variable
string
//_variable path
}
type
_batch
struct
{
Link
string
Type
string
Addr
string
Size
int
Cron
string
Results
[]
_batchResult
}
type
_job
struct
{
Cron
string
Script
string
//javascript
}
type
_strategy
struct
{
Script
string
//javascript
}
type
Instance
struct
{
Links
map
[
string
]
_link
//
Links map[string]_link
Variables
map
[
string
]
_variable
Batches
map
[
string
]
_batch
Jobs
map
[
string
]
_job
Strategies
map
[
string
]
_strategy
//
Batches map[string]_batch
//
Jobs map[string]_job
//
Strategies map[string]_strategy
vm
*
otto
.
Otto
}
internal/model/parser.go
已删除
100644 → 0
浏览文件 @
e0e9f005
package
model
type
_base
struct
{
Name
string
`json:"name"`
Description
string
`json:"description"`
}
type
ModelLink
struct
{
_base
Protocol
string
`json:"protocol"`
}
type
ModelVariable
struct
{
_base
Link
string
`json:"link"`
Type
string
`json:"type"`
Addr
string
`json:"addr"`
Default
string
`json:"default"`
Writable
bool
`json:"writable"`
//可写,用于输出(如开关)
//TODO 采样:无、定时、轮询
Cron
string
`json:"cron"`
Children
[]
ModelVariable
`json:"children"`
}
type
ModelBatchResult
struct
{
Offset
int
`json:"offset"`
Variable
string
`json:"variable"`
//ModelVariable path
}
type
ModelBatch
struct
{
_base
Link
string
`json:"link"`
Type
string
`json:"type"`
Addr
string
`json:"addr"`
Size
int
`json:"size"`
Cron
string
`json:"cron"`
Results
[]
ModelBatchResult
`json:"results"`
}
type
ModelJob
struct
{
_base
Cron
string
`json:"cron"`
Script
string
`json:"script"`
//javascript
}
type
ModelStrategy
struct
{
_base
Script
string
`json:"script"`
//javascript
}
type
Model
struct
{
_base
Version
string
`json:"version"`
H5
string
`json:"h5"`
Links
[]
ModelLink
`json:"links"`
Variables
[]
ModelVariable
`json:"variables"`
Batches
[]
ModelBatch
`json:"batches"`
Jobs
[]
ModelJob
`json:"jobs"`
Strategies
[]
ModelStrategy
`json:"strategies"`
}
func
Import
(
json
string
)
error
{
//TODO parser model, import
return
nil
}
func
Export
(
id
int
)
string
{
//TODO ge
return
""
}
web/api/model.go
0 → 100644
浏览文件 @
dc8f0222
package
api
import
(
"git.zgwit.com/zgwit/iot-admin/internal/db"
"git.zgwit.com/zgwit/iot-admin/types"
"github.com/gin-gonic/gin"
"time"
)
type
ModelBase
struct
{
Name
string
`json:"name"`
Description
string
`json:"description"`
}
type
ModelTunnel
struct
{
ModelBase
Protocol
string
`json:"protocol"`
ProtocolOpts
string
`json:"protocol_opts"`
PollingEnable
bool
`json:"polling_enable"`
//轮询
PollingInterval
int
`json:"polling_interval"`
//轮询间隔
}
type
ModelVariable
struct
{
ModelBase
Tunnel
string
`json:"tunnel"`
Type
string
`json:"type"`
Addr
string
`json:"addr"`
Default
string
`json:"default"`
Writable
bool
`json:"writable"`
//可写,用于输出(如开关)
//采样:无、定时、轮询
Cron
string
`json:"cron"`
PollingEnable
bool
`json:"polling_enable"`
//轮询
PollingTimes
int
`json:"polling_times"`
}
type
ModelBatch
struct
{
ModelBase
Tunnel
string
`json:"tunnel"`
Type
string
`json:"type"`
Addr
string
`json:"addr"`
Size
int
`json:"size"`
//采样:无、定时、轮询
Cron
string
`json:"cron"`
PollingEnable
bool
`json:"polling_enable"`
//轮询
PollingTimes
int
`json:"polling_times"`
//结果解析
Results
[]
types
.
ModelBatchResult
`json:"results"`
}
type
ModelJob
struct
{
ModelBase
Cron
string
`json:"cron"`
Script
string
`json:"script"`
//javascript
}
type
ModelStrategy
struct
{
ModelBase
Script
string
`json:"script"`
//javascript
}
type
Model
struct
{
Name
string
`json:"name"`
Description
string
`json:"description"`
Version
string
`json:"version"`
H5
string
`json:"h5"`
Polling
bool
`json:"polling"`
//轮询
Tunnels
[]
ModelTunnel
`json:"tunnels"`
Variables
[]
ModelVariable
`json:"variables"`
Batches
[]
ModelBatch
`json:"batches"`
Jobs
[]
ModelJob
`json:"jobs"`
Strategies
[]
ModelStrategy
`json:"strategies"`
}
func
modelImport
(
ctx
*
gin
.
Context
)
{
var
model
Model
err
:=
ctx
.
ShouldBind
(
&
model
)
if
err
!=
nil
{
replyError
(
ctx
,
err
)
return
}
//TODO 导入模型
m
:=
types
.
Model
{
Name
:
model
.
Name
,
Description
:
model
.
Description
,
Version
:
model
.
Version
,
H5
:
model
.
H5
,
Polling
:
model
.
Polling
,
CreatedAt
:
time
.
Now
(),
}
modelDB
:=
db
.
DB
(
"model"
)
err
=
modelDB
.
Save
(
&
m
)
if
err
!=
nil
{
replyError
(
ctx
,
err
)
return
}
//创建通道
tunnelIds
:=
make
(
map
[
string
]
int
)
tunnelDB
:=
modelDB
.
From
(
"tunnel"
)
for
_
,
t
:=
range
model
.
Tunnels
{
tunnel
:=
types
.
ModelTunnel
{
ModelBase
:
types
.
ModelBase
{
ModelId
:
m
.
Id
,
Name
:
t
.
Name
,
Description
:
t
.
Description
,
CreatedAt
:
time
.
Now
(),
},
Protocol
:
t
.
Protocol
,
ProtocolOpts
:
t
.
ProtocolOpts
,
PollingEnable
:
t
.
PollingEnable
,
PollingInterval
:
t
.
PollingInterval
,
}
err
=
tunnelDB
.
Save
(
&
tunnel
)
if
err
!=
nil
{
replyError
(
ctx
,
err
)
return
}
tunnelIds
[
tunnel
.
Name
]
=
tunnel
.
Id
}
//创建变量
variableDB
:=
modelDB
.
From
(
"variable"
)
for
_
,
v
:=
range
model
.
Variables
{
variable
:=
types
.
ModelVariable
{
ModelBase
:
types
.
ModelBase
{
ModelId
:
m
.
Id
,
Name
:
v
.
Name
,
Description
:
v
.
Description
,
CreatedAt
:
time
.
Now
(),
},
TunnelId
:
tunnelIds
[
v
.
Tunnel
],
Type
:
v
.
Type
,
Addr
:
v
.
Addr
,
Default
:
v
.
Default
,
Writable
:
v
.
Writable
,
Cron
:
v
.
Cron
,
PollingEnable
:
v
.
PollingEnable
,
PollingTimes
:
v
.
PollingTimes
,
}
err
=
variableDB
.
Save
(
&
variable
)
if
err
!=
nil
{
replyError
(
ctx
,
err
)
return
}
}
//创建批量
batchDB
:=
modelDB
.
From
(
"batch"
)
for
_
,
v
:=
range
model
.
Batches
{
batch
:=
types
.
ModelBatch
{
ModelBase
:
types
.
ModelBase
{
ModelId
:
m
.
Id
,
Name
:
v
.
Name
,
Description
:
v
.
Description
,
CreatedAt
:
time
.
Now
(),
},
TunnelId
:
tunnelIds
[
v
.
Tunnel
],
Type
:
v
.
Type
,
Addr
:
v
.
Addr
,
Size
:
v
.
Size
,
Cron
:
v
.
Cron
,
PollingEnable
:
v
.
PollingEnable
,
PollingTimes
:
v
.
PollingTimes
,
Results
:
nil
,
}
err
=
batchDB
.
Save
(
&
batch
)
if
err
!=
nil
{
replyError
(
ctx
,
err
)
return
}
}
//创建任务
jobDB
:=
modelDB
.
From
(
"job"
)
for
_
,
v
:=
range
model
.
Jobs
{
job
:=
types
.
ModelJob
{
ModelBase
:
types
.
ModelBase
{
ModelId
:
m
.
Id
,
Name
:
v
.
Name
,
Description
:
v
.
Description
,
CreatedAt
:
time
.
Now
(),
},
Cron
:
v
.
Cron
,
Script
:
v
.
Script
,
}
err
=
jobDB
.
Save
(
&
job
)
if
err
!=
nil
{
replyError
(
ctx
,
err
)
return
}
}
//创建策略
strategyDB
:=
modelDB
.
From
(
"strategy"
)
for
_
,
v
:=
range
model
.
Strategies
{
job
:=
types
.
ModelStrategy
{
ModelBase
:
types
.
ModelBase
{
ModelId
:
m
.
Id
,
Name
:
v
.
Name
,
Description
:
v
.
Description
,
CreatedAt
:
time
.
Now
(),
},
Script
:
v
.
Script
,
}
err
=
strategyDB
.
Save
(
&
job
)
if
err
!=
nil
{
replyError
(
ctx
,
err
)
return
}
}
replyOk
(
ctx
,
m
)
}
func
modelExport
(
ctx
*
gin
.
Context
)
{
var
pid
paramId
if
err
:=
ctx
.
BindUri
(
&
pid
);
err
!=
nil
{
replyError
(
ctx
,
err
)
return
}
var
model
types
.
Model
modelDB
:=
db
.
DB
(
"model"
)
err
:=
modelDB
.
One
(
"Id"
,
pid
.
Id
,
&
model
)
if
err
!=
nil
{
replyError
(
ctx
,
err
)
return
}
m
:=
Model
{
Name
:
model
.
Name
,
Description
:
model
.
Description
,
Version
:
model
.
Version
,
H5
:
model
.
H5
,
Polling
:
model
.
Polling
,
Tunnels
:
make
([]
ModelTunnel
,
0
),
Variables
:
make
([]
ModelVariable
,
0
),
Batches
:
make
([]
ModelBatch
,
0
),
Jobs
:
make
([]
ModelJob
,
0
),
Strategies
:
make
([]
ModelStrategy
,
0
),
}
//读取通道
tunnelIds
:=
make
(
map
[
int
]
string
)
tunnelDB
:=
modelDB
.
From
(
"tunnel"
)
var
tunnels
[]
types
.
ModelTunnel
err
=
tunnelDB
.
Find
(
"ModelId"
,
model
.
Id
,
&
tunnels
)
if
err
!=
nil
{
replyError
(
ctx
,
err
)
return
}
for
_
,
v
:=
range
tunnels
{
tunnel
:=
ModelTunnel
{
ModelBase
:
ModelBase
{
Name
:
v
.
Name
,
Description
:
v
.
Description
,
},
Protocol
:
v
.
Protocol
,
ProtocolOpts
:
v
.
ProtocolOpts
,
PollingEnable
:
v
.
PollingEnable
,
PollingInterval
:
v
.
PollingInterval
,
}
m
.
Tunnels
=
append
(
m
.
Tunnels
,
tunnel
)
tunnelIds
[
v
.
Id
]
=
v
.
Name
}
//读取变量
variableDB
:=
modelDB
.
From
(
"variable"
)
var
variables
[]
types
.
ModelVariable
err
=
variableDB
.
Find
(
"ModelId"
,
model
.
Id
,
&
variables
)
if
err
!=
nil
{
replyError
(
ctx
,
err
)
return
}
for
_
,
v
:=
range
variables
{
variable
:=
ModelVariable
{
ModelBase
:
ModelBase
{
Name
:
v
.
Name
,
Description
:
v
.
Description
,
},
Tunnel
:
tunnelIds
[
v
.
TunnelId
],
Type
:
v
.
Type
,
Addr
:
v
.
Addr
,
Default
:
v
.
Default
,
Writable
:
v
.
Writable
,
Cron
:
v
.
Cron
,
PollingEnable
:
v
.
PollingEnable
,
PollingTimes
:
v
.
PollingTimes
,
}
m
.
Variables
=
append
(
m
.
Variables
,
variable
)
}
//读取批量
batchDB
:=
modelDB
.
From
(
"batch"
)
var
batches
[]
types
.
ModelBatch
err
=
batchDB
.
Find
(
"ModelId"
,
model
.
Id
,
&
batches
)
if
err
!=
nil
{
replyError
(
ctx
,
err
)
return
}
for
_
,
v
:=
range
batches
{
batch
:=
ModelBatch
{
ModelBase
:
ModelBase
{
Name
:
v
.
Name
,
Description
:
v
.
Description
,
},
Tunnel
:
tunnelIds
[
v
.
TunnelId
],
Type
:
v
.
Type
,
Addr
:
v
.
Addr
,
Size
:
v
.
Size
,
Cron
:
v
.
Cron
,
PollingEnable
:
v
.
PollingEnable
,
PollingTimes
:
v
.
PollingTimes
,
Results
:
v
.
Results
,
}
m
.
Batches
=
append
(
m
.
Batches
,
batch
)
}
//读取任务
jobDB
:=
modelDB
.
From
(
"job"
)
var
jobs
[]
types
.
ModelJob
err
=
jobDB
.
Find
(
"ModelId"
,
model
.
Id
,
&
jobs
)
if
err
!=
nil
{
replyError
(
ctx
,
err
)
return
}
for
_
,
v
:=
range
jobs
{
job
:=
ModelJob
{
ModelBase
:
ModelBase
{
Name
:
v
.
Name
,
Description
:
v
.
Description
,
},
Cron
:
v
.
Cron
,
Script
:
v
.
Script
,
}
m
.
Jobs
=
append
(
m
.
Jobs
,
job
)
}
//读取策略
strategyDB
:=
modelDB
.
From
(
"strategy"
)
var
strategies
[]
types
.
ModelStrategy
err
=
strategyDB
.
Find
(
"ModelId"
,
model
.
Id
,
&
strategies
)
if
err
!=
nil
{
replyError
(
ctx
,
err
)
return
}
for
_
,
v
:=
range
strategies
{
strategy
:=
ModelStrategy
{
ModelBase
:
ModelBase
{
Name
:
v
.
Name
,
Description
:
v
.
Description
,
},
Script
:
v
.
Script
,
}
m
.
Strategies
=
append
(
m
.
Strategies
,
strategy
)
}
replyOk
(
ctx
,
m
)
}
web/api/router.go
浏览文件 @
dc8f0222
...
...
@@ -60,14 +60,14 @@ func RegisterRoutes(app *gin.RouterGroup) {
//TODO 转移至子目录,并使用中间件,检查session及权限
app
.
POST
(
"/channels"
,
channels
)
app
.
POST
(
"/c
ore
"
,
channelCreate
)
app
.
DELETE
(
"/c
ore
/:id"
,
channelDelete
)
app
.
PUT
(
"/c
ore
/:id"
,
channelModify
)
app
.
GET
(
"/c
ore
/:id"
,
channelGet
)
app
.
GET
(
"/c
ore
/:id/start"
,
channelStart
)
app
.
GET
(
"/c
ore
/:id/stop"
,
channelStop
)
app
.
POST
(
"/c
hannel
"
,
channelCreate
)
app
.
DELETE
(
"/c
hannel
/:id"
,
channelDelete
)
app
.
PUT
(
"/c
hannel
/:id"
,
channelModify
)
app
.
GET
(
"/c
hannel
/:id"
,
channelGet
)
app
.
GET
(
"/c
hannel
/:id/start"
,
channelStart
)
app
.
GET
(
"/c
hannel
/:id/stop"
,
channelStop
)
//app.POST("/c
ore
/:id/links")
//app.POST("/c
hannel
/:id/links")
//连接管理
app
.
POST
(
"/links"
,
links
)
...
...
@@ -82,6 +82,52 @@ func RegisterRoutes(app *gin.RouterGroup) {
app
.
PUT
(
"/plugin/:id"
,
pluginModify
)
app
.
GET
(
"/plugin/:id"
,
pluginGet
)
//模型管理
app
.
POST
(
"/models"
,
nop
)
app
.
POST
(
"/model"
,
nop
)
app
.
DELETE
(
"/model/:id"
,
nop
)
app
.
PUT
(
"/model/:id"
,
nop
)
app
.
GET
(
"/model/:id"
,
nop
)
app
.
POST
(
"/model/:id/tunnels"
,
nop
)
app
.
POST
(
"/model/:id/variables"
,
nop
)
app
.
POST
(
"/model/:id/batches"
,
nop
)
app
.
POST
(
"/model/:id/jobs"
,
nop
)
app
.
POST
(
"/model/:id/strategies"
,
nop
)
app
.
POST
(
"/model-import"
,
modelImport
)
app
.
GET
(
"/model-export/:id"
,
modelExport
)
app
.
POST
(
"/tunnels"
,
nop
)
app
.
POST
(
"/tunnel"
,
nop
)
app
.
DELETE
(
"/tunnel/:id"
,
nop
)
app
.
PUT
(
"/tunnel/:id"
,
nop
)
app
.
GET
(
"/tunnel/:id"
,
nop
)
app
.
POST
(
"/variables"
,
nop
)
app
.
POST
(
"/variable"
,
nop
)
app
.
DELETE
(
"/variable/:id"
,
nop
)
app
.
PUT
(
"/variable/:id"
,
nop
)
app
.
GET
(
"/variable/:id"
,
nop
)
app
.
POST
(
"/batches"
,
nop
)
app
.
POST
(
"/batch"
,
nop
)
app
.
DELETE
(
"/batch/:id"
,
nop
)
app
.
PUT
(
"/batch/:id"
,
nop
)
app
.
GET
(
"/batch/:id"
,
nop
)
app
.
POST
(
"/jobs"
,
nop
)
app
.
POST
(
"/job"
,
nop
)
app
.
DELETE
(
"/job/:id"
,
nop
)
app
.
PUT
(
"/job/:id"
,
nop
)
app
.
GET
(
"/job/:id"
,
nop
)
app
.
POST
(
"/strategies"
,
nop
)
app
.
POST
(
"/strategy"
,
nop
)
app
.
DELETE
(
"/strategy/:id"
,
nop
)
app
.
PUT
(
"/strategy/:id"
,
nop
)
app
.
GET
(
"/strategy/:id"
,
nop
)
}
func
replyOk
(
ctx
*
gin
.
Context
,
data
interface
{})
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录