Commit 1c5665a0 by yunpeng.song

增加shedule http 接口

parent 2e3a72ce
......@@ -16,7 +16,8 @@
},
"thriftport": {
"loginserver": "9090",
"multserver": "9091"
"multserver": "9091",
"httpserver": "9081"
},
"eurekakey": {
"device": "dispatchserver"
......
......@@ -37,6 +37,7 @@ type (
ServerPortCFG struct {
LoginServer string `json:"loginserver"` // 消息推送服务端口
MultServer string `json:"multserver"` // 多服务复用端口
HttpServer string `json:"httpserver"` // http 服务端口
}
HeartTime struct {
......
......@@ -170,6 +170,11 @@ func GetMultServerPort() string {
return net.JoinHostPort("", ThriftPort.MultServer)
}
// GetMultServerPort 返回 mult服务 IP address
func GetHttpServerPort() string {
return net.JoinHostPort("", ThriftPort.HttpServer)
}
//GetClientMaxLostTimes 返回client maxlosttimes
func GetClientMaxLostTimes() int {
return Client.MaxLostTimes
......
......@@ -29,7 +29,7 @@ func InitLog() {
logName+".%Y-%m-%d-%H-%M.log",
rotatelogs.WithLinkName(logName), // 生成软链,指向最新日志文件
rotatelogs.WithMaxAge(30*24*time.Hour), // 文件最大保存时间
rotatelogs.WithRotationTime(2*time.Hour), // 日志切割时间间隔
rotatelogs.WithRotationTime(4*time.Hour), // 日志切割时间间隔
//rotatelogs.WithRotationTime(1*time.Minute),
)
writeMap := lfshook.WriterMap{
......
......@@ -15,6 +15,7 @@ import (
"ficus_clientserver/nethandle/thriftservice"
"ficus_clientserver/tool"
"fmt"
"net/http"
"os"
"os/exec"
"runtime/debug"
......@@ -127,6 +128,7 @@ func StartThrift() {
go StartThriftSever1()
go StartThriftSever2()
go StartClientHeartWork()
go StartHttpServer()
}
// StartClientHeartWork 开始循环心跳工作
......@@ -249,3 +251,24 @@ func StartThriftSever2() {
log.Panicln(err)
}
}
func StartHttpServer() {
scheduleHandle := thriftservice.NewScheduleHandle(MsgControl, ClientManager)
scheduleProcessor := native.NewScheduleServiceProcessor(scheduleHandle)
scheduleProtocolFactory := thrift.NewTJSONProtocolFactory()
scheduleHandler := thrift.NewThriftHandlerFunc(scheduleProcessor, scheduleProtocolFactory, scheduleProtocolFactory)
mux := http.NewServeMux()
mux.HandleFunc("/schedule", MiddleHandle(http.HandlerFunc(scheduleHandler)))
http.ListenAndServe(config.GetHttpServerPort(), mux)
}
func MiddleHandle(next http.Handler) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*") //允许访问所有域
w.Header().Set("Access-Control-Allow-Headers", "*")
//w.Header().Add("Access-Control-Allow-Headers", "Content-Type") //header的类型
w.Header().Set("content-type", "application/json") //返回数据格式是json
w.Header().Set("Access-Control-Allow-Methods", "*")
next.ServeHTTP(w, r)
})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment