commons-go/config/probe/container.go
crusader 38f12b4fbe ing
2018-05-04 17:37:08 +09:00

78 lines
1.6 KiB
Go

package probe
import (
"encoding/json"
"fmt"
)
const (
FlagProbePortName = "probe-port"
FlagLoggingConfigFilePathName = "logging-config-path"
)
var (
ContainerBinFileName = map[ContainerType]string{
ContainerDiscovery: "container_discovery",
ContainerNetwork: "container_network",
ContainerGenernal: "container_general.jar",
}
ContainerLoggingConfigFileName = map[ContainerType]string{
ContainerDiscovery: "discovery.logging.json",
ContainerNetwork: "network.logging.json",
ContainerGenernal: "general.logging.xml",
}
)
type ContainerType int
const (
ContainerDiscovery ContainerType = iota
ContainerNetwork
ContainerGenernal
)
var (
containerTypeID = map[ContainerType]string{
ContainerDiscovery: "DISCOVERY",
ContainerNetwork: "NETWORK",
ContainerGenernal: "GENERNAL",
}
containerTypeName = map[string]ContainerType{
"DISCOVERY": ContainerDiscovery,
"NETWORK": ContainerNetwork,
"GENERNAL": ContainerGenernal,
}
)
func ToContainerType(v string) ContainerType {
return containerTypeName[v]
}
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
}