Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/bobohume/gonet
Browse files Browse the repository at this point in the history
  • Loading branch information
bobohume committed Oct 16, 2022
2 parents 6cf9dd7 + c82edde commit 0dc6050
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion base/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (this *Log) Fatalf(format string, params ...interface{}) {
func (this *Log) WriteFile(nType LG_TYPE) {
var err error
tTime := time.Now()
if this.logFile[nType] == nil || this.logTime.Year() != tTime.Year() ||
if this.logTime.Year() != tTime.Year() ||
this.logTime.Month() != tTime.Month() || this.logTime.Day() != tTime.Day() {
this.loceker.Lock()
if this.logFile[nType] != nil {
Expand Down
14 changes: 7 additions & 7 deletions base/uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ import (
/*
* Snowflake
*
* 1 39 52 64
* 1 42 54 64
* +-----------------------------------------------+----------------+---------------+
* | timestamp(ms) | workerid | sequence |
* +-----------------------------------------------+----------------+---------------+
* | 0000000000 0000000000 0000000000 0000000000 0 | 0000000000 000 | 0000000000 00 |
* | 0000000000 0000000000 0000000000 0000000000 0 | 0000000000 00 | 0000000000 |
* +-----------------------------------------------+----------------+---------------+
*
* 1. 39位时间截(毫秒级),注意这是时间截的差值(当前时间截 - 开始时间截)。可以使用约7年: (1L << 39) / (1000L * 60 * 60 * 24 * 365) = 8
* 2. 13位数据机器位,可以部署在8096个节点
* 3. 12位序列,毫秒内的计数,同一机器,同一时间截并发4096个序号
* 1. 41位时间截(毫秒级),注意这是时间截的差值(当前时间截 - 开始时间截)。可以使用约69年: (1L << 41) / (1000L * 60 * 60 * 24 * 365) = 69
* 2. 12位数据机器位,可以部署在4096个节点
* 3. 10位序列,毫秒内的计数,同一机器,同一时间截并发1024个序号
*/
const (
twepoch = int64(1483228800000) //开始时间截 (2017-01-01)
workeridBits = uint(13) //机器id所占的位数
sequenceBits = uint(12) //序列所占的位数
workeridBits = uint(12) //机器id所占的位数
sequenceBits = uint(10) //序列所占的位数
workeridMax = int64(-1 ^ (-1 << workeridBits)) //支持的最大机器id数量
sequenceMask = int64(-1 ^ (-1 << sequenceBits)) //
workeridShift = sequenceBits //机器id左移位数
Expand Down
12 changes: 6 additions & 6 deletions orm/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type (
Json bool
Ignore bool
Table bool //table name
Froce bool //update ignore is zero
Force bool //update ignore is zero
tag string
}

Expand Down Expand Up @@ -177,9 +177,9 @@ func (this *Properties) IsTable() bool {
}

//is zero can update
//tablename `sql:"froce"`
func (this *Properties) IsFroce() bool {
return this.Froce
//tablename `sql:"force"`
func (this *Properties) IsForce() bool {
return this.Force
}

//---获取datetime时间
Expand Down Expand Up @@ -218,8 +218,8 @@ func getProperties(sf reflect.StructField) *Properties {
p.Ignore = true
case "table":
p.Table = true
case "froce":
p.Froce = true
case "force":
p.Force = true
default:
if strings.Contains(v, "name:") {
p.Name = v[5:]
Expand Down
14 changes: 7 additions & 7 deletions orm/parseSql.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
"strconv"
)

func marshalBlob(value reflect.Value) ([]byte, error){
func marshalBlob(value reflect.Value) ([]byte, error) {
buf := bytes.NewBuffer([]byte{})
enc := gob.NewEncoder(buf)
err := enc.Encode(value.Interface())
return buf.Bytes(), err
return buf.Bytes(), err
}

func unMarshalBlob(data []byte, value reflect.Value) error{
func unMarshalBlob(data []byte, value reflect.Value) error {
buf := bytes.NewBuffer(data)
dec := gob.NewDecoder(buf)
return dec.Decode(value.Addr().Interface())
Expand Down Expand Up @@ -133,7 +133,7 @@ func parseSfSql(p *Properties, classField reflect.StructField, classVal reflect.
return true
} else if p.IsTable() {
return true
} else if !op.forceFlag && !p.IsPrimary() && !p.IsFroce() && classVal.IsZero() {
} else if !op.forceFlag && !p.IsPrimary() && !p.IsForce() && classVal.IsZero() {
return true
}
case SQLTYPE_DELETE:
Expand Down Expand Up @@ -165,7 +165,7 @@ func parseSfSql(p *Properties, classField reflect.StructField, classVal reflect.
return true
} else if p.IsTable() {
return true
} else if !op.forceFlag && !p.IsPrimary() && !p.IsFroce() && classVal.IsZero() {
} else if !op.forceFlag && !p.IsPrimary() && !p.IsForce() && classVal.IsZero() {
return true
}
case SQLTYPE_LOAD:
Expand All @@ -175,7 +175,7 @@ func parseSfSql(p *Properties, classField reflect.StructField, classVal reflect.
} else if p.IsBlob() {
sqlData.Name += fmt.Sprintf("`%s`,", p.Name)
return true
}else if p.IsIgnore() {
} else if p.IsIgnore() {
return true
} else if p.IsTable() {
return true
Expand All @@ -196,7 +196,7 @@ func parseSfSql(p *Properties, classField reflect.StructField, classVal reflect.
return true
} else if p.IsTable() {
return true
} else if !op.forceFlag && !p.IsPrimary() && !p.IsFroce() && classVal.IsZero() {
} else if !op.forceFlag && !p.IsPrimary() && !p.IsForce() && classVal.IsZero() {
return true
}
case SQLTYPE_WHERE:
Expand Down
4 changes: 2 additions & 2 deletions orm/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ func getSliceTypeString(paramType reflect.Type) string {
switch sTypeName {
case "bool", "float64", "float32", "int8", "uint8", "int16", "uint16",
"int32", "uint32", "int64", "uint64", "string", "int", "uint":
return "[*]" + sTypeName
return "[]" + sTypeName
}

return "[*]struct"
return "[]struct"
}

func getArrayTypeString(paramType reflect.Type) string {
Expand Down
2 changes: 1 addition & 1 deletion orm/updateSql.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

func updateSqlStr(sqlData *SqlData) string {
str := sqlData.Value
str := sqlData.NameValue
primary := sqlData.Key
index := strings.LastIndex(str, ",")
if index != -1 {
Expand Down

0 comments on commit 0dc6050

Please sign in to comment.