commons-go/probe/constants/container.go
crusader 572ab7844e ing
2018-04-18 20:20:43 +09:00

74 lines
1.5 KiB
Go

package constants
import (
"encoding/json"
"fmt"
)
const (
FlagPidFilePathName = "pid-path"
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.json",
}
)
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 (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
}