Skip to content

Commit

Permalink
code clean
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansu committed Jul 13, 2021
1 parent 924ecf2 commit ac30326
Show file tree
Hide file tree
Showing 25 changed files with 78 additions and 95 deletions.
2 changes: 1 addition & 1 deletion component/gin/middleware.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//from https://github.com/gin-contrib/zap/
// Package cherryGin from https://github.com/gin-contrib/zap/
package cherryGin

import (
Expand Down
14 changes: 7 additions & 7 deletions const/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (

// component name
const (
HandlerComponent = "handler_component"
SessionComponent = "session_component"
DataConfigComponent = "data_config_component"
ORMComponent = "db_orm_component"
ConnectorPomeloComponent = "connector_pomelo_component"
RPCServerComponent = "rpc_server_component"
RPCClientComponent = "rpc_client_component"
HandlerComponent = "handler_component"
SessionComponent = "session_component"
DataConfigComponent = "data_config_component"
ORMComponent = "db_orm_component"
ConnectorComponent = "connector_component"
RPCServerComponent = "rpc_server_component"
RPCClientComponent = "rpc_client_component"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion error/define.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var (
MessageReplyShouldBeNotNull = Error("message replay should be not null")
)

// serializer protobuf
// protobuf
var (
ProtobufWrongValueType = Error("convert on wrong type value")
)
3 changes: 1 addition & 2 deletions extend/map/safe_map.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// file from https://github.com/beego/beego/blob/develop/core/utils/safemap.go

// Package cherryMap file from https://github.com/beego/beego/blob/develop/core/utils/safemap.go
package cherryMap

import (
Expand Down
3 changes: 1 addition & 2 deletions extend/map/string_any_map.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// file from https://github.com/gogf/gf

// Package cherryMap file from https://github.com/gogf/gf
package cherryMap

import (
Expand Down
2 changes: 1 addition & 1 deletion extend/mapstructure/error.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// file from https://github.com/goinggo/mapstructure
// Package cherryMapStructure file from https://github.com/goinggo/mapstructure
package cherryMapStructure

import (
Expand Down
57 changes: 29 additions & 28 deletions extend/mapstructure/mapstructure.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package cherryMapStructure
// code from https://github.com/goinggo/mapstructure
// The mapstructure package exposes functionality to convert an
// abitrary map[string]interface{} into a native Go structure.
Expand Down Expand Up @@ -126,7 +127,7 @@ func DecodeSlicePath(ms []map[string]interface{}, rawSlice interface{}) error {

if (rawKind == reflect.Ptr && rawElement.Kind() != reflect.Slice) ||
(rawKind != reflect.Ptr && rawKind != reflect.Slice) {
return fmt.Errorf("Incompatible Value, Looking For Slice : %v : %v", rawKind, rawElement.Kind())
return fmt.Errorf("incompatible value, looking for slice : %v : %v", rawKind, rawElement.Kind())
}

config := &DecoderConfig{
Expand Down Expand Up @@ -244,16 +245,16 @@ func (d *Decoder) DecodePath(m map[string]interface{}, rawVal interface{}) (bool
case reflect.Ptr:
val = reflectRawValue.Elem()
if val.Kind() != reflect.Struct {
return decoded, fmt.Errorf("Incompatible Type : %v : Looking For Struct", kind)
return decoded, fmt.Errorf("incompatible type : %v : looking for struct", kind)
}
case reflect.Struct:
var ok bool
val, ok = rawVal.(reflect.Value)
if ok == false {
return decoded, fmt.Errorf("Incompatible Type : %v : Looking For reflect.Value", kind)
return decoded, fmt.Errorf("incompatible type : %v : looking for reflect.Value", kind)
}
default:
return decoded, fmt.Errorf("Incompatible Type : %v", kind)
return decoded, fmt.Errorf("incompatible type : %v", kind)
}

// Iterate over the fields in the struct
Expand Down Expand Up @@ -294,7 +295,7 @@ func (d *Decoder) DecodePath(m map[string]interface{}, rawVal interface{}) (bool
if valueField.Kind() == reflect.Slice {
// Ignore a slice of maps - This sucks but not sure how to check
if strings.Contains(valueField.Type().String(), "map[") {
goto normal_decode
goto normalDecode
}

// We have a slice
Expand All @@ -303,7 +304,7 @@ func (d *Decoder) DecodePath(m map[string]interface{}, rawVal interface{}) (bool
// Test if this is a slice of more maps
_, ok := mapSlice[0].(map[string]interface{})
if ok == false {
goto normal_decode
goto normalDecode
}

// Extract the maps out and run it through DecodeSlicePath
Expand All @@ -316,7 +317,7 @@ func (d *Decoder) DecodePath(m map[string]interface{}, rawVal interface{}) (bool
continue
}
}
normal_decode:
normalDecode:
decoded = true
err := d.decode("", data, valueField)
if err != nil {
Expand Down Expand Up @@ -570,7 +571,7 @@ func (d *Decoder) decodeFloat(name string, data interface{}, val reflect.Value)
case dataKind == reflect.Uint:
val.SetFloat(float64(dataVal.Uint()))
case dataKind == reflect.Float32:
val.SetFloat(float64(dataVal.Float()))
val.SetFloat(dataVal.Float())
case dataKind == reflect.Bool && d.config.WeaklyTypedInput:
if dataVal.Bool() {
val.SetFloat(1)
Expand Down Expand Up @@ -617,23 +618,23 @@ func (d *Decoder) decodeMap(name string, data interface{}, val reflect.Value) er
}

// Accumulate errors
errors := make([]string, 0)
errorSlice := make([]string, 0)

for _, k := range dataVal.MapKeys() {
fieldName := fmt.Sprintf("%s[%s]", name, k)

// First decode the key into the proper type
currentKey := reflect.Indirect(reflect.New(valKeyType))
if err := d.decode(fieldName, k.Interface(), currentKey); err != nil {
errors = appendErrors(errors, err)
errorSlice = appendErrors(errorSlice, err)
continue
}

// Next decode the data into the proper type
v := dataVal.MapIndex(k).Interface()
currentVal := reflect.Indirect(reflect.New(valElemType))
if err := d.decode(fieldName, v, currentVal); err != nil {
errors = appendErrors(errors, err)
errorSlice = appendErrors(errorSlice, err)
continue
}

Expand All @@ -644,8 +645,8 @@ func (d *Decoder) decodeMap(name string, data interface{}, val reflect.Value) er
val.Set(valMap)

// If we had errors, return those
if len(errors) > 0 {
return &Error{errors}
if len(errorSlice) > 0 {
return &Error{errorSlice}
}

return nil
Expand Down Expand Up @@ -674,24 +675,24 @@ func (d *Decoder) decodeSlice(name string, data interface{}, val reflect.Value)
}

// Accumulate any errors
errors := make([]string, 0)
errorSlice := make([]string, 0)

for i := 0; i < dataVal.Len(); i++ {
currentData := dataVal.Index(i).Interface()
currentField := valSlice.Index(i)

fieldName := fmt.Sprintf("%s[%d]", name, i)
if err := d.decode(fieldName, currentData, currentField); err != nil {
errors = appendErrors(errors, err)
errorSlice = appendErrors(errorSlice, err)
}
}

// Finally, set the value to the slice we built up
val.Set(valSlice)

// If there were errors, we return those
if len(errors) > 0 {
return &Error{errors}
if len(errorSlice) > 0 {
return &Error{errorSlice}
}

return nil
Expand All @@ -718,7 +719,7 @@ func (d *Decoder) decodeStruct(name string, data interface{}, val reflect.Value)
dataValKeysUnused[dataValKey.Interface()] = struct{}{}
}

errors := make([]string, 0)
errorSlice := make([]string, 0)

// This slice will keep track of all the structs we'll be decoding.
// There can be more than one struct if there are embedded structs
Expand All @@ -740,8 +741,8 @@ func (d *Decoder) decodeStruct(name string, data interface{}, val reflect.Value)
if fieldType.Anonymous {
fieldKind := fieldType.Type.Kind()
if fieldKind != reflect.Struct {
errors = appendErrors(errors,
fmt.Errorf("%s: unsupported type: %s", fieldType.Name, fieldKind))
fmtError := fmt.Errorf("%s: unsupported type: %s", fieldType.Name, fieldKind)
errorSlice = appendErrors(errorSlice, fmtError)
continue
}

Expand Down Expand Up @@ -781,7 +782,7 @@ func (d *Decoder) decodeStruct(name string, data interface{}, val reflect.Value)
if !rawMapVal.IsValid() {
// Do a slower search by iterating over each key and
// doing case-insensitive search.
for dataValKey, _ := range dataValKeys {
for dataValKey := range dataValKeys {
mK, ok := dataValKey.Interface().(string)
if !ok {
// Not a string key
Expand Down Expand Up @@ -823,28 +824,28 @@ func (d *Decoder) decodeStruct(name string, data interface{}, val reflect.Value)
}

if err := d.decode(fieldName, rawMapVal.Interface(), field); err != nil {
errors = appendErrors(errors, err)
errorSlice = appendErrors(errorSlice, err)
}
}

if d.config.ErrorUnused && len(dataValKeysUnused) > 0 {
keys := make([]string, 0, len(dataValKeysUnused))
for rawKey, _ := range dataValKeysUnused {
for rawKey := range dataValKeysUnused {
keys = append(keys, rawKey.(string))
}
sort.Strings(keys)

err := fmt.Errorf("'%s' has invalid keys: %s", name, strings.Join(keys, ", "))
errors = appendErrors(errors, err)
fmtError := fmt.Errorf("'%s' has invalid keys: %s", name, strings.Join(keys, ", "))
errorSlice = appendErrors(errorSlice, fmtError)
}

if len(errors) > 0 {
return &Error{errors}
if len(errorSlice) > 0 {
return &Error{errorSlice}
}

// Add the unused keys to the list of unused keys if we're tracking metadata
if d.config.Metadata != nil {
for rawKey, _ := range dataValKeysUnused {
for rawKey := range dataValKeysUnused {
key := rawKey.(string)
if name != "" {
key = fmt.Sprintf("%s.%s", name, key)
Expand Down
3 changes: 1 addition & 2 deletions extend/regex/regex.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// file from https://github.com/gogf/gf

// Package cherryRegex file from https://github.com/gogf/gf
package cherryRegex

import "regexp"
Expand Down
2 changes: 1 addition & 1 deletion extend/slice/slice.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// code from: https://github.com/beego/beego/blob/develop/core/utils/slice.go
// Package cherySlice code from: https://github.com/beego/beego/blob/develop/core/utils/slice.go
package cherySlice

import (
Expand Down
6 changes: 3 additions & 3 deletions extend/time/time.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// code from: https://github.com/golang-module/carbon
// Package cherryTime code from: https://github.com/golang-module/carbon
package cherryTime

import (
Expand Down Expand Up @@ -112,7 +112,7 @@ func CreateFromTime(hour int, minute int, second int) CherryTime {
return NewTime(t, false)
}

// parseByDuration 通过持续时间解析
// ParseByDuration 通过持续时间解析
func ParseByDuration(duration string) (time.Duration, error) {
td, err := time.ParseDuration(duration)
if err != nil {
Expand All @@ -121,7 +121,7 @@ func ParseByDuration(duration string) (time.Duration, error) {
return td, err
}

// getAbsValue 获取绝对值
// GetAbsValue 获取绝对值
func GetAbsValue(value int64) int64 {
return (value ^ value>>31) - value>>31
}
2 changes: 1 addition & 1 deletion extend/time/time_compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (c CherryTime) IsJanuary() bool {
return c.Time.Month() == time.January
}

// IsMonday 是否是二月
// IsFebruary 是否是二月
func (c CherryTime) IsFebruary() bool {
return c.Time.Month() == time.February
}
Expand Down
6 changes: 3 additions & 3 deletions extend/time/time_traveler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"time"
)

// AddDurations 按照持续时间字符串增加时间
// AddDuration 按照持续时间字符串增加时间
// 支持整数/浮点数和符号ns(纳秒)、us(微妙)、ms(毫秒)、s(秒)、m(分钟)、h(小时)的组合
func (c *CherryTime) AddDuration(duration string) error {
td, err := ParseByDuration(duration)
Expand All @@ -16,7 +16,7 @@ func (c *CherryTime) AddDuration(duration string) error {
return nil
}

// SubDurations 按照持续时间字符串减少时间
// SubDuration 按照持续时间字符串减少时间
// 支持整数/浮点数和符号ns(纳秒)、us(微妙)、ms(毫秒)、s(秒)、m(分钟)、h(小时)的组合
func (c *CherryTime) SubDuration(duration string) error {
return c.AddDuration("-" + duration)
Expand Down Expand Up @@ -125,7 +125,7 @@ func (c *CherryTime) AddQuarter() {
c.AddQuarters(1)
}

// NextQuarters 1季度后(月份不溢出)
// AddQuarterNoOverflow 1季度后(月份不溢出)
func (c *CherryTime) AddQuarterNoOverflow() {
c.AddQuartersNoOverflow(1)
}
Expand Down
3 changes: 1 addition & 2 deletions extend/utils/utils_array.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// file from https://github.com/gogf/gf

// Package cherryUtils file from https://github.com/gogf/gf
package cherryUtils

import "reflect"
Expand Down
3 changes: 1 addition & 2 deletions extend/utils/utils_empty.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// file from https://github.com/gogf/gf

// Package cherryUtils file from https://github.com/gogf/gf
package cherryUtils

import "reflect"
Expand Down
3 changes: 1 addition & 2 deletions extend/utils/utils_letter.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// file from https://github.com/gogf/gf

// Package cherryUtils file from https://github.com/gogf/gf
package cherryUtils

// IsLetterUpper checks whether the given byte b is in upper case.
Expand Down
2 changes: 1 addition & 1 deletion facade/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cherryFacade
import jsoniter "github.com/json-iterator/go"

type (
// {key:nodeType,value:{key:nodeId,value:INode}}
// NodeMap {key:nodeType,value:{key:nodeId,value:INode}}
NodeMap map[string]map[string]INode
)

Expand Down
2 changes: 1 addition & 1 deletion facade/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type IConnector interface {
OnConnect(listener ...OnConnectListener) // 启动前设置连接器监听函数
}

// 建立连接时的监听函数
// OnConnectListener 建立连接时监听的函数
type OnConnectListener func(conn INetConn)

type INetConn interface {
Expand Down
Loading

0 comments on commit ac30326

Please sign in to comment.