75 lines
1.8 KiB
Go
75 lines
1.8 KiB
Go
package probe
|
|
|
|
import (
|
|
"encoding/json"
|
|
//"fmt"
|
|
//"git.loafle.net/overflow/overflow_service/proxy"
|
|
|
|
"git.loafle.net/overflow/overflow_service/proxy/utils"
|
|
|
|
"git.loafle.net/overflow/commons_go/model/timestamp"
|
|
"git.loafle.net/overflow/overflow_service/proxy/domain"
|
|
"git.loafle.net/overflow/overflow_service/proxy/meta"
|
|
)
|
|
|
|
type ProbeService struct {
|
|
}
|
|
|
|
type Probe struct {
|
|
Id json.Number `json:"id,Number,omitempty"`
|
|
Status *meta.MetaProbeStatus `json:"status,omitempty"`
|
|
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
|
LastPollingDate timestamp.Timestamp `json:"lastPollingDate,omitempty"`
|
|
NextPollingDate timestamp.Timestamp `json:"nextPollingDate,omitempty"`
|
|
Domain *domain.Domain `json:"domain,omitempty"`
|
|
ProbeKey string `json:"probeKey,omitempty"`
|
|
EncryptionKey string `json:"encryptionKey,omitempty"`
|
|
}
|
|
|
|
func NewProbeService() *ProbeService {
|
|
return &ProbeService{}
|
|
}
|
|
|
|
func NewProbe(probeKey string, encryptionKey string) *Probe {
|
|
|
|
na := &Probe{
|
|
Status: meta.NewMetaProbeStatus(meta.PROBE_STATUS_INITIAL),
|
|
ProbeKey: probeKey,
|
|
EncryptionKey: encryptionKey,
|
|
}
|
|
return na
|
|
}
|
|
|
|
func (as *ProbeService) Regist(p *Probe) (string, error) {
|
|
|
|
out, err := utils.InvokeDBByModel("probe", "save", p, utils.MODEL_PROBE)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return out, nil
|
|
}
|
|
|
|
func (as *ProbeService) ReadAllByDomain(d *domain.Domain) (string, error) {
|
|
|
|
out, err := utils.InvokeDBByModel("probe", "findAllByDomain", d, utils.MODEL_DOMAIN)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return out, nil
|
|
}
|
|
|
|
func (as *ProbeService) ReadByProbeKey(probeKey string) (string, error) {
|
|
|
|
out, err := utils.InvokeDBByModel("probe", "findByProbeKey", probeKey, utils.MODEL_STRING)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return out, nil
|
|
}
|