diff --git a/file_type.go b/file_type.go index a39ee6f..73977d5 100644 --- a/file_type.go +++ b/file_type.go @@ -7,13 +7,41 @@ // Date : 2023-08-11 10:59 package consts +type FileType string + +func (ft FileType) String() string { + return string(ft) +} + +func (ft FileType) MarshalJSON() ([]byte, error) { + return []byte(ft.String()), nil +} + +func (ft FileType) IsValid() bool { + supportFileTypeList := []FileType{ + FileTypeJson, + FileTypeIni, + FileTypeYml, + FileTypeYaml, + FileTypeToml, + FileTypeXml, + FileTypeTxt, + } + for _, fileType := range supportFileTypeList { + if fileType == ft { + return true + } + } + return false +} + const ( - FileTypeJson = "json" // json格式文件 - FileTypeIni = "ini" // ini格式文件 - FileTypeYml = "yml" // yml 格式文件 - FileTypeYaml = "yaml" // yaml格式文件 - FileTypeToml = "toml" // toml格式文件 - FileTypeXml = "xml" // xml格式文件 - FileTypeTxt = "txt" // txt格式文件 - FileTypeUnknown = "unknown" // 未知格式 + FileTypeJson FileType = "json" // json格式文件 + FileTypeIni FileType = "ini" // ini格式文件 + FileTypeYml FileType = "yml" // yml 格式文件 + FileTypeYaml FileType = "yaml" // yaml格式文件 + FileTypeToml FileType = "toml" // toml格式文件 + FileTypeXml FileType = "xml" // xml格式文件 + FileTypeTxt FileType = "txt" // txt格式文件 + FileTypeUnknown FileType = "unknown" // 未知格式 ) diff --git a/header.go b/header.go index 85d528c..d0b9577 100644 --- a/header.go +++ b/header.go @@ -7,10 +7,20 @@ // Date : 2024-01-04 20:28 package consts +type HttpHeader string + +func (hh HttpHeader) String() string { + return string(hh) +} + +func (hh HttpHeader) MarshalJSON() ([]byte, error) { + return []byte(hh.String()), nil +} + const ( - HeaderKeyAccessControlAllowOrigin = "Access-Control-Allow-Origin" // 标识允许哪个域的请求 - HeaderKeyAccessControlAllowHeaders = "Access-Control-Allow-Headers" // 标识允许的请求header - HeaderKeyAccessControlAllowMethods = "Access-Control-Allow-Methods" // 标识允许的请求方法 - HeaderKeyAccessControlExposeHeaders = "Access-Control-Expose-Headers" // 允许浏览器端能够获取相应的header值 - HeaderKeyAccessControlMaxAge = "Access-Control-Max-Age" // 控制发送预检请求options的频率,单位 : 秒 + HeaderKeyAccessControlAllowOrigin HttpHeader = "Access-Control-Allow-Origin" // 标识允许哪个域的请求 + HeaderKeyAccessControlAllowHeaders HttpHeader = "Access-Control-Allow-Headers" // 标识允许的请求header + HeaderKeyAccessControlAllowMethods HttpHeader = "Access-Control-Allow-Methods" // 标识允许的请求方法 + HeaderKeyAccessControlExposeHeaders HttpHeader = "Access-Control-Expose-Headers" // 允许浏览器端能够获取相应的header值 + HeaderKeyAccessControlMaxAge HttpHeader = "Access-Control-Max-Age" // 控制发送预检请求options的频率,单位 : 秒 ) diff --git a/logger.go b/logger.go index 3ab7621..cc10cd8 100644 --- a/logger.go +++ b/logger.go @@ -7,14 +7,64 @@ // Date : 2024-06-24 15:46 package consts +type LogLevel string + +func (ll LogLevel) String() string { + return string(ll) +} + +func (ll LogLevel) MarshalJSON() ([]byte, error) { + return []byte(ll.String()), nil +} + +func (ll LogLevel) IsValid() bool { + levelList := []LogLevel{ + LogLevelDebug, + LogLevelInfo, + LogLevelWarn, + LogLevelError, + LogLevelPanic, + } + for _, level := range levelList { + if level == ll { + return true + } + } + return false +} + const ( - LogLevelDebug = "DEBUG" - LogLevelInfo = "INFO" - LogLevelWarn = "WARN" - LogLevelError = "ERROR" - LogLevelPanic = "PANIC" + LogLevelDebug LogLevel = "DEBUG" + LogLevelInfo LogLevel = "INFO" + LogLevelWarn LogLevel = "WARN" + LogLevelError LogLevel = "ERROR" + LogLevelPanic LogLevel = "PANIC" ) +type LogSplit string + +func (ls LogSplit) String() string { + return string(ls) +} +func (ls LogSplit) MarshalJSON() ([]byte, error) { + return []byte(ls.String()), nil +} + +func (ls LogSplit) IsValid() bool { + supportSplitList := []LogSplit{ + LogSplitHour, + LogSplitDay, + LogSplitMonth, + LogSplitYear, + } + for _, supportSplit := range supportSplitList { + if supportSplit == ls { + return true + } + } + return false +} + const ( LogSplitHour = "HOUR" LogSplitDay = "DAY" diff --git a/redis.go b/redis.go index c4012fb..cb98ec6 100644 --- a/redis.go +++ b/redis.go @@ -7,29 +7,39 @@ // Date : 2024-10-08 16:32 package consts +type RedisCmd string + +func (rc RedisCmd) String() string { + return string(rc) +} + +func (rc RedisCmd) MarshalJSON() ([]byte, error) { + return []byte(rc.String()), nil +} + const ( - RedisCommandExists = "EXISTS" - RedisCommandTTL = "TTL" - RedisCommandSet = "SET" - RedisCommandDel = "DEL" - RedisCommandGet = "GET" - RedisCommandHget = "HGET" - RedisCommandHset = "HSET" - RedisCommandHdel = "HDEL" - RedisCommandMGet = "MGET" - RedisCommandMSet = "MSET" - RedisCommandLpush = "LPUSH" - RedisCommandLpop = "LPOP" - RedisCommandRpush = "RPUSH" - RedisCommandRpop = "RPOP" - RedisCommandSadd = "SADD" - RedisCommandSunionstore = "SUNIONSTORE" - RedisCommandZadd = "ZADD" - RedisCommandZincrby = "ZINCRBY" - RedisCommandPsubScribe = "PSUBSCRIBE" - RedisCommandPubsub = "PUBSUB" - RedisCommandPublish = "PUBLISH" - RedisCommandPunsubScribe = "PUNSUBSCRIBE" - RedisCommandSubscribe = "SUBSCRIBE" - RedisCommandUnsubscribe = "UNSUBSCRIBE" + RedisCommandExists RedisCmd = "EXISTS" + RedisCommandTTL RedisCmd = "TTL" + RedisCommandSet RedisCmd = "SET" + RedisCommandDel RedisCmd = "DEL" + RedisCommandGet RedisCmd = "GET" + RedisCommandHget RedisCmd = "HGET" + RedisCommandHset RedisCmd = "HSET" + RedisCommandHdel RedisCmd = "HDEL" + RedisCommandMGet RedisCmd = "MGET" + RedisCommandMSet RedisCmd = "MSET" + RedisCommandLpush RedisCmd = "LPUSH" + RedisCommandLpop RedisCmd = "LPOP" + RedisCommandRpush RedisCmd = "RPUSH" + RedisCommandRpop RedisCmd = "RPOP" + RedisCommandSadd RedisCmd = "SADD" + RedisCommandSunionstore RedisCmd = "SUNIONSTORE" + RedisCommandZadd RedisCmd = "ZADD" + RedisCommandZincrby RedisCmd = "ZINCRBY" + RedisCommandPsubScribe RedisCmd = "PSUBSCRIBE" + RedisCommandPubsub RedisCmd = "PUBSUB" + RedisCommandPublish RedisCmd = "PUBLISH" + RedisCommandPunsubScribe RedisCmd = "PUNSUBSCRIBE" + RedisCommandSubscribe RedisCmd = "SUBSCRIBE" + RedisCommandUnsubscribe RedisCmd = "UNSUBSCRIBE" ) diff --git a/scheme.go b/scheme.go index 26e6bfc..fda9a86 100644 --- a/scheme.go +++ b/scheme.go @@ -7,32 +7,42 @@ // Date : 2024-01-01 14:33 package consts +type HttpScheme string + +func (hs HttpScheme) String() string { + return string(hs) +} + +func (hs HttpScheme) MarshalJSON() ([]byte, error) { + return []byte(hs.String()), nil +} + const ( - SchemeHTTP = "http" - SchemeHTTPS = "https" - SchemeWs = "ws" - SchemeWss = "wss" + SchemeHTTP HttpScheme = "http" + SchemeHTTPS HttpScheme = "https" + SchemeWs HttpScheme = "ws" + SchemeWss HttpScheme = "wss" - SchemeSms = "sms" // SchemeSms 短信 - SchemeTel = "tel" // SchemeTel 电话 - SchemeMobileNotes = "mobilenotes" // SchemeMobileNotes 备忘录 - SchemeMessage = "MESSAGE" // SchemeMessage E-MAIL + SchemeSms HttpScheme = "sms" // SchemeSms 短信 + SchemeTel HttpScheme = "tel" // SchemeTel 电话 + SchemeMobileNotes HttpScheme = "mobilenotes" // SchemeMobileNotes 备忘录 + SchemeMessage HttpScheme = "MESSAGE" // SchemeMessage E-MAIL - SchemeAliPay = "alipay" // SchemeAliPay 支付宝 - SchemeDingTalk = "dingtalk" // SchemeDingTalk 钉钉 - SchemeWeChat = "wechat" // SchemeWeChat 微信 - SchemeWeiXin = "weixin" // SchemeWeiXin 微信 + SchemeAliPay HttpScheme = "alipay" // SchemeAliPay 支付宝 + SchemeDingTalk HttpScheme = "dingtalk" // SchemeDingTalk 钉钉 + SchemeWeChat HttpScheme = "wechat" // SchemeWeChat 微信 + SchemeWeiXin HttpScheme = "weixin" // SchemeWeiXin 微信 - SchemeTCP = "tcp" - SchemeUDP = "udp" - SchemeUnix = "unix" - SchemeKCP = "kcp" - SchemeQuic = "quic" - SchemeGRPC = "grpc" - SchemeMQTT = "mqtt" - SchemeMQTT5 = "mqtt5" - SchemeMQTTN = "mqttn" - SchemeMQTTv3 = "mqttv3" - SchemeMQTTv4 = "mqttv4" - SchemeMQTTv5 = "mqttv5" + SchemeTCP HttpScheme = "tcp" + SchemeUDP HttpScheme = "udp" + SchemeUnix HttpScheme = "unix" + SchemeKCP HttpScheme = "kcp" + SchemeQuic HttpScheme = "quic" + SchemeGRPC HttpScheme = "grpc" + SchemeMQTT HttpScheme = "mqtt" + SchemeMQTT5 HttpScheme = "mqtt5" + SchemeMQTTN HttpScheme = "mqttn" + SchemeMQTTv3 HttpScheme = "mqttv3" + SchemeMQTTv4 HttpScheme = "mqttv4" + SchemeMQTTv5 HttpScheme = "mqttv5" )