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
9458b451
Commit
9458b451
authored
Jul 23, 2020
by
root
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go fmt
parent
1fcb761c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
35 deletions
+34
-35
main.go
main.go
+7
-6
broadcast.go
pkg/app/broadcast.go
+11
-12
cmd.go
pkg/cmd/cmd.go
+16
-17
No files found.
main.go
View file @
9458b451
...
@@ -10,13 +10,13 @@ import (
...
@@ -10,13 +10,13 @@ import (
"fmt"
"fmt"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"chain33-pai/pkg/cmd"
"chain33-pai/pkg/pai"
"flag"
clog
"github.com/33cn/chain33/common/log"
clog
"github.com/33cn/chain33/common/log"
log
"github.com/33cn/chain33/common/log/log15"
log
"github.com/33cn/chain33/common/log/log15"
"net/http"
"net/http"
"time"
"time"
"flag"
"chain33-pai/pkg/pai"
"chain33-pai/pkg/cmd"
)
)
func
init
()
{
func
init
()
{
...
@@ -31,9 +31,10 @@ func init() {
...
@@ -31,9 +31,10 @@ func init() {
var
tlog
=
log
.
New
(
"main"
,
"main.go"
)
var
tlog
=
log
.
New
(
"main"
,
"main.go"
)
var
(
var
(
versionCmd
=
flag
.
Bool
(
"v"
,
false
,
"version"
)
versionCmd
=
flag
.
Bool
(
"v"
,
false
,
"version"
)
testCmd
=
flag
.
Bool
(
"t"
,
false
,
"test"
)
testCmd
=
flag
.
Bool
(
"t"
,
false
,
"test"
)
)
)
// @title Golang Gin API
// @title Golang Gin API
// @version 1.0
// @version 1.0
// @description An example of gin
// @description An example of gin
...
@@ -47,7 +48,7 @@ func main() {
...
@@ -47,7 +48,7 @@ func main() {
return
return
}
}
if
*
testCmd
{
if
*
testCmd
{
fmt
.
Println
(
"app sys:"
,
cmd
.
GetLocalArchType
(),
pai
.
GetArchType
())
fmt
.
Println
(
"app sys:"
,
cmd
.
GetLocalArchType
(),
pai
.
GetArchType
())
return
return
}
}
gin
.
SetMode
(
setting
.
ServerSetting
.
RunMode
)
gin
.
SetMode
(
setting
.
ServerSetting
.
RunMode
)
...
...
pkg/app/broadcast.go
View file @
9458b451
...
@@ -26,7 +26,7 @@ func Broadcast() {
...
@@ -26,7 +26,7 @@ func Broadcast() {
panic
(
"no serial no"
)
panic
(
"no serial no"
)
}
}
}
}
ip
,
err
:=
GetRightIp
()
ip
,
err
:=
GetRightIp
()
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
panic
(
err
)
}
}
...
@@ -105,21 +105,21 @@ func GetRightIp() (ipv4 *net.IPNet, err error) {
...
@@ -105,21 +105,21 @@ func GetRightIp() (ipv4 *net.IPNet, err error) {
}
}
}
}
}
}
return
ip
,
err
return
ip
,
err
}
}
func
GetRightIps
()
(
ipv4s
[]
*
net
.
IPNet
,
err
error
)
{
func
GetRightIps
()
(
ipv4s
[]
*
net
.
IPNet
,
err
error
)
{
ips
:=
make
([]
*
net
.
IPNet
,
0
)
ips
:=
make
([]
*
net
.
IPNet
,
0
)
interfaces
,
err
:=
net
.
Interfaces
()
interfaces
,
err
:=
net
.
Interfaces
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
for
_
,
i
:=
range
interfaces
{
for
_
,
i
:=
range
interfaces
{
ip
,
err
:=
util
.
GetLocalIpByName
(
i
.
Name
)
ip
,
err
:=
util
.
GetLocalIpByName
(
i
.
Name
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
ips
=
append
(
ips
,
ip
)
ips
=
append
(
ips
,
ip
)
}
}
return
ips
,
nil
return
ips
,
nil
}
}
\ No newline at end of file
pkg/cmd/cmd.go
View file @
9458b451
package
cmd
package
cmd
import
(
import
(
"os/exec"
"bytes"
"bytes"
"strings"
"fmt"
"fmt"
"github.com/33cn/chain33/common/log"
"github.com/33cn/chain33/common/log"
"os/exec"
"strings"
)
)
var
cmdLog
=
log
.
New
(
"pkg"
,
"app"
)
var
cmdLog
=
log
.
New
(
"pkg"
,
"app"
)
...
@@ -16,13 +16,13 @@ func GetLocalArchType() string {
...
@@ -16,13 +16,13 @@ func GetLocalArchType() string {
cmd
.
Stdout
=
&
buf
cmd
.
Stdout
=
&
buf
err
:=
cmd
.
Run
()
err
:=
cmd
.
Run
()
if
err
!=
nil
{
if
err
!=
nil
{
cmdLog
.
Error
(
"GetLocalArchType"
,
"err"
,
err
)
cmdLog
.
Error
(
"GetLocalArchType"
,
"err"
,
err
)
return
""
return
""
}
}
if
buf
.
String
()
!=
""
{
if
buf
.
String
()
!=
""
{
lines
:=
strings
.
Split
(
buf
.
String
(),
"
\n
"
)
lines
:=
strings
.
Split
(
buf
.
String
(),
"
\n
"
)
if
len
(
lines
)
==
2
{
if
len
(
lines
)
==
2
{
return
strings
.
Trim
(
lines
[
0
],
" "
)
return
strings
.
Trim
(
lines
[
0
],
" "
)
}
}
}
}
return
""
return
""
...
@@ -30,29 +30,29 @@ func GetLocalArchType() string {
...
@@ -30,29 +30,29 @@ func GetLocalArchType() string {
func
GetLocalUuid
()
string
{
func
GetLocalUuid
()
string
{
cmd
:=
exec
.
Command
(
"dmidecode"
)
cmd
:=
exec
.
Command
(
"dmidecode"
)
var
buf
,
errbuf
bytes
.
Buffer
var
buf
,
errbuf
bytes
.
Buffer
cmd
.
Stdout
=
&
buf
cmd
.
Stdout
=
&
buf
cmd
.
Stderr
=
&
errbuf
cmd
.
Stderr
=
&
errbuf
err
:=
cmd
.
Start
()
err
:=
cmd
.
Start
()
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
"Start"
,
err
)
fmt
.
Println
(
"Start"
,
err
)
}
}
err
=
cmd
.
Wait
()
err
=
cmd
.
Wait
()
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
"Wait"
,
err
)
fmt
.
Println
(
"Wait"
,
err
)
}
}
fmt
.
Println
(
"err"
,
errbuf
.
String
())
fmt
.
Println
(
"err"
,
errbuf
.
String
())
fmt
.
Println
(
"uuid"
,
buf
.
String
())
fmt
.
Println
(
"uuid"
,
buf
.
String
())
if
buf
.
String
()
!=
""
{
if
buf
.
String
()
!=
""
{
lines
:=
strings
.
Split
(
buf
.
String
(),
"
\n
"
)
lines
:=
strings
.
Split
(
buf
.
String
(),
"
\n
"
)
if
len
(
lines
)
>
0
{
if
len
(
lines
)
>
0
{
for
_
,
l
:=
range
lines
{
for
_
,
l
:=
range
lines
{
if
strings
.
Contains
(
l
,
"UUID"
)
{
if
strings
.
Contains
(
l
,
"UUID"
)
{
return
strings
.
Trim
(
l
,
"
\t
"
)
return
strings
.
Trim
(
l
,
"
\t
"
)
}
}
}
}
}
}
}
}
return
""
return
""
}
}
\ No newline at end of file
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