ing
This commit is contained in:
parent
7df953742d
commit
83807646bd
49
core/constants/network-crypto.go
Normal file
49
core/constants/network-crypto.go
Normal 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
|
||||||
|
}
|
|
@ -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"`
|
||||||
|
|
|
@ -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"`
|
||||||
|
|
Loading…
Reference in New Issue
Block a user