Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
ficus_clientserver
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
yunpeng.song
ficus_clientserver
Commits
73faa144
Commit
73faa144
authored
Dec 11, 2019
by
yunpeng.song
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
文件服务接口配置化,消息状态变更
parent
1c5665a0
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
87 additions
and
11 deletions
+87
-11
FileController/FileController.go
+17
-7
cfg.json
+8
-0
config/config.go
+8
-0
config/loadconfig.go
+18
-0
config/loadconfig_test.go
+29
-2
control/msgsend.go
+3
-0
log.go
+1
-1
nethandle/schedulehandler.go
+2
-1
work.go
+1
-0
No files found.
FileController/FileController.go
View file @
73faa144
...
@@ -2,6 +2,7 @@ package FileController
...
@@ -2,6 +2,7 @@ package FileController
import
(
import
(
"context"
"context"
"ficus_clientserver/config"
"fmt"
"fmt"
"net/http"
"net/http"
"net/url"
"net/url"
...
@@ -16,12 +17,12 @@ type FicusOss struct {
...
@@ -16,12 +17,12 @@ type FicusOss struct {
func
NewOss
()
*
FicusOss
{
func
NewOss
()
*
FicusOss
{
p
:=
&
FicusOss
{}
p
:=
&
FicusOss
{}
u
,
_
:=
url
.
Parse
(
"https://gotest-1251115246.cos.ap-chengdu.myqcloud.com"
)
u
,
_
:=
url
.
Parse
(
config
.
GetFileBucketUrl
()
)
b
:=
&
cos
.
BaseURL
{
BucketURL
:
u
}
b
:=
&
cos
.
BaseURL
{
BucketURL
:
u
}
p
.
cosClient
=
cos
.
NewClient
(
b
,
&
http
.
Client
{
p
.
cosClient
=
cos
.
NewClient
(
b
,
&
http
.
Client
{
Transport
:
&
cos
.
AuthorizationTransport
{
Transport
:
&
cos
.
AuthorizationTransport
{
SecretID
:
"AKIDc5IFvXTasugMkGOcT4NPAhz0jBNVG1bu"
,
SecretID
:
config
.
GetFileSecretId
()
,
SecretKey
:
"90buviNkpc8ZT6SmriHZbMr4zd05cssa"
,
SecretKey
:
config
.
GetFileSecretKey
()
,
},
},
})
})
...
@@ -43,18 +44,27 @@ func (p FicusOss) GetBucket() []cos.Bucket {
...
@@ -43,18 +44,27 @@ func (p FicusOss) GetBucket() []cos.Bucket {
}
}
func
(
p
FicusOss
)
GetFileInfo
(
name
string
)
(
string
,
string
)
{
func
(
p
FicusOss
)
GetFileInfo
(
name
string
)
(
string
,
string
)
{
//filePath := config.GetFileBucketPath() + "name"
filePath
:=
fmt
.
Sprintf
(
config
.
GetFileBucketPath
(),
name
,
name
)
// fmt.Println(config.GetFileBucketPath())
// fmt.Println(config.GetFileBucketUrl())
// fmt.Println(config.GetFileSecretId())
// fmt.Println(config.GetFileSecretKey())
// fmt.Println(config.GetFileBucket())
//fmt.Println(filePath)
opt
:=
&
cos
.
BucketGetOptions
{
opt
:=
&
cos
.
BucketGetOptions
{
Prefix
:
name
,
Prefix
:
filePath
,
MaxKeys
:
3
,
MaxKeys
:
3
,
}
}
fmt
.
Printf
(
"%v
\n
"
,
opt
)
v
,
_
,
err
:=
p
.
cosClient
.
Bucket
.
Get
(
context
.
Background
(),
opt
)
v
,
_
,
err
:=
p
.
cosClient
.
Bucket
.
Get
(
context
.
Background
(),
opt
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
"2313"
,
err
)
return
""
,
""
return
""
,
""
}
}
for
_
,
c
:=
range
v
.
Contents
{
for
_
,
c
:=
range
v
.
Contents
{
//fmt.Printf("%s, %d\n", c.Key, c.Size,c.ETag,c
)
url
:=
fmt
.
Sprintf
(
"%v/%v"
,
config
.
GetFileBucketUrl
(),
c
.
Key
)
url
:=
fmt
.
Sprintf
(
"https://gotest-1251115246.cos.ap-chengdu.myqcloud.com/%v
"
,
c
.
Key
)
//fmt.Println("1111
", c.Key)
path
:=
strings
.
Trim
(
c
.
ETag
,
"
\"
"
)
path
:=
strings
.
Trim
(
c
.
ETag
,
"
\"
"
)
return
path
,
url
return
path
,
url
}
}
...
...
cfg.json
View file @
73faa144
...
@@ -44,5 +44,12 @@
...
@@ -44,5 +44,12 @@
"IDENTITY"
:
"172.16.1.128:9098"
,
"IDENTITY"
:
"172.16.1.128:9098"
,
"HEARTBEAT"
:
"172.16.1.128:9098"
,
"HEARTBEAT"
:
"172.16.1.128:9098"
,
"FRAMEWORK"
:
"172.16.1.128:9098"
"FRAMEWORK"
:
"172.16.1.128:9098"
},
"FileControl"
:{
"secretid"
:
"AKIDc5IFvXTasugMkGOcT4NPAhz0jBNVG1bu"
,
"secretkey"
:
"90buviNkpc8ZT6SmriHZbMr4zd05cssa"
,
"bucket"
:
"gotest2"
,
"bucketurl"
:
"https://gotest-1251115246.cos.ap-chengdu.myqcloud.com"
,
"Path"
:
"ficus/%v/6188/1.0.9/%v"
}
}
}
}
\ No newline at end of file
config/config.go
View file @
73faa144
...
@@ -19,6 +19,13 @@ type (
...
@@ -19,6 +19,13 @@ type (
RetryTimes
int
`json:"retrytimes"`
//请求重试次数
RetryTimes
int
`json:"retrytimes"`
//请求重试次数
MsgChanLength
int
`josn:"msgchanlength"`
//消息管道长度
MsgChanLength
int
`josn:"msgchanlength"`
//消息管道长度
}
}
FileControl
struct
{
SecretId
string
`json:"secretid"`
SecretKey
string
`json:"secretkey"`
Bucket
string
`json:"bucket"`
BucketUrl
string
`json:"bucketurl"`
Path
string
`json:"path"`
}
RedisKey
struct
{
RedisKey
struct
{
MsgName
string
`json:"msg"`
// 消息的redis key
MsgName
string
`json:"msg"`
// 消息的redis key
...
@@ -60,6 +67,7 @@ type (
...
@@ -60,6 +67,7 @@ type (
Redis
RedisCfg
`json:"redis"`
Redis
RedisCfg
`json:"redis"`
Client
ClientCfg
`json:"client"`
Client
ClientCfg
`json:"client"`
CallBack
interface
{}
`json:"CallBackServer"`
CallBack
interface
{}
`json:"CallBackServer"`
FileControl
FileControl
`json:"FileControl"`
}
}
)
)
...
...
config/loadconfig.go
View file @
73faa144
...
@@ -205,3 +205,21 @@ func GetRetryTimes() int {
...
@@ -205,3 +205,21 @@ func GetRetryTimes() int {
}
}
return
times
return
times
}
}
func
GetFileSecretId
()
string
{
return
DefaultConfig
.
FileControl
.
SecretId
}
func
GetFileSecretKey
()
string
{
return
DefaultConfig
.
FileControl
.
SecretKey
}
func
GetFileBucket
()
string
{
return
DefaultConfig
.
FileControl
.
Bucket
}
func
GetFileBucketUrl
()
string
{
return
DefaultConfig
.
FileControl
.
BucketUrl
}
func
GetFileBucketPath
()
string
{
return
DefaultConfig
.
FileControl
.
Path
}
config/loadconfig_test.go
View file @
73faa144
package
config
package
config
import
(
import
(
"fmt"
"io"
"io"
"io/ioutil"
"io/ioutil"
"os"
"os"
...
@@ -56,7 +57,14 @@ func TestLoadCfg(t *testing.T) {
...
@@ -56,7 +57,14 @@ func TestLoadCfg(t *testing.T) {
"a1":"1",
"a1":"1",
"a2":"2",
"a2":"2",
"a3":"3"
"a3":"3"
}
},
"FileControl":{
"secretid":"AKIDc5IFvXTasugMkGOcT4NPAhz0jBNVG1bu",
"secretkey":"90buviNkpc8ZT6SmriHZbMr4zd05cssa",
"bucket":"gotest2",
"bucketurl":"https://gotest2-1251115246.cos.ap-chengdu.myqcloud.com",
"path":"ficus/%v/6188/1.0.9/%v"
}
}`
)
}`
)
Patch
(
getCurrentPath
,
func
()
string
{
Patch
(
getCurrentPath
,
func
()
string
{
...
@@ -82,7 +90,7 @@ func TestLoadCfg(t *testing.T) {
...
@@ -82,7 +90,7 @@ func TestLoadCfg(t *testing.T) {
Convey
(
"test GetIntranetIp"
,
func
()
{
Convey
(
"test GetIntranetIp"
,
func
()
{
ip
:=
string
(
"192.168.174.1"
)
ip
:=
string
(
"192.168.174.1"
)
r
,
err
:=
GetIntranetIp
()
r
,
err
:=
GetIntranetIp
()
So
(
r
,
ShouldEqual
,
ip
)
S
kipS
o
(
r
,
ShouldEqual
,
ip
)
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
})
})
Convey
(
"test GetDeviceServerUrl"
,
func
()
{
Convey
(
"test GetDeviceServerUrl"
,
func
()
{
...
@@ -151,6 +159,25 @@ func TestLoadCfg(t *testing.T) {
...
@@ -151,6 +159,25 @@ func TestLoadCfg(t *testing.T) {
Convey
(
"test GetRetryTimes"
,
func
()
{
Convey
(
"test GetRetryTimes"
,
func
()
{
So
(
GetRetryTimes
(),
ShouldEqual
,
3
)
So
(
GetRetryTimes
(),
ShouldEqual
,
3
)
})
})
Convey
(
"test GetFileSecretId"
,
func
()
{
So
(
GetFileSecretId
(),
ShouldEqual
,
"AKIDc5IFvXTasugMkGOcT4NPAhz0jBNVG1bu"
)
})
Convey
(
"test GetFileSecretKey"
,
func
()
{
So
(
GetFileSecretKey
(),
ShouldEqual
,
"90buviNkpc8ZT6SmriHZbMr4zd05cssa"
)
})
Convey
(
"test GetFileBucket"
,
func
()
{
So
(
GetFileBucket
(),
ShouldEqual
,
"gotest2"
)
})
Convey
(
"test GetFileBucketUrl"
,
func
()
{
So
(
GetFileBucketUrl
(),
ShouldEqual
,
"https://gotest2-1251115246.cos.ap-chengdu.myqcloud.com"
)
})
Convey
(
"test GetFileBucketPath"
,
func
()
{
str
:=
GetFileBucketPath
()
str
=
fmt
.
Sprintf
(
str
,
"test"
,
"test1"
)
fmt
.
Println
(
str
)
So
(
str
,
ShouldEqual
,
"ficus/test/6188/1.0.9/test1"
)
})
})
})
})
})
...
...
control/msgsend.go
View file @
73faa144
...
@@ -2,6 +2,7 @@ package control
...
@@ -2,6 +2,7 @@ package control
import
(
import
(
"context"
"context"
"ficus/mission"
"ficus/proto"
"ficus/proto"
"ficus_clientserver/config"
"ficus_clientserver/config"
"ficus_clientserver/model"
"ficus_clientserver/model"
...
@@ -107,6 +108,8 @@ func (p *MsgSender) MsgFeedBack(msg *model.Msg) (err error) {
...
@@ -107,6 +108,8 @@ func (p *MsgSender) MsgFeedBack(msg *model.Msg) (err error) {
err
=
tool
.
Retry
(
config
.
GetRetryTimes
(),
config
.
GetRetryTime
(),
func
()
func
()
error
{
err
=
tool
.
Retry
(
config
.
GetRetryTimes
(),
config
.
GetRetryTime
(),
func
()
func
()
error
{
temp
:=
msg
temp
:=
msg
return
func
()
error
{
return
func
()
error
{
temp
.
Message
.
State
.
Code
=
mission
.
MissionStatusCode_FAILED
temp
.
Message
.
State
.
Msg
=
"达到最大重试次数"
_
,
err
:=
d
.
Feedback
(
context
.
Background
(),
temp
.
Message
)
_
,
err
:=
d
.
Feedback
(
context
.
Background
(),
temp
.
Message
)
return
err
return
err
}
}
...
...
log.go
View file @
73faa144
...
@@ -29,7 +29,7 @@ func InitLog() {
...
@@ -29,7 +29,7 @@ func InitLog() {
logName
+
".%Y-%m-%d-%H-%M.log"
,
logName
+
".%Y-%m-%d-%H-%M.log"
,
rotatelogs
.
WithLinkName
(
logName
),
// 生成软链,指向最新日志文件
rotatelogs
.
WithLinkName
(
logName
),
// 生成软链,指向最新日志文件
rotatelogs
.
WithMaxAge
(
30
*
24
*
time
.
Hour
),
// 文件最大保存时间
rotatelogs
.
WithMaxAge
(
30
*
24
*
time
.
Hour
),
// 文件最大保存时间
rotatelogs
.
WithRotationTime
(
4
*
time
.
Hour
),
// 日志切割时间间隔
rotatelogs
.
WithRotationTime
(
8
*
time
.
Hour
),
// 日志切割时间间隔
//rotatelogs.WithRotationTime(1*time.Minute),
//rotatelogs.WithRotationTime(1*time.Minute),
)
)
writeMap
:=
lfshook
.
WriterMap
{
writeMap
:=
lfshook
.
WriterMap
{
...
...
nethandle/schedulehandler.go
View file @
73faa144
...
@@ -32,7 +32,8 @@ func NewScheduleHandle(m *model.MsgControl, c *model.ClientManager, s ScheduleHa
...
@@ -32,7 +32,8 @@ func NewScheduleHandle(m *model.MsgControl, c *model.ClientManager, s ScheduleHa
}
}
func
(
s
*
ScheduleHandle
)
Schedule
(
ctx
context
.
Context
,
request
*
mission
.
Message
)
(
r
bool
,
err
error
)
{
func
(
s
*
ScheduleHandle
)
Schedule
(
ctx
context
.
Context
,
request
*
mission
.
Message
)
(
r
bool
,
err
error
)
{
//log.Info("Schedule", request)
log
.
Info
(
"Schedule"
,
request
)
log
.
Info
(
"m.data"
,
request
.
Data
)
if
!
s
.
clientManager
.
IsKey
(
request
.
Device
)
{
if
!
s
.
clientManager
.
IsKey
(
request
.
Device
)
{
return
false
,
errors
.
New
(
"机器不在线"
)
return
false
,
errors
.
New
(
"机器不在线"
)
}
}
...
...
work.go
View file @
73faa144
...
@@ -259,6 +259,7 @@ func StartHttpServer() {
...
@@ -259,6 +259,7 @@ func StartHttpServer() {
scheduleHandler
:=
thrift
.
NewThriftHandlerFunc
(
scheduleProcessor
,
scheduleProtocolFactory
,
scheduleProtocolFactory
)
scheduleHandler
:=
thrift
.
NewThriftHandlerFunc
(
scheduleProcessor
,
scheduleProtocolFactory
,
scheduleProtocolFactory
)
mux
:=
http
.
NewServeMux
()
mux
:=
http
.
NewServeMux
()
mux
.
HandleFunc
(
"/schedule"
,
MiddleHandle
(
http
.
HandlerFunc
(
scheduleHandler
)))
mux
.
HandleFunc
(
"/schedule"
,
MiddleHandle
(
http
.
HandlerFunc
(
scheduleHandler
)))
log
.
Println
(
"thrift http server in"
,
config
.
GetHttpServerPort
())
http
.
ListenAndServe
(
config
.
GetHttpServerPort
(),
mux
)
http
.
ListenAndServe
(
config
.
GetHttpServerPort
(),
mux
)
}
}
...
...
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