2018-05-03 11:24:07 +00:00
|
|
|
package data
|
2018-04-14 11:04:07 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2018-05-11 03:55:35 +00:00
|
|
|
"net/url"
|
|
|
|
"path"
|
|
|
|
"strings"
|
2018-04-14 11:04:07 +00:00
|
|
|
|
2018-04-18 14:56:13 +00:00
|
|
|
logging "git.loafle.net/commons/logging-go"
|
2018-07-01 04:09:50 +00:00
|
|
|
cssc "git.loafle.net/commons/server-go/socket/client"
|
2018-04-26 08:39:32 +00:00
|
|
|
occp "git.loafle.net/overflow/commons-go/config/probe"
|
2018-05-03 11:24:07 +00:00
|
|
|
"git.loafle.net/overflow/probe/client"
|
2018-04-14 11:04:07 +00:00
|
|
|
"git.loafle.net/overflow/probe/config"
|
|
|
|
)
|
|
|
|
|
2018-07-01 04:09:50 +00:00
|
|
|
func New() (cssc.Connector, error) {
|
2018-05-11 03:55:35 +00:00
|
|
|
_config := config.GetConfig()
|
|
|
|
if nil == _config {
|
2018-04-14 11:04:07 +00:00
|
|
|
return nil, fmt.Errorf("Config is not available")
|
|
|
|
}
|
|
|
|
|
2018-05-03 11:24:07 +00:00
|
|
|
connector, err := client.NewConnector("Data", occp.HTTPEntry_Data)
|
2018-04-14 11:04:07 +00:00
|
|
|
if nil != err {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-05-11 03:55:35 +00:00
|
|
|
if config.Dev {
|
|
|
|
u := url.URL{
|
|
|
|
Scheme: "ws",
|
2018-06-14 07:24:05 +00:00
|
|
|
Host: fmt.Sprintf("%s:%d", strings.Split(_config.Central.Address, ":")[0], 19110),
|
2018-05-11 03:55:35 +00:00
|
|
|
}
|
|
|
|
u.Path = path.Join(u.Path, occp.HTTPEntry_Data)
|
|
|
|
connector.URL = u.String()
|
|
|
|
}
|
|
|
|
|
2018-04-14 11:04:07 +00:00
|
|
|
connector.RequestHeader = func() http.Header {
|
|
|
|
header := make(map[string][]string)
|
2018-04-26 08:39:32 +00:00
|
|
|
header[occp.HTTPRequestHeaderKey_Probe_Method] = []string{occp.HTTPRequestHeaderValue_Probe_Method_Connect}
|
2018-05-11 03:55:35 +00:00
|
|
|
header[occp.HTTPRequestHeaderKey_Probe_ProbeKey] = []string{*_config.Probe.Key}
|
2018-04-14 11:04:07 +00:00
|
|
|
return header
|
|
|
|
}
|
|
|
|
connector.ResponseHandler = func(res *http.Response) {
|
|
|
|
}
|
2018-07-01 04:09:50 +00:00
|
|
|
connector.OnDisconnected = func(connector cssc.Connector) {
|
2018-04-18 14:56:13 +00:00
|
|
|
logging.Logger().Debugf("Client[%s] has been disconnected", connector.GetName())
|
|
|
|
}
|
2018-04-14 11:04:07 +00:00
|
|
|
|
2018-05-11 06:37:31 +00:00
|
|
|
return connector, nil
|
2018-04-14 11:04:07 +00:00
|
|
|
}
|