model/meta/MetaIPType.go
2018-08-12 19:46:46 +09:00

48 lines
908 B
Go

package meta
import (
"encoding/json"
"git.loafle.net/overflow/model/util"
)
type MetaIPType struct {
ID json.Number `json:"id,Number,omitempty"`
Name string `json:"name,omitempty"`
Key string `json:"key,omitempty"`
CreateDate *util.Timestamp `json:"createDate,omitempty"`
}
type MetaIPTypeEnum int
const (
MetaIPTypeEnumV4 MetaIPTypeEnum = iota + 1
MetaIPTypeEnumV6
)
var (
metaIPTypeEnumID = map[MetaIPTypeEnum]string{
MetaIPTypeEnumV4: "V4",
MetaIPTypeEnumV6: "V6",
}
metaIPTypeEnumKey = map[string]MetaIPTypeEnum{
"V4": MetaIPTypeEnumV4,
"V6": MetaIPTypeEnumV6,
}
)
func (e MetaIPTypeEnum) String() string {
return metaIPTypeEnumID[e]
}
func ToMetaIPTypeEnum(v *MetaIPType) MetaIPTypeEnum {
return metaIPTypeEnumKey[v.Key]
}
func ToMetaIPType(v MetaIPTypeEnum) *MetaIPType {
return &MetaIPType{
Key: metaIPTypeEnumID[v],
}
}