Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
chain33-pai
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
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
szh
chain33-pai
Commits
0a7bf8ed
Commit
0a7bf8ed
authored
Dec 17, 2019
by
szh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加跨域 广播设置为5秒
parent
a3a21b80
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
3 deletions
+72
-3
main.go
main.go
+2
-1
process.go
pkg/app/process.go
+48
-1
router.go
routers/router.go
+22
-1
No files found.
main.go
View file @
0a7bf8ed
...
...
@@ -101,6 +101,6 @@ func broadcast() {
panic
(
err
)
}
log
.
Println
(
send
)
time
.
Sleep
(
time
.
Second
)
time
.
Sleep
(
time
.
Second
*
5
)
}
}
\ No newline at end of file
pkg/app/process.go
View file @
0a7bf8ed
...
...
@@ -15,6 +15,7 @@ import (
"regexp"
"strings"
"time"
"io/ioutil"
)
type
ProcessInfo
struct
{
...
...
@@ -30,6 +31,19 @@ type updateInfo struct {
}
type
Server
struct
{
Disks
[]
*
Disk
//硬盘信息
NodeProcesssInfo
ProcessInfo
//节点信息
Error
error
//节点错误信息
}
type
Disk
struct
{
UseP
string
//硬盘使用率
Filesystem
string
Type
string
//硬盘格式
SizeK
string
//硬盘大小
}
var
Bityuan
ProcessInfo
var
UpdateInfo
updateInfo
var
NodeError
error
...
...
@@ -60,8 +74,15 @@ func getProcessInfo(keyfile string)string{
func
getWalletInfo
()
error
{
rawProcessInfo
:=
getProcessInfo
(
setting
.
BityuanSetting
.
Name
)
log
.
Println
(
rawProcessInfo
)
log
.
Println
(
"getWalletInfo"
,
rawProcessInfo
)
if
rawProcessInfo
==
""
{
//钱包节点未启动
//检查服务器状态
err
:=
MonitorServer
()
if
err
!=
nil
{
log
.
Println
(
"MonitorServer"
,
err
)
return
err
}
StartProcess
(
setting
.
Chain33Pai
.
Auto
)
var
buffer
bytes
.
Buffer
cmd
:=
exec
.
Command
(
"find"
,
"/media"
,
"-name"
,
setting
.
BityuanSetting
.
Name
)
...
...
@@ -104,6 +125,7 @@ func StrFilter(str []string,filter string)(res []string){
//corn job for collecting chain33 process info
func
CornProcessJob
(
ticker
*
time
.
Ticker
){
NodeError
=
getWalletInfo
()
for
{
select
{
...
...
@@ -187,3 +209,28 @@ func StartProcess(scriptsAddr string)(err error){
return
}
//
func
MonitorServer
()
error
{
//获取硬盘情况
cmd
:=
exec
.
Command
(
"df"
,
"-T"
)
stdout
,
err
:=
cmd
.
StdoutPipe
()
err
=
cmd
.
Start
()
if
err
!=
nil
{
log
.
Println
(
"MonitorServer"
,
"df -T start "
,
err
)
return
err
}
content
,
err
:=
ioutil
.
ReadAll
(
stdout
)
if
err
!=
nil
{
log
.
Println
(
err
)
return
err
}
err
=
cmd
.
Wait
()
if
err
!=
nil
{
log
.
Println
(
"MonitorServer"
,
"df -T end"
,
err
)
return
err
}
log
.
Println
(
"MonitorServer"
,
string
(
content
))
return
nil
}
routers/router.go
View file @
0a7bf8ed
...
...
@@ -4,6 +4,7 @@ import (
"github.com/gin-gonic/gin"
_
"chain33-pai/docs"
"chain33-pai/routers/api/v1"
"net/http"
)
// InitRouter initialize routing information
...
...
@@ -11,7 +12,7 @@ func InitRouter() *gin.Engine {
r
:=
gin
.
New
()
r
.
Use
(
gin
.
Logger
())
r
.
Use
(
gin
.
Recovery
())
r
.
Use
(
Cors
())
apiv1
:=
r
.
Group
(
"/pai"
)
//获取树莓派基本信息
apiv1
.
POST
(
"/devdetail"
,
v1
.
GetDevdetail
)
...
...
@@ -27,3 +28,23 @@ func InitRouter() *gin.Engine {
return
r
}
// 处理跨域请求,支持options访问
func
Cors
()
gin
.
HandlerFunc
{
return
func
(
c
*
gin
.
Context
)
{
method
:=
c
.
Request
.
Method
c
.
Header
(
"Access-Control-Allow-Origin"
,
"*"
)
c
.
Header
(
"Access-Control-Allow-Headers"
,
"Content-Type,AccessToken,X-CSRF-Token,Authorization"
)
//Content-Type,AccessToken,X-CSRF-Token,Authorization,Token,FZM-APP-ID
c
.
Header
(
"Access-Control-Allow-Methods"
,
"POST, GET, OPTIONS, PUT, PATCH, DELETE"
)
c
.
Header
(
"Access-Control-Expose-Headers"
,
"Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type"
)
c
.
Header
(
"Access-Control-Allow-Credentials"
,
"true"
)
// 放行所有OPTIONS方法,因为有的模板是要请求两次的
if
method
==
"OPTIONS"
{
c
.
AbortWithStatus
(
http
.
StatusNoContent
)
}
// 处理请求
c
.
Next
()
}
}
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