From fac45a284db1e975786e0d75882ecd795283fa78 Mon Sep 17 00:00:00 2001 From: crusader Date: Wed, 18 Apr 2018 17:37:18 +0900 Subject: [PATCH] ing --- meta/model/MetaContainer.go | 14 +++++++++ meta/model/MetaCrawler.go | 1 + meta/model/MetaInfraVendor.go | 8 ++--- meta/model/MetaSensorItem.go | 10 +++---- probe/constants/container.go | 55 +++++++++++++++++++++++++++++++++++ 5 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 meta/model/MetaContainer.go create mode 100644 probe/constants/container.go diff --git a/meta/model/MetaContainer.go b/meta/model/MetaContainer.go new file mode 100644 index 0000000..f0aefbf --- /dev/null +++ b/meta/model/MetaContainer.go @@ -0,0 +1,14 @@ +package model + +import ( + "encoding/json" + + "git.loafle.net/overflow/commons-go/core/util" +) + +type MetaContainer struct { + ID json.Number `json:"id,Number,omitempty"` + Name string `json:"name,omitempty"` + Description string `json:"description,omitempty"` + CreateDate util.Timestamp `json:"createDate,omitempty"` +} diff --git a/meta/model/MetaCrawler.go b/meta/model/MetaCrawler.go index c6c070d..d3742ba 100644 --- a/meta/model/MetaCrawler.go +++ b/meta/model/MetaCrawler.go @@ -11,4 +11,5 @@ type MetaCrawler struct { Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` CreateDate util.Timestamp `json:"createDate,omitempty"` + Container *MetaContainer `json:"container,omitempty"` } diff --git a/meta/model/MetaInfraVendor.go b/meta/model/MetaInfraVendor.go index 1695431..135b8ae 100644 --- a/meta/model/MetaInfraVendor.go +++ b/meta/model/MetaInfraVendor.go @@ -7,8 +7,8 @@ import ( ) type MetaInfraVendor struct { - ID json.Number `json:"id,Number,omitempty"` - Name string `json:"name,omitempty"` - CreateDate util.Timestamp `json:"createDate,omitempty"` - MetaInfraType *MetaInfraType `json:"metaInfraType,omitempty"` + ID json.Number `json:"id,Number,omitempty"` + Name string `json:"name,omitempty"` + CreateDate util.Timestamp `json:"createDate,omitempty"` + InfraType *MetaInfraType `json:"infraType,omitempty"` } diff --git a/meta/model/MetaSensorItem.go b/meta/model/MetaSensorItem.go index 7979707..2777e19 100644 --- a/meta/model/MetaSensorItem.go +++ b/meta/model/MetaSensorItem.go @@ -7,9 +7,9 @@ import ( ) type MetaSensorItem struct { - ID json.Number `json:"id,Number,omitempty"` - MetaSensorItemType *MetaSensorItemType `json:"metaSensorItemType,omitempty"` - Key string `json:"key,omitempty"` - Name string `json:"name,omitempty"` - CreateDate util.Timestamp `json:"createDate,omitempty"` + ID json.Number `json:"id,Number,omitempty"` + SensorItemType *MetaSensorItemType `json:"sensorItemType,omitempty"` + Key string `json:"key,omitempty"` + Name string `json:"name,omitempty"` + CreateDate util.Timestamp `json:"createDate,omitempty"` } diff --git a/probe/constants/container.go b/probe/constants/container.go new file mode 100644 index 0000000..8186e03 --- /dev/null +++ b/probe/constants/container.go @@ -0,0 +1,55 @@ +package constants + +import ( + "encoding/json" + "fmt" +) + +type ContainerType int + +const ( + DISCOVERY ContainerType = iota + NETWORK + GENERNAL +) + +var ( + containerTypeID = map[ContainerType]string{ + DISCOVERY: "DISCOVERY", + NETWORK: "NETWORK", + GENERNAL: "GENERNAL", + } + + containerTypeName = map[string]ContainerType{ + "DISCOVERY": DISCOVERY, + "NETWORK": NETWORK, + "GENERNAL": GENERNAL, + } +) + +func (ct ContainerType) String() string { + return containerTypeID[ct] +} + +func (ct ContainerType) MarshalJSON() ([]byte, error) { + value, ok := containerTypeID[ct] + if !ok { + return nil, fmt.Errorf("Invalid EnumType[%s] value", ct) + } + return json.Marshal(value) +} + +func (ct ContainerType) UnmarshalJSON(b []byte) error { + var s string + err := json.Unmarshal(b, &s) + if err != nil { + return err + } + + value, ok := containerTypeName[s] + if !ok { + return fmt.Errorf("Invalid EnumType[%s] value", s) + } + ct = value + return nil +}