probe/client/central/probe.go

38 lines
1.1 KiB
Go
Raw Normal View History

2018-04-14 08:57:01 +00:00
package central
2018-04-14 11:04:07 +00:00
import (
"fmt"
"net/http"
crc "git.loafle.net/commons/rpc-go/client"
ocnpc "git.loafle.net/overflow/commons-go/probe/constants"
"git.loafle.net/overflow/probe/config"
)
func NewProbe(encryptionKeyHandler func(encryptionKey string), services []interface{}) (*crc.Client, error) {
config := config.GetConfig()
if nil == config {
return nil, fmt.Errorf("Config is not available")
}
connector, err := newConnector("Probe", ocnpc.HTTPEntry_Probe)
if nil != err {
return nil, err
}
connector.RequestHeader = func() http.Header {
header := make(map[string][]string)
header[ocnpc.HTTPRequestHeaderKey_Probe_Method] = []string{ocnpc.HTTPRequestHeaderValue_Probe_Method_Connect}
header[ocnpc.HTTPRequestHeaderKey_Probe_ProbeKey] = []string{*config.Probe.Key}
return header
}
connector.ResponseHandler = func(res *http.Response) {
encryptionKey := res.Header.Get(ocnpc.HTTPResponseHeaderKey_Probe_SetEncryptionKey)
if nil != encryptionKeyHandler {
encryptionKeyHandler(encryptionKey)
}
}
return newClient("Probe", connector, services), nil
}