Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rym-util
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhengqiuyun
rym-util
Commits
d7645d43
Commit
d7645d43
authored
Oct 26, 2022
by
zhengqiuyun86
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
数组差集算法
parent
9482dd4e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
74 additions
and
333 deletions
+74
-333
conf.go
conf/conf.go
+16
-13
GlobalException.go
exception/GlobalException.go
+4
-4
go.mod
go.mod
+37
-1
go.sum
go.sum
+0
-0
AddrUtil.go
util/AddrUtil.go
+1
-42
ArrayUtil.go
util/ArrayUtil.go
+6
-180
ArrayUtil_test.go
util/ArrayUtil_test.go
+2
-2
HttpUtil.go
util/HttpUtil.go
+5
-89
MapUtil.go
util/MapUtil.go
+3
-2
No files found.
conf/conf.go
View file @
d7645d43
package
conf
import
"git.168cad.top/zhengqiuyun/rym-util/util"
import
(
"git.168cad.top/zhengqiuyun/rym-util/exception"
"git.168cad.top/zhengqiuyun/rym-util/util"
)
type
Config
struct
{
ServerName
string
...
...
@@ -20,7 +23,7 @@ type Config struct {
func
BaseConfig
(
conf
Config
)
{
if
util
.
IsEmpty
(
&
conf
.
ServerName
)
{
panic
(
"ServerName error"
)
exception
.
AssertThrowable
(
"ServerName error"
)
}
else
{
ServerName
=
conf
.
ServerName
}
...
...
@@ -48,33 +51,33 @@ func BaseConfig(conf Config) {
MySql
=
conf
.
Mysql
}
//Base conf
//
Base conf
var
ServerName
string
var
Env
string
var
HttpPort
int
//log conf
//
log conf
var
LogLevel
=
"DEBUG"
var
LogColorful
=
true
var
LogResponseLength
int
var
LogShowSql
=
true
var
LogIndexNamePrefix
=
""
//Redis conf
//
Redis conf
type
RedisConf
struct
{
RedisHost
string
RedisPort
int
RedisPwd
string
RedisDb
int
ReadTimeout
int
//取超时间 单位秒 默认值为3秒
RedisHost
string
RedisPort
int
RedisPwd
string
RedisDb
int
ReadTimeout
int
//取超时间 单位秒 默认值为3秒
WriteTimeout
int
// 写入超时时间 单位秒 默认与读超时时间一致
PoolSize
int
//最大连接数 默认cpu数*10
PoolSize
int
//最大连接数 默认cpu数*10
MinIdleConns
int
//最小空闲连接数
}
var
Redis
=
RedisConf
{}
//ES conf
//
ES conf
type
EsConf
struct
{
ServerHost
string
ServerPort
int
...
...
@@ -83,7 +86,7 @@ type EsConf struct {
var
Es
=
EsConf
{}
//Mysql conf
//
Mysql conf
type
MysqlConf
struct
{
Host
string
Port
int
...
...
exception/GlobalException.go
View file @
d7645d43
...
...
@@ -7,7 +7,7 @@ import (
)
func
ThrowsErr
(
err
error
)
{
panic
(
err
)
panic
[
error
]
(
err
)
}
func
ThrowsValid
(
err
error
,
r
interface
{})
{
...
...
@@ -16,10 +16,10 @@ func ThrowsValid(err error, r interface{}) {
case
validator
.
ValidationErrors
:
e
:=
(
err
)
.
(
validator
.
ValidationErrors
)
errMsg
:=
getError
(
e
,
r
)
panic
(
DError
{
Code
:
"REQUEST_PARAMS_ERR"
,
Err
:
errMsg
})
panic
[
DError
]
(
DError
{
Code
:
"REQUEST_PARAMS_ERR"
,
Err
:
errMsg
})
break
default
:
panic
(
err
)
ThrowsErr
(
err
)
break
}
}
...
...
@@ -53,7 +53,7 @@ type DError struct {
}
func
ThrowsErrS
(
code
,
err
string
)
{
panic
(
DError
{
Code
:
code
,
Err
:
err
})
panic
[
DError
]
(
DError
{
Code
:
code
,
Err
:
err
})
}
func
AssertThrowableErr
(
throwable
bool
,
err
error
)
{
...
...
go.mod
View file @
d7645d43
module git.168cad.top/zhengqiuyun/rym-util
go 1.1
6
go 1.1
8
require (
github.com/gin-gonic/gin v1.8.1
...
...
@@ -12,6 +12,42 @@ require (
)
require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.6 // indirect
github.com/go-openapi/spec v0.20.4 // indirect
github.com/go-openapi/swag v0.19.15 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/goccy/go-json v0.9.7 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.3 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/swaggo/swag v1.8.1 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
require (
github.com/gin-contrib/cors v1.4.0
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/onsi/gomega v1.20.0 // indirect
...
...
go.sum
View file @
d7645d43
This diff is collapsed.
Click to expand it.
util/AddrUtil.go
View file @
d7645d43
package
util
import
"time"
func
Strings
(
p
string
)
*
string
{
return
&
p
}
func
Uint64s
(
p
uint64
)
*
uint64
{
return
&
p
}
func
Uint32s
(
p
uint32
)
*
uint32
{
return
&
p
}
func
Uint16s
(
p
uint16
)
*
uint16
{
return
&
p
}
func
Uint8s
(
p
uint8
)
*
uint8
{
return
&
p
}
func
Int64s
(
p
int64
)
*
int64
{
return
&
p
}
func
Int32s
(
p
int32
)
*
int32
{
return
&
p
}
func
Int16s
(
p
int16
)
*
int16
{
return
&
p
}
func
Int8s
(
p
int8
)
*
int8
{
return
&
p
}
func
Ints
(
p
int
)
*
int
{
return
&
p
}
func
Float64s
(
p
float64
)
*
float64
{
return
&
p
}
func
Float32s
(
p
float32
)
*
float32
{
return
&
p
}
func
Bytes
(
p
byte
)
*
byte
{
return
&
p
}
func
Times
(
p
time
.
Time
)
*
time
.
Time
{
func
Addr
[
T
any
](
p
T
)
*
T
{
return
&
p
}
util/ArrayUtil.go
View file @
d7645d43
package
util
import
(
"time"
)
func
ArrayContains
(
array
[]
string
,
e
string
)
bool
{
for
_
,
v
:=
range
array
{
if
v
==
e
{
return
true
}
}
return
false
}
func
ArrayContainsUint64
(
array
[]
uint64
,
e
uint64
)
bool
{
for
_
,
v
:=
range
array
{
if
v
==
e
{
return
true
}
}
return
false
}
func
ArrayContainsUint32
(
array
[]
uint32
,
e
uint32
)
bool
{
for
_
,
v
:=
range
array
{
if
v
==
e
{
return
true
}
}
return
false
}
func
ArrayContainsUint16
(
array
[]
uint16
,
e
uint16
)
bool
{
for
_
,
v
:=
range
array
{
if
v
==
e
{
return
true
}
}
return
false
}
func
ArrayContainsUint8
(
array
[]
uint8
,
e
uint8
)
bool
{
for
_
,
v
:=
range
array
{
if
v
==
e
{
return
true
}
}
return
false
}
func
ArrayContainsInt64
(
array
[]
int64
,
e
int64
)
bool
{
func
ArrayContains
[
T
comparable
](
array
[]
T
,
e
T
)
bool
{
for
_
,
v
:=
range
array
{
if
v
==
e
{
return
true
...
...
@@ -52,147 +8,17 @@ func ArrayContainsInt64(array []int64, e int64) bool {
}
return
false
}
func
ArrayContainsInt32
(
array
[]
int32
,
e
int32
)
bool
{
for
_
,
v
:=
range
array
{
if
v
==
e
{
return
true
}
}
return
false
}
func
ArrayContainsInt16
(
array
[]
int16
,
e
int16
)
bool
{
for
_
,
v
:=
range
array
{
if
v
==
e
{
return
true
}
}
return
false
}
func
ArrayContainsInt8
(
array
[]
int8
,
e
int8
)
bool
{
for
_
,
v
:=
range
array
{
if
v
==
e
{
return
true
}
}
return
false
}
func
ArrayContainsInt
(
array
[]
int
,
e
int
)
bool
{
for
_
,
v
:=
range
array
{
if
v
==
e
{
return
true
}
}
return
false
}
func
ArrayContainsFloat64
(
array
[]
float64
,
e
float64
)
bool
{
for
_
,
v
:=
range
array
{
if
v
==
e
{
return
true
}
}
return
false
}
func
ArrayContainsFloat32
(
array
[]
float32
,
e
float32
)
bool
{
for
_
,
v
:=
range
array
{
if
v
==
e
{
return
true
}
}
return
false
}
func
ArrayContainsByte
(
array
[]
byte
,
e
byte
)
bool
{
for
_
,
v
:=
range
array
{
if
v
==
e
{
return
true
}
}
return
false
}
func
ArrayContainsTime
(
array
[]
time
.
Time
,
e
time
.
Time
)
bool
{
for
_
,
v
:=
range
array
{
if
v
==
e
{
return
true
}
}
return
false
}
func
DifferenceSetInt64
(
a1
,
a2
[]
int64
)
(
d1
,
d2
[]
int64
)
{
var
vMap
=
map
[
int64
]
*
int
{}
for
_
,
v1
:=
range
a1
{
vMap
[
v1
]
=
Ints
(
1
)
}
for
_
,
v2
:=
range
a2
{
if
vMap
[
v2
]
==
nil
{
vMap
[
v2
]
=
Ints
(
2
)
}
else
{
vMap
[
v2
]
=
Ints
(
0
)
}
}
for
k
,
v
:=
range
vMap
{
if
*
v
==
1
{
d1
=
append
(
d1
,
k
)
}
else
if
*
v
==
2
{
d2
=
append
(
d2
,
k
)
}
}
return
d1
,
d2
}
func
DifferenceSetInt32
(
a1
,
a2
[]
int32
)
(
d1
,
d2
[]
int32
)
{
var
vMap
=
map
[
int32
]
*
int
{}
for
_
,
v1
:=
range
a1
{
vMap
[
v1
]
=
Ints
(
1
)
}
for
_
,
v2
:=
range
a2
{
if
vMap
[
v2
]
==
nil
{
vMap
[
v2
]
=
Ints
(
2
)
}
else
{
vMap
[
v2
]
=
Ints
(
0
)
}
}
for
k
,
v
:=
range
vMap
{
if
*
v
==
1
{
d1
=
append
(
d1
,
k
)
}
else
if
*
v
==
2
{
d2
=
append
(
d2
,
k
)
}
}
return
d1
,
d2
}
func
DifferenceSetInt
(
a1
,
a2
[]
int
)
(
d1
,
d2
[]
int
)
{
var
vMap
=
map
[
int
]
*
int
{}
for
_
,
v1
:=
range
a1
{
vMap
[
v1
]
=
Ints
(
1
)
}
for
_
,
v2
:=
range
a2
{
if
vMap
[
v2
]
==
nil
{
vMap
[
v2
]
=
Ints
(
2
)
}
else
{
vMap
[
v2
]
=
Ints
(
0
)
}
}
for
k
,
v
:=
range
vMap
{
if
*
v
==
1
{
d1
=
append
(
d1
,
k
)
}
else
if
*
v
==
2
{
d2
=
append
(
d2
,
k
)
}
}
return
d1
,
d2
}
func
DifferenceSet
(
a1
,
a2
[]
string
)
(
d1
,
d2
[]
string
)
{
var
vMap
=
map
[
string
]
*
int
{}
func
DifferenceSet
[
K
comparable
](
a1
,
a2
[]
K
)
(
d1
,
d2
[]
K
)
{
var
vMap
=
map
[
K
]
*
int
{}
for
_
,
v1
:=
range
a1
{
vMap
[
v1
]
=
Ints
(
1
)
vMap
[
v1
]
=
Addr
[
int
]
(
1
)
}
for
_
,
v2
:=
range
a2
{
if
vMap
[
v2
]
==
nil
{
vMap
[
v2
]
=
Ints
(
2
)
vMap
[
v2
]
=
Addr
[
int
]
(
2
)
}
else
{
vMap
[
v2
]
=
Ints
(
0
)
vMap
[
v2
]
=
Addr
[
int
]
(
0
)
}
}
for
k
,
v
:=
range
vMap
{
...
...
util/ArrayUtil_test.go
View file @
d7645d43
...
...
@@ -12,13 +12,13 @@ func TestArrayContainsInterface(t *testing.T) {
areaIds
=
append
(
areaIds
,
PareDateTime
(
"2022-02-09 22:09:12"
))
areaIds
=
append
(
areaIds
,
PareDateTime
(
"2022-03-09 22:09:12"
))
areaIds
=
append
(
areaIds
,
PareDateTime
(
"2022-12-09 22:09:12"
))
fmt
.
Println
(
ArrayContains
Time
(
areaIds
,
PareDateTime
(
"2022-02-10 22:09:12"
)))
fmt
.
Println
(
ArrayContains
[
time
.
Time
]
(
areaIds
,
PareDateTime
(
"2022-02-10 22:09:12"
)))
}
func
TestDifference
(
t
*
testing
.
T
)
{
a1
:=
[]
int64
{
1
,
5
,
2
,
3
}
a2
:=
[]
int64
{
2
,
1
,
34
,
3
,
3
,
4
}
d1
,
d2
:=
DifferenceSet
Int64
(
a1
,
a2
)
d1
,
d2
:=
DifferenceSet
[
int64
]
(
a1
,
a2
)
fmt
.
Println
(
"a1与a2的差集分别是:"
,
d1
,
d2
)
}
...
...
util/HttpUtil.go
View file @
d7645d43
...
...
@@ -2,102 +2,18 @@ package util
import
(
"bytes"
"fmt"
"git.168cad.top/zhengqiuyun/rym-util/exception"
"github.com/gin-gonic/gin"
"io/ioutil"
"net/http"
"strconv"
"strings"
)
func
ParamInt64
(
c
*
gin
.
Context
,
key
string
)
int64
{
return
int64
(
ParamInt
(
c
,
key
))
}
func
ParamInt32
(
c
*
gin
.
Context
,
key
string
)
int32
{
return
int32
(
ParamInt
(
c
,
key
))
}
func
ParamInt16
(
c
*
gin
.
Context
,
key
string
)
int16
{
return
int16
(
ParamInt
(
c
,
key
))
}
func
ParamInt8
(
c
*
gin
.
Context
,
key
string
)
int8
{
return
int8
(
ParamInt
(
c
,
key
))
}
func
ParamUint64
(
c
*
gin
.
Context
,
key
string
)
uint64
{
return
uint64
(
ParamInt
(
c
,
key
))
}
func
ParamUint32
(
c
*
gin
.
Context
,
key
string
)
uint32
{
return
uint32
(
ParamInt
(
c
,
key
))
}
func
ParamUint16
(
c
*
gin
.
Context
,
key
string
)
uint16
{
return
uint16
(
ParamInt
(
c
,
key
))
}
func
ParamUint8
(
c
*
gin
.
Context
,
key
string
)
uint8
{
return
uint8
(
ParamInt
(
c
,
key
))
}
func
ParamInt
(
c
*
gin
.
Context
,
key
string
)
int
{
v
:=
c
.
Query
(
key
)
if
v
==
""
{
return
0
}
i
,
err
:=
strconv
.
Atoi
(
v
)
if
err
!=
nil
{
exception
.
ThrowsErrS
(
"PARAMS_ERR"
,
"请传入正确的数字"
)
func
ParamNumber
[
T
any
](
c
*
gin
.
Context
,
key
string
)
*
T
{
if
val
,
ok
:=
c
.
Get
(
key
);
ok
&&
val
!=
nil
{
i
,
_
:=
val
.
(
T
)
return
&
i
}
return
i
}
func
ParamFloat64
(
c
*
gin
.
Context
,
key
string
)
float64
{
v
:=
c
.
Query
(
key
)
if
v
==
""
{
return
0
}
i
,
err
:=
strconv
.
ParseFloat
(
v
,
2
)
if
err
!=
nil
{
exception
.
ThrowsErrS
(
"PARAMS_ERR"
,
"请传入正确的数字"
)
}
return
i
}
func
ParamFloat32
(
c
*
gin
.
Context
,
key
string
)
float32
{
return
float32
(
ParamFloat64
(
c
,
key
))
}
func
ParamFloat64B
(
c
*
gin
.
Context
,
key
string
,
bitSize
int
)
float64
{
v
:=
c
.
Query
(
key
)
if
v
==
""
{
return
0
}
i
,
err
:=
strconv
.
ParseFloat
(
v
,
bitSize
)
if
err
!=
nil
{
exception
.
ThrowsErrS
(
"PARAMS_ERR"
,
"请传入正确的数字"
)
}
return
i
}
func
ParamFloat32B
(
c
*
gin
.
Context
,
key
string
,
bitSize
int
)
float32
{
return
float32
(
ParamFloat64B
(
c
,
key
,
bitSize
))
}
func
Param
(
c
*
gin
.
Context
,
key
string
)
string
{
v
,
ok
:=
c
.
GetQuery
(
key
)
if
!
ok
||
v
==
""
{
exception
.
ThrowsErrS
(
"PARAMS_ERR"
,
fmt
.
Sprintf
(
"%s不能为空"
,
key
))
}
return
v
}
func
ParamB
(
c
*
gin
.
Context
,
key
string
)
string
{
v
:=
c
.
Query
(
key
)
return
v
return
nil
}
const
(
...
...
util/MapUtil.go
View file @
d7645d43
...
...
@@ -90,11 +90,12 @@ func StrToMapStr(obj string) map[string]string {
return
m
}
func
ToObject
(
txt
string
,
p
interface
{})
{
func
ToObject
(
txt
string
,
p
interface
{})
error
{
err
:=
json
.
Unmarshal
([]
byte
(
txt
),
p
)
if
err
!=
nil
{
panic
(
err
)
return
err
}
return
nil
}
func
SortKeys
(
orgMap
map
[
string
]
interface
{})
[]
string
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment