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,15 +5,16 @@ import (
|
|||
|
||||
"github.com/google/gopacket"
|
||||
|
||||
"git.loafle.net/overflow/commons-go/core/constants"
|
||||
"git.loafle.net/overflow/commons-go/core/util"
|
||||
)
|
||||
|
||||
type Port struct {
|
||||
Host *Host `json:"host,omitempty"`
|
||||
|
||||
ID json.Number `json:"id,Number,omitempty"`
|
||||
PortType string `json:"portType,omitempty"`
|
||||
PortNumber json.Number `json:"portNumber,omitempty"`
|
||||
ID json.Number `json:"id,Number,omitempty"`
|
||||
PortType constants.PortType `json:"portType,omitempty"`
|
||||
PortNumber json.Number `json:"portNumber,omitempty"`
|
||||
|
||||
DiscoveredDate util.Timestamp `json:"discoveredDate,omitempty"`
|
||||
|
||||
|
|
|
@ -3,15 +3,16 @@ package model
|
|||
import (
|
||||
"encoding/json"
|
||||
|
||||
"git.loafle.net/overflow/commons-go/core/constants"
|
||||
"git.loafle.net/overflow/commons-go/core/util"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
Port *Port `json:"port,omitempty"`
|
||||
|
||||
ID json.Number `json:"id,Number,omitempty"`
|
||||
CryptoType string `json:"cryptoType,omitempty"`
|
||||
ServiceName string `json:"serviceName,omitempty"`
|
||||
ID json.Number `json:"id,Number,omitempty"`
|
||||
CryptoType constants.CryptoType `json:"cryptoType,omitempty"`
|
||||
ServiceName string `json:"serviceName,omitempty"`
|
||||
|
||||
DiscoveredDate util.Timestamp `json:"discoveredDate,omitempty"`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user