This commit is contained in:
crusader 2018-04-19 17:25:56 +09:00
parent 7df953742d
commit 83807646bd
4 changed files with 57 additions and 6 deletions

View File

@ -0,0 +1,49 @@
package constants
import (
"encoding/json"
"fmt"
)
type CryptoType int
const (
CryptoTypeTLS CryptoType = iota
)
var (
cryptoTypeID = map[CryptoType]string{
CryptoTypeTLS: "TLS",
}
cryptoTypeName = map[string]CryptoType{
"TLS": CryptoTypeTLS,
}
)
func (ct CryptoType) String() string {
return cryptoTypeID[ct]
}
func (ct CryptoType) MarshalJSON() ([]byte, error) {
value, ok := cryptoTypeID[ct]
if !ok {
return nil, fmt.Errorf("Invalid EnumType[%s] value", ct)
}
return json.Marshal(value)
}
func (ct CryptoType) UnmarshalJSON(b []byte) error {
var s string
err := json.Unmarshal(b, &s)
if err != nil {
return err
}
value, ok := cryptoTypeName[s]
if !ok {
return fmt.Errorf("Invalid EnumType[%s] value", s)
}
ct = value
return nil
}

View File

@ -5,6 +5,7 @@ import (
"github.com/google/gopacket" "github.com/google/gopacket"
"git.loafle.net/overflow/commons-go/core/constants"
"git.loafle.net/overflow/commons-go/core/util" "git.loafle.net/overflow/commons-go/core/util"
) )
@ -12,7 +13,7 @@ type Port struct {
Host *Host `json:"host,omitempty"` Host *Host `json:"host,omitempty"`
ID json.Number `json:"id,Number,omitempty"` ID json.Number `json:"id,Number,omitempty"`
PortType string `json:"portType,omitempty"` PortType constants.PortType `json:"portType,omitempty"`
PortNumber json.Number `json:"portNumber,omitempty"` PortNumber json.Number `json:"portNumber,omitempty"`
DiscoveredDate util.Timestamp `json:"discoveredDate,omitempty"` DiscoveredDate util.Timestamp `json:"discoveredDate,omitempty"`

View File

@ -3,6 +3,7 @@ package model
import ( import (
"encoding/json" "encoding/json"
"git.loafle.net/overflow/commons-go/core/constants"
"git.loafle.net/overflow/commons-go/core/util" "git.loafle.net/overflow/commons-go/core/util"
) )
@ -10,7 +11,7 @@ type Service struct {
Port *Port `json:"port,omitempty"` Port *Port `json:"port,omitempty"`
ID json.Number `json:"id,Number,omitempty"` ID json.Number `json:"id,Number,omitempty"`
CryptoType string `json:"cryptoType,omitempty"` CryptoType constants.CryptoType `json:"cryptoType,omitempty"`
ServiceName string `json:"serviceName,omitempty"` ServiceName string `json:"serviceName,omitempty"`
DiscoveredDate util.Timestamp `json:"discoveredDate,omitempty"` DiscoveredDate util.Timestamp `json:"discoveredDate,omitempty"`