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
0
Merge Requests
0
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
ligaishun
chain33-pai
Commits
3e81abf5
Commit
3e81abf5
authored
Sep 18, 2019
by
szh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
分支 内置树莓派程序
parent
71e25d63
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
168 additions
and
7 deletions
+168
-7
app.ini
conf/app.ini
+2
-2
main.go
main.go
+55
-5
main1.go1
main1.go1
+111
-0
No files found.
conf/app.ini
View file @
3e81abf5
[app]
[app]
PageSize
=
10
PageSize
=
10
JwtSecret
=
233
JwtSecret
=
233
PrefixUrl
=
http://127.0.0.1:8
000
PrefixUrl
=
http://127.0.0.1:8
803
RuntimeRootPath
=
runtime/
RuntimeRootPath
=
runtime/
...
@@ -22,7 +22,7 @@ TimeFormat = 20060102
...
@@ -22,7 +22,7 @@ TimeFormat = 20060102
[server]
[server]
#debug or release
#debug or release
RunMode
=
debug
RunMode
=
debug
HttpPort
=
8
000
HttpPort
=
8
803
ReadTimeout
=
60
ReadTimeout
=
60
WriteTimeout
=
60
WriteTimeout
=
60
...
...
main.go
View file @
3e81abf5
...
@@ -4,22 +4,27 @@ import (
...
@@ -4,22 +4,27 @@ import (
"fmt"
"fmt"
"log"
"log"
"net/http"
"net/http"
"bufio"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"chain33-pai/models"
"chain33-pai/pkg/gredis"
"chain33-pai/pkg/logging"
"chain33-pai/pkg/logging"
"chain33-pai/pkg/setting"
"chain33-pai/pkg/setting"
"chain33-pai/routers"
"chain33-pai/routers"
"chain33-pai/pkg/util"
"chain33-pai/pkg/util"
"os/exec"
"io"
"strings"
)
)
var
cache
map
[
string
]
string
func
init
()
{
func
init
()
{
cache
=
make
(
map
[
string
]
string
,
0
)
getPaiConfig
(
"cat"
,
"/proc/cpuinfo"
,
"|"
,
"grep Serial"
)
setting
.
Setup
()
setting
.
Setup
()
models
.
Setup
()
//
models.Setup()
logging
.
Setup
()
logging
.
Setup
()
gredis
.
Setup
()
//
gredis.Setup()
util
.
Setup
()
util
.
Setup
()
}
}
...
@@ -30,6 +35,7 @@ func init() {
...
@@ -30,6 +35,7 @@ func init() {
// @license.name MIT
// @license.name MIT
// @license.url https://chain33-pai/blob/master/LICENSE
// @license.url https://chain33-pai/blob/master/LICENSE
func
main
()
{
func
main
()
{
fmt
.
Println
(
"Serial:"
,
cache
)
gin
.
SetMode
(
setting
.
ServerSetting
.
RunMode
)
gin
.
SetMode
(
setting
.
ServerSetting
.
RunMode
)
routersInit
:=
routers
.
InitRouter
()
routersInit
:=
routers
.
InitRouter
()
...
@@ -64,3 +70,46 @@ func main() {
...
@@ -64,3 +70,46 @@ func main() {
// log.Printf("Server err: %v", err)
// log.Printf("Server err: %v", err)
//}
//}
}
}
func
getPaiConfig
(
command
string
,
arg
...
string
)
(
config
map
[
string
]
string
,
err
error
)
{
//获取操作系统版本信息
if
_
,
ok
:=
cache
[
"serial"
];
ok
{
return
cache
,
nil
}
list
:=
make
(
map
[
string
]
string
,
0
)
cmd
:=
exec
.
Command
(
"cat"
,
arg
...
)
stdout
,
err
:=
cmd
.
StdoutPipe
()
//fmt.Println(stdout)
if
err
!=
nil
{
fmt
.
Println
(
err
)
return
nil
,
err
}
defer
stdout
.
Close
()
if
err
:=
cmd
.
Start
();
err
!=
nil
{
fmt
.
Println
(
err
)
return
nil
,
err
}
rd
:=
bufio
.
NewReader
(
stdout
)
for
{
line
,
err
:=
rd
.
ReadString
(
'\n'
)
if
err
!=
nil
||
io
.
EOF
==
err
{
break
}
else
{
fmt
.
Println
(
"line"
,
line
)
l
:=
strings
.
Split
(
line
,
":"
)
if
len
(
l
)
==
2
{
k
:=
strings
.
ToLower
(
strings
.
TrimRight
(
strings
.
Trim
(
strings
.
Replace
(
l
[
0
],
" "
,
" "
,
-
1
),
" "
),
" "
))
v
:=
strings
.
Trim
(
strings
.
Replace
(
l
[
1
],
"
\n
"
,
""
,
-
1
),
" "
)
fmt
.
Println
(
"KEY:"
,
k
,
"VAL:"
,
v
)
if
_
,
ok
:=
list
[
k
];
!
ok
{
list
[
k
]
=
v
}
cache
[
k
]
=
v
}
}
}
return
list
,
nil
}
\ No newline at end of file
main1.go1
0 → 100644
View file @
3e81abf5
package
main
import
(
"os/exec"
"fmt"
"io/ioutil"
"net"
"errors"
"net/http"
"bufio"
"io"
"strings"
)
var
cache
map
[
string
]
string
func
init
()
{
cache
=
make
(
map
[
string
]
string
,
0
)
getPaiConfig
(
"cat"
,
"/proc/cpuinfo"
)
getLocalIP
()
getExternalIp
()
}
func
main
()
{
fmt
.
Println
(
"cache"
,
cache
)
}
func
getPaiConfig
(
command
string
,
arg
...
string
)
(
config
map
[
string
]
string
,
err
error
)
{
//
获取操作系统版本信息
if
_
,
ok
:=
cache
[
"serial"
];
ok
{
return
cache
,
nil
}
list
:=
make
(
map
[
string
]
string
,
0
)
cmd
:=
exec
.
Command
(
"cat"
,
arg
...)
stdout
,
err
:=
cmd
.
StdoutPipe
()
//
fmt
.
Println
(
stdout
)
if
err
!= nil {
fmt
.
Println
(
err
)
return
nil
,
err
}
defer
stdout
.
Close
()
if
err
:=
cmd
.
Start
();
err
!= nil {
fmt
.
Println
(
err
)
return
nil
,
err
}
rd
:=
bufio
.
NewReader
(
stdout
)
for
{
line
,
err
:=
rd
.
ReadString
(
'\n'
)
if
err
!=nil || io.EOF==err{
break
}
else
{
fmt
.
Println
(
"line"
,
line
)
l
:=
strings
.
Split
(
line
,
":"
)
if
len
(
l
)
==
2
{
k
:=
strings
.
ToLower
(
strings
.
TrimRight
(
strings
.
Trim
(
strings
.
Replace
(
l
[
0
],
" "
,
" "
,-
1
),
" "
),
" "
))
v
:=
strings
.
Trim
(
strings
.
Replace
(
l
[
1
],
"
\n
"
,
""
,-
1
),
" "
)
fmt
.
Println
(
"KEY:"
,
k
,
"VAL:"
,
v
)
if
_
,
ok
:=
list
[
k
];
!ok {
list
[
k
]
=
v
}
cache
[
k
]
=
v
}
}
}
return
list
,
nil
}
//
获取本机网卡
IP
func
getLocalIP
()
(
ipv4
string
,
err
error
)
{
var
(
addrs
[]
net
.
Addr
addr
net
.
Addr
ipNet
*
net
.
IPNet
//
IP
地址
isIpNet
bool
)
//
获取所有网卡
if
addrs
,
err
=
net
.
InterfaceAddrs
();
err
!= nil {
return
}
//
取第一个非
lo
的网卡
IP
for
_
,
addr
=
range
addrs
{
//
这个网络地址是
IP
地址
:
ipv4
,
ipv6
if
ipNet
,
isIpNet
=
addr
.(*
net
.
IPNet
);
isIpNet
&&
!ipNet.IP.IsLoopback() {
//
跳过
IPV6
if
ipNet
.
IP
.
To4
()
!= nil {
ipv4
=
ipNet
.
IP
.
String
()
//
192.168.1.1
cache
[
"localIp"
]
=
ipv4
return
}
}
}
err
=
errors
.
New
(
"ERR_NO_LOCAL_IP_FOUND"
)
return
}
func
getExternalIp
()
(
ipv4
string
,
err
error
)
{
resp
,
err
:=
http
.
Get
(
"http://myexternalip.com/raw"
)
if
err
!= nil {
return
""
,
err
}
defer
resp
.
Body
.
Close
()
content
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
ipv4
=
string
(
content
)
cache
[
"externalIp"
]
=
ipv4
fmt
.
Println
(
"ext"
,
ipv4
)
return
}
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