diff --git a/README.md b/README.md index c209cda..a065f21 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# kratos-utils \ No newline at end of file +# kratos-utils diff --git a/crypto/crypto.go b/crypto/crypto.go new file mode 100644 index 0000000..454c786 --- /dev/null +++ b/crypto/crypto.go @@ -0,0 +1,17 @@ +package crypto + +import ( + "golang.org/x/crypto/bcrypt" +) + +// HashPassword 加密密码 +func HashPassword(password string) (string, error) { + bytes, err := bcrypt.GenerateFromPassword([]byte(password), 10) + return string(bytes), err +} + +// CheckPasswordHash 校验密码 +func CheckPasswordHash(password, hash string) bool { + err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)) + return err == nil +} diff --git a/crypto/crypto_test.go b/crypto/crypto_test.go new file mode 100644 index 0000000..b53215f --- /dev/null +++ b/crypto/crypto_test.go @@ -0,0 +1,32 @@ +package crypto + +import ( + "fmt" + "github.com/stretchr/testify/assert" + "strings" + "testing" +) + +func TestHashPassword(t *testing.T) { + text := "admin" + hash, _ := HashPassword(text) + fmt.Println(hash) +} + +func TestCheckPasswordHash(t *testing.T) { + text := "123456" + hash3 := "$2a$10$ygWrRwHCzg2GUpz0UK40kuWAGva121VkScpcdMNsDCih2U/bL2qYy" + bMatched := CheckPasswordHash(text, hash3) + assert.True(t, bMatched) + + bMatched = CheckPasswordHash(text, hash3) + assert.True(t, bMatched) +} + +func TestJwtToken(t *testing.T) { + const bearerWord string = "Bearer" + token := "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjowfQ.XgcKAAjHbA6o4sxxbEaMi05ingWvKdCNnyW9wowbJvs" + auths := strings.SplitN(token, " ", 2) + assert.Equal(t, len(auths), 2) + assert.Equal(t, strings.EqualFold(auths[0], bearerWord), true, "JWT token is missing") +} diff --git a/entgo/mixin/autoincrement_id.go b/entgo/mixin/autoincrement_id.go new file mode 100644 index 0000000..1faecf8 --- /dev/null +++ b/entgo/mixin/autoincrement_id.go @@ -0,0 +1,39 @@ +package mixin + +import ( + "entgo.io/contrib/entproto" + "entgo.io/ent" + "entgo.io/ent/dialect" + "entgo.io/ent/schema/field" + "entgo.io/ent/schema/index" + "entgo.io/ent/schema/mixin" +) + +var _ ent.Mixin = (*AutoIncrementId)(nil) + +type AutoIncrementId struct{ mixin.Schema } + +func (AutoIncrementId) Fields() []ent.Field { + return []ent.Field{ + field.Uint32("id"). + Comment("id"). + StructTag(`json:"id,omitempty"`). + SchemaType(map[string]string{ + dialect.MySQL: "int", + dialect.Postgres: "serial", + }). + Annotations( + entproto.Field(1), + ). + Positive(). + Immutable(). + Unique(), + } +} + +// Indexes of the AutoIncrementId. +func (AutoIncrementId) Indexes() []ent.Index { + return []ent.Index{ + index.Fields("id"), + } +} diff --git a/entgo/mixin/operator.go b/entgo/mixin/operator.go new file mode 100644 index 0000000..88c7b58 --- /dev/null +++ b/entgo/mixin/operator.go @@ -0,0 +1,85 @@ +package mixin + +import ( + "entgo.io/ent" + "entgo.io/ent/schema/field" + "entgo.io/ent/schema/mixin" +) + +var _ ent.Mixin = (*CreateBy)(nil) + +type CreateBy struct{ mixin.Schema } + +func (CreateBy) Fields() []ent.Field { + return []ent.Field{ + field.Int("create_by"). + Comment("创建者"). + Optional(). + Nillable(), + } +} + +var _ ent.Mixin = (*UpdateBy)(nil) + +type UpdateBy struct{ mixin.Schema } + +func (UpdateBy) Fields() []ent.Field { + return []ent.Field{ + field.Int("update_by"). + Comment("更新者"). + Optional(). + Nillable(), + } +} + +var _ ent.Mixin = (*DeleteBy)(nil) + +type DeleteBy struct{ mixin.Schema } + +func (DeleteBy) Fields() []ent.Field { + return []ent.Field{ + field.Int("delete_by"). + Comment("删除者"). + Optional(). + Nillable(), + } +} + +var _ ent.Mixin = (*CreatedBy)(nil) + +type CreatedBy struct{ mixin.Schema } + +func (CreatedBy) Fields() []ent.Field { + return []ent.Field{ + field.Int("created_by"). + Comment("创建者"). + Optional(). + Nillable(), + } +} + +var _ ent.Mixin = (*UpdatedBy)(nil) + +type UpdatedBy struct{ mixin.Schema } + +func (UpdatedBy) Fields() []ent.Field { + return []ent.Field{ + field.Int("updated_by"). + Comment("更新者"). + Optional(). + Nillable(), + } +} + +var _ ent.Mixin = (*DeletedBy)(nil) + +type DeletedBy struct{ mixin.Schema } + +func (DeletedBy) Fields() []ent.Field { + return []ent.Field{ + field.Int("deleted_by"). + Comment("删除者"). + Optional(). + Nillable(), + } +} diff --git a/entgo/mixin/time.go b/entgo/mixin/time.go new file mode 100644 index 0000000..337f29f --- /dev/null +++ b/entgo/mixin/time.go @@ -0,0 +1,122 @@ +package mixin + +import ( + "time" + + "entgo.io/ent" + "entgo.io/ent/schema/field" + "entgo.io/ent/schema/mixin" +) + +var _ ent.Mixin = (*CreateTime)(nil) + +type CreateTime struct{ mixin.Schema } + +func (CreateTime) Fields() []ent.Field { + return []ent.Field{ + // 创建时间,毫秒 + field.Int64("create_time"). + Comment("创建时间"). + Immutable(). + Optional(). + Nillable(). + DefaultFunc(time.Now().UnixMilli), + } +} + +var _ ent.Mixin = (*UpdateTime)(nil) + +type UpdateTime struct{ mixin.Schema } + +func (UpdateTime) Fields() []ent.Field { + return []ent.Field{ + // 更新时间,毫秒 + // 需要注意的是,如果不是程序自动更新,那么这个字段不会被更新,除非在数据库里面下触发器更新。 + field.Int64("update_time"). + Comment("更新时间"). + Optional(). + Nillable(). + UpdateDefault(time.Now().UnixMilli), + } +} + +var _ ent.Mixin = (*DeleteTime)(nil) + +type DeleteTime struct{ mixin.Schema } + +func (DeleteTime) Fields() []ent.Field { + return []ent.Field{ + // 删除时间,毫秒 + field.Int64("delete_time"). + Comment("删除时间"). + Optional(). + Nillable(), + } +} + +var _ ent.Mixin = (*Time)(nil) + +type Time struct{ mixin.Schema } + +func (Time) Fields() []ent.Field { + var fields []ent.Field + fields = append(fields, CreateTime{}.Fields()...) + fields = append(fields, UpdateTime{}.Fields()...) + fields = append(fields, DeleteTime{}.Fields()...) + return fields +} + +var _ ent.Mixin = (*CreatedAt)(nil) + +type CreatedAt struct{ mixin.Schema } + +func (CreatedAt) Fields() []ent.Field { + return []ent.Field{ + // 创建时间 + field.Time("created_at"). + Comment("创建时间"). + Immutable(). + Optional(). + Nillable(), + } +} + +var _ ent.Mixin = (*UpdatedAt)(nil) + +type UpdatedAt struct{ mixin.Schema } + +func (UpdatedAt) Fields() []ent.Field { + return []ent.Field{ + // 更新时间 + field.Time("updated_at"). + Comment("更新时间"). + Optional(). + Nillable(), + } +} + +var _ ent.Mixin = (*DeletedAt)(nil) + +type DeletedAt struct{ mixin.Schema } + +func (DeletedAt) Fields() []ent.Field { + return []ent.Field{ + // 删除时间 + field.Time("deleted_at"). + Comment("删除时间"). + Optional(). + Nillable(), + } +} + +var _ ent.Mixin = (*TimeAt)(nil) + +type TimeAt struct{ mixin.Schema } + +func (TimeAt) Fields() []ent.Field { + var fields []ent.Field + fields = append(fields, CreatedAt{}.Fields()...) + fields = append(fields, UpdatedAt{}.Fields()...) + fields = append(fields, DeletedAt{}.Fields()...) + return fields +} diff --git a/entgo/mixin/uuid_id.go b/entgo/mixin/uuid_id.go new file mode 100644 index 0000000..70470d7 --- /dev/null +++ b/entgo/mixin/uuid_id.go @@ -0,0 +1,31 @@ +package mixin + +import ( + "entgo.io/ent" + "entgo.io/ent/schema/field" + "entgo.io/ent/schema/index" + "entgo.io/ent/schema/mixin" + "github.com/google/uuid" +) + +var _ ent.Mixin = (*UuidId)(nil) + +type UuidId struct{ mixin.Schema } + +func (UuidId) Fields() []ent.Field { + return []ent.Field{ + field.UUID("id", uuid.UUID{}). + Comment("id"). + Default(uuid.New). + Unique(). + Immutable(). + StructTag(`json:"id,omitempty"`), + } +} + +// Indexes of the UuidId. +func (UuidId) Indexes() []ent.Index { + return []ent.Index{ + index.Fields("id"), + } +} diff --git a/entgo/util.go b/entgo/util.go new file mode 100644 index 0000000..0bf149e --- /dev/null +++ b/entgo/util.go @@ -0,0 +1,61 @@ +package entgo + +import ( + "encoding/json" + "strings" + + "entgo.io/ent/dialect/sql" + + "kratos-utils/stringcase" +) + +type WhereConditions []func(s *sql.Selector) +type OrderConditions []func(*sql.Selector) + +// QueryCommandToSelector 查询命令转换为选择器 +func QueryCommandToSelector(queryCmd, orderByCmd map[string]string) (WhereConditions, OrderConditions) { + var whereCond WhereConditions + var orderCond OrderConditions + + if queryCmd != nil { + queryStr, ok := queryCmd["query"] + if ok { + var queryMap map[string]string + err := json.Unmarshal([]byte(queryStr), &queryMap) + if err == nil { + for k, v := range queryMap { + key := stringcase.ToSnakeCase(k) + value := v + whereCond = append(whereCond, func(s *sql.Selector) { + s.Where(sql.EQ(s.C(key), value)) + }) + } + } + } + } + + if orderByCmd != nil { + orderByStr, ok := orderByCmd["orderBy"] + if ok { + var orderByMap map[string]string + err := json.Unmarshal([]byte(orderByStr), &orderByMap) + if err == nil { + for k, v := range orderByMap { + key := stringcase.ToSnakeCase(k) + switch strings.ToLower(v) { + case "desc", "descending", "descend": + orderCond = append(orderCond, func(s *sql.Selector) { + s.OrderBy(sql.Desc(s.C(key))) + }) + case "asc", "ascending", "ascend": + orderCond = append(orderCond, func(s *sql.Selector) { + s.OrderBy(sql.Asc(s.C(key))) + }) + } + } + } + } + } + + return whereCond, orderCond +} diff --git a/geoip/GeoLite2-City.mmdb b/geoip/GeoLite2-City.mmdb new file mode 100644 index 0000000..703e7e7 Binary files /dev/null and b/geoip/GeoLite2-City.mmdb differ diff --git a/geoip/geoip.go b/geoip/geoip.go new file mode 100644 index 0000000..b0d4dd6 --- /dev/null +++ b/geoip/geoip.go @@ -0,0 +1,69 @@ +package geoip + +import ( + _ "embed" + "errors" + "net" + + "github.com/go-kratos/kratos/v2/log" + "github.com/oschwald/geoip2-golang" +) + +//go:embed GeoLite2-City.mmdb +var geoipMmdbByte []byte + +type Result struct { + Country string // 国家 + Province string // 省 + City string // 城市 +} + +// GeoIp 地理位置解析结构体 +type GeoIp struct { + db *geoip2.Reader + outputLanguage string +} + +// NewGeoIp . +func NewGeoIp() (geoip *GeoIp, err error) { + db, err := geoip2.FromBytes(geoipMmdbByte) + if err != nil { + return nil, err + } + return &GeoIp{db: db, outputLanguage: "zh-CN"}, nil +} + +func (g *GeoIp) Close() (err error) { + return g.db.Close() +} + +// SetLanguage 设置输出的语言,默认为:zh-CN +func (g *GeoIp) SetLanguage(code string) { + g.outputLanguage = code +} + +func (g *GeoIp) query(rawIP string) (city *geoip2.City, err error) { + ip := net.ParseIP(rawIP) + if ip == nil { + return nil, errors.New("invalid ip") + } + + return g.db.City(ip) +} + +// GetAreaFromIP 通过IP获取地区 +func (g *GeoIp) GetAreaFromIP(rawIP string) (ret Result, err error) { + record, err := g.query(rawIP) + if err != nil { + log.Fatal(err) + return ret, err + } + + ret.Country = record.Country.Names[g.outputLanguage] + if len(record.Subdivisions) > 0 { + ret.Province = record.Subdivisions[0].Names[g.outputLanguage] + } + ret.City = record.City.Names[g.outputLanguage] + + return +} diff --git a/geoip/geoip_test.go b/geoip/geoip_test.go new file mode 100644 index 0000000..f45b851 --- /dev/null +++ b/geoip/geoip_test.go @@ -0,0 +1,17 @@ +package geoip + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +func TestGeoIp(t *testing.T) { + g, err := NewGeoIp() + assert.Nil(t, err) + + ret, err := g.GetAreaFromIP("47.108.149.89") + assert.Nil(t, err) + assert.Equal(t, ret.Country, "中国") + assert.Equal(t, ret.Province, "四川省") + assert.Equal(t, ret.City, "成都") +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..220a4a4 --- /dev/null +++ b/go.mod @@ -0,0 +1,38 @@ +module kratos-utils + +go 1.20 + +require ( + entgo.io/contrib v0.4.5 + entgo.io/ent v0.12.3 + github.com/go-kratos/kratos/v2 v2.6.2 + github.com/google/uuid v1.3.0 + github.com/oschwald/geoip2-golang v1.8.0 + github.com/stretchr/testify v1.8.2 + golang.org/x/crypto v0.9.0 +) + +require ( + ariga.io/atlas v0.10.2-0.20230427182402-87a07dfb83bf // indirect + github.com/agext/levenshtein v1.2.1 // indirect + github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/go-openapi/inflect v0.19.0 // indirect + github.com/golang/protobuf v1.5.2 // indirect + github.com/google/go-cmp v0.5.9 // indirect + github.com/hashicorp/hcl/v2 v2.13.0 // indirect + github.com/jhump/protoreflect v1.10.1 // indirect + github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/oschwald/maxminddb-golang v1.10.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/zclconf/go-cty v1.8.0 // indirect + go.uber.org/atomic v1.10.0 // indirect + go.uber.org/multierr v1.9.0 // indirect + golang.org/x/mod v0.10.0 // indirect + golang.org/x/sys v0.8.0 // indirect + golang.org/x/text v0.9.0 // indirect + golang.org/x/tools v0.8.1-0.20230428195545-5283a0178901 // indirect + google.golang.org/protobuf v1.28.1 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..5d744a8 --- /dev/null +++ b/go.sum @@ -0,0 +1,188 @@ +ariga.io/atlas v0.10.2-0.20230427182402-87a07dfb83bf h1:Tq2DRB39ZHScIwWACjPKLv5oEErv7zv6PBb5RTz5CKA= +ariga.io/atlas v0.10.2-0.20230427182402-87a07dfb83bf/go.mod h1:+TR129FJZ5Lvzms6dvCeGWh1yR6hMvmXBhug4hrNIGk= +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +entgo.io/contrib v0.4.5 h1:BFaOHwFLE8WZjVJadP0XHCIaxgcC1BAtUvAyw7M/GHk= +entgo.io/contrib v0.4.5/go.mod h1:wpZyq2DJgthugFvDBlaqMXj9mV4/9ebyGEn7xlTVQqE= +entgo.io/ent v0.12.3 h1:N5lO2EOrHpCH5HYfiMOCHYbo+oh5M8GjT0/cx5x6xkk= +entgo.io/ent v0.12.3/go.mod h1:AigGGx+tbrBBYHAzGOg8ND661E5cxx1Uiu5o/otJ6Yg= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= +github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8= +github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= +github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw= +github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/go-kratos/kratos/v2 v2.6.2 h1:9ar3d6tbci4GhqUsar18MB20hgFDOV70buDkWGUrX3M= +github.com/go-kratos/kratos/v2 v2.6.2/go.mod h1:xTeAeI9iYBP8MauISfxmRGSmKdDTLRQ3rbarKYmt6P4= +github.com/go-openapi/inflect v0.19.0 h1:9jCH9scKIbHeV9m12SmPilScz6krDxKRasNNSNPXu/4= +github.com/go-openapi/inflect v0.19.0/go.mod h1:lHpZVlpIQqLyKwJ4N+YSc9hchQy/i12fJykb83CRBH4= +github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gordonklaus/ineffassign v0.0.0-20200309095847-7953dde2c7bf/go.mod h1:cuNKsD1zp2v6XfE/orVX2QE1LC+i254ceGcVeDT3pTU= +github.com/hashicorp/hcl/v2 v2.13.0 h1:0Apadu1w6M11dyGFxWnmhhcMjkbAiKCv7G1r/2QgCNc= +github.com/hashicorp/hcl/v2 v2.13.0/go.mod h1:e4z5nxYlWNPdDSNYX+ph14EvWYMFm3eP0zIUqPc2jr0= +github.com/jhump/protoreflect v1.10.1 h1:iH+UZfsbRE6vpyZH7asAjTPWJf7RJbpZ9j/N3lDlKs0= +github.com/jhump/protoreflect v1.10.1/go.mod h1:7GcYQDdMU/O/BBrl/cX6PNHpXh6cenjd8pneu5yW7Tg= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3vkb4ax0b5D2DHbNAUsen0Gx5wZoq3lV4= +github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y= +github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM= +github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/nishanths/predeclared v0.0.0-20200524104333-86fad755b4d3/go.mod h1:nt3d53pc1VYcphSCIaYAJtnPYnr3Zyn8fMq2wvPGPso= +github.com/oschwald/geoip2-golang v1.8.0 h1:KfjYB8ojCEn/QLqsDU0AzrJ3R5Qa9vFlx3z6SLNcKTs= +github.com/oschwald/geoip2-golang v1.8.0/go.mod h1:R7bRvYjOeaoenAp9sKRS8GX5bJWcZ0laWO5+DauEktw= +github.com/oschwald/maxminddb-golang v1.10.0 h1:Xp1u0ZhqkSuopaKmk1WwHtjF0H9Hd9181uj2MQ5Vndg= +github.com/oschwald/maxminddb-golang v1.10.0/go.mod h1:Y2ELenReaLAZ0b400URyGwvYxHV1dLIxBuyOsyYjHK0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= +github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/zclconf/go-cty v1.8.0 h1:s4AvqaeQzJIu3ndv4gVIhplVD0krU+bgrcLSVUnaWuA= +github.com/zclconf/go-cty v1.8.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= +go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ= +go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= +go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= +go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= +golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= +golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200522201501-cb1345f3a375/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200717024301-6ddee64345a6/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.8.1-0.20230428195545-5283a0178901 h1:0wxTF6pSjIIhNt7mo9GvjDfzyCOiWhmICgtO/Ah948s= +golang.org/x/tools v0.8.1-0.20230428195545-5283a0178901/go.mod h1:JxBZ99ISMI5ViVkT1tr6tdNmXeTrcpVSD3vZ1RsRdN4= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6 h1:a2S6M0+660BgMNl++4JPlcAO/CjkqYItDEZwkoDQK7c= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.52.3 h1:pf7sOysg4LdgBqduXveGKrcEwbStiK2rtfghdzlUYDQ= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.25.1-0.20200805231151-a709e31e5d12/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= +google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= diff --git a/pagination/pagination.go b/pagination/pagination.go new file mode 100644 index 0000000..2740730 --- /dev/null +++ b/pagination/pagination.go @@ -0,0 +1,5 @@ +package pagination + +func GetPageOffset(pageNum, pageSize int32) int { + return int((pageNum - 1) * pageSize) +} diff --git a/stringcase/stringcase.go b/stringcase/stringcase.go new file mode 100644 index 0000000..f9ac0c3 --- /dev/null +++ b/stringcase/stringcase.go @@ -0,0 +1,119 @@ +package stringcase + +import ( + "strings" + "unicode" +) + +// ToSnakeCase 把字符转换为 蛇形命名法(snake_case) +func ToSnakeCase(input string) string { + if input == "" { + return input + } + if len(input) == 1 { + return strings.ToLower(input) + } + + input = strings.Replace(input, " ", "", -1) + + source := []rune(input) + dist := strings.Builder{} + dist.Grow(len(input) + len(input)/3) // avoid reallocation memory, 33% ~ 50% is recommended + skipNext := false + for i := 0; i < len(source); i++ { + cur := source[i] + switch cur { + case '-', '_': + dist.WriteRune('_') + skipNext = true + continue + } + if unicode.IsLower(cur) || unicode.IsDigit(cur) { + dist.WriteRune(cur) + continue + } + + if i == 0 { + dist.WriteRune(unicode.ToLower(cur)) + continue + } + + last := source[i-1] + if (!unicode.IsLetter(last)) || unicode.IsLower(last) { + if skipNext { + skipNext = false + } else { + dist.WriteRune('_') + } + dist.WriteRune(unicode.ToLower(cur)) + continue + } + // last is upper case + if i < len(source)-1 { + next := source[i+1] + if unicode.IsLower(next) { + if skipNext { + skipNext = false + } else { + dist.WriteRune('_') + } + dist.WriteRune(unicode.ToLower(cur)) + continue + } + } + dist.WriteRune(unicode.ToLower(cur)) + } + + return dist.String() +} + +// ToPascalCase 把字符转换为 帕斯卡命名/大驼峰命名法(CamelCase) +func ToPascalCase(input string) string { + return toCamelCase(input, true) +} + +// ToLowCamelCase 把字符转换为 小驼峰命名法(lowerCamelCase) +func ToLowCamelCase(input string) string { + return toCamelCase(input, false) +} + +func toCamelCase(s string, initCase bool) string { + s = strings.TrimSpace(s) + if s == "" { + return s + } + + var uppercaseAcronym = map[string]string{} + if a, ok := uppercaseAcronym[s]; ok { + s = a + } + + n := strings.Builder{} + n.Grow(len(s)) + capNext := initCase + for i, v := range []byte(s) { + vIsCap := v >= 'A' && v <= 'Z' + vIsLow := v >= 'a' && v <= 'z' + if capNext { + if vIsLow { + v += 'A' + v -= 'a' + } + } else if i == 0 { + if vIsCap { + v += 'a' + v -= 'A' + } + } + if vIsCap || vIsLow { + n.WriteByte(v) + capNext = false + } else if vIsNum := v >= '0' && v <= '9'; vIsNum { + n.WriteByte(v) + capNext = true + } else { + capNext = v == '_' || v == ' ' || v == '-' || v == '.' + } + } + return n.String() +} diff --git a/stringcase/stringcase_test.go b/stringcase/stringcase_test.go new file mode 100644 index 0000000..dede096 --- /dev/null +++ b/stringcase/stringcase_test.go @@ -0,0 +1,24 @@ +package stringcase + +import ( + "fmt" + "testing" +) + +func TestToLowCamelCase(t *testing.T) { + fmt.Println(ToLowCamelCase("snake_case")) + fmt.Println(ToLowCamelCase("CamelCase")) + fmt.Println(ToLowCamelCase("lowerCamelCase")) +} + +func TestToPascalCase(t *testing.T) { + fmt.Println(ToPascalCase("snake_case")) + fmt.Println(ToPascalCase("CamelCase")) + fmt.Println(ToPascalCase("lowerCamelCase")) +} + +func TestToSnakeCase(t *testing.T) { + fmt.Println(ToSnakeCase("snake_case")) + fmt.Println(ToSnakeCase("CamelCase")) + fmt.Println(ToSnakeCase("lowerCamelCase")) +} diff --git a/time/util.go b/time/util.go new file mode 100644 index 0000000..72a402f --- /dev/null +++ b/time/util.go @@ -0,0 +1,139 @@ +package util + +import "time" + +const ( + TimeLayout = "2006-01-02 15:04:05" + DateLayout = "2006-01-02" +) + +// UnixMilliToStringPtr 毫秒时间戳转字符串 +func UnixMilliToStringPtr(tm *int64) *string { + if tm == nil { + return nil + } + str := time.UnixMilli(*tm).Format(TimeLayout) + return &str +} + +// StringTimeToTime 字符串转时间 +func StringTimeToTime(tm *string) *time.Time { + if tm == nil { + return nil + } + loc, _ := time.LoadLocation("Asia/Shanghai") + theTime, err := time.ParseInLocation(TimeLayout, *tm, loc) + if err != nil { + return nil + } + return &theTime +} + +// StringDateToTime 字符串转时间 +func StringDateToTime(tm *string) *time.Time { + if tm == nil { + return nil + } + loc, _ := time.LoadLocation("Asia/Shanghai") + theTime, err := time.ParseInLocation(DateLayout, *tm, loc) + if err != nil { + return nil + } + return &theTime +} + +// StringToUnixMilliInt64Ptr 字符串转毫秒时间戳 +func StringToUnixMilliInt64Ptr(tm *string) *int64 { + theTime := StringTimeToTime(tm) + if theTime == nil { + return nil + } + unixTime := theTime.UnixMilli() + return &unixTime +} + +// GetCurrentDayTime 获取今天的时间 +func GetCurrentDayTime() (time.Time, time.Time) { + now := time.Now() + startDate := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()) + endDate := time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 0, now.Location()) + return startDate, endDate +} + +// GetCurrentMonthTime 获取本月的时间 +func GetCurrentMonthTime() (time.Time, time.Time) { + now := time.Now() + firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location()) + lastDay := firstDay.AddDate(0, 1, -1) + endDate := time.Date(lastDay.Year(), lastDay.Month(), lastDay.Day(), 23, 59, 59, 0, now.Location()) + return firstDay, endDate +} + +// GetCurrentYearTime 获取今年的时间 +func GetCurrentYearTime() (time.Time, time.Time) { + now := time.Now() + firstDay := time.Date(now.Year(), time.January, 1, 0, 0, 0, 0, now.Location()) + lastDay := firstDay.AddDate(1, 0, -1) + endDate := time.Date(lastDay.Year(), lastDay.Month(), lastDay.Day(), 23, 59, 59, 0, now.Location()) + return firstDay, endDate +} + +// GetCurrentDayDateString 获取今天的日期字符串 +func GetCurrentDayDateString() (string, string) { + firstDay, lastDay := GetCurrentDayTime() + + startDate := firstDay.Format(DateLayout) + endDate := lastDay.Format(DateLayout) + + return startDate, endDate +} + +// GetCurrentMonthDateString 获取本月的日期字符串 +func GetCurrentMonthDateString() (string, string) { + firstDay, lastDay := GetCurrentMonthTime() + + startDate := firstDay.Format(DateLayout) + endDate := lastDay.Format(DateLayout) + + return startDate, endDate +} + +// GetCurrentYearDateString 获取今年的日期字符串 +func GetCurrentYearDateString() (string, string) { + firstDay, lastDay := GetCurrentYearTime() + + startDate := firstDay.Format(DateLayout) + endDate := lastDay.Format(DateLayout) + + return startDate, endDate +} + +// GetCurrentDayTimeString 获取今天的时间字符串 +func GetCurrentDayTimeString() (string, string) { + firstDay, lastDay := GetCurrentDayTime() + + startDate := firstDay.Format(TimeLayout) + endDate := lastDay.Format(TimeLayout) + + return startDate, endDate +} + +// GetCurrentMonthTimeString 获取本月的时间字符串 +func GetCurrentMonthTimeString() (string, string) { + firstDay, lastDay := GetCurrentMonthTime() + + startDate := firstDay.Format(TimeLayout) + endDate := lastDay.Format(TimeLayout) + + return startDate, endDate +} + +// GetCurrentYearTimeString 获取今年的时间字符串 +func GetCurrentYearTimeString() (string, string) { + firstDay, lastDay := GetCurrentYearTime() + + startDate := firstDay.Format(TimeLayout) + endDate := lastDay.Format(TimeLayout) + + return startDate, endDate +} diff --git a/time/util_test.go b/time/util_test.go new file mode 100644 index 0000000..f1fd29f --- /dev/null +++ b/time/util_test.go @@ -0,0 +1,43 @@ +package util + +import ( + "fmt" + "testing" + "time" + + "kratos-utils/trans" +) + +func TestUnixMilliToStringPtr(t *testing.T) { + now := time.Now().UnixMilli() + str := UnixMilliToStringPtr(&now) + fmt.Println(now) + fmt.Println(*str) + + fmt.Println(*UnixMilliToStringPtr(trans.Int64(1677135885288))) + fmt.Println(*UnixMilliToStringPtr(trans.Int64(1677647430853))) + fmt.Println(*UnixMilliToStringPtr(trans.Int64(1677647946234))) + + fmt.Println(*StringToUnixMilliInt64Ptr(trans.String("2023-03-01 00:00:00"))) + + fmt.Println(*StringTimeToTime(trans.String("2023-03-01 00:00:00"))) + fmt.Println(*StringDateToTime(trans.String("2023-03-01"))) +} + +func TestGetCurrentDateString(t *testing.T) { + fmt.Println(GetCurrentDayDateString()) + fmt.Println(GetCurrentMonthDateString()) + fmt.Println(GetCurrentYearDateString()) +} + +func TestGetCurrentTime(t *testing.T) { + fmt.Println(GetCurrentDayTime()) + fmt.Println(GetCurrentMonthTime()) + fmt.Println(GetCurrentYearTime()) +} + +func TestGetCurrentTimeString(t *testing.T) { + fmt.Println(GetCurrentDayTimeString()) + fmt.Println(GetCurrentMonthTimeString()) + fmt.Println(GetCurrentYearTimeString()) +} diff --git a/trans/trans.go b/trans/trans.go new file mode 100644 index 0000000..10e7ef5 --- /dev/null +++ b/trans/trans.go @@ -0,0 +1,504 @@ +package trans + +import "time" + +func String(a string) *string { + return &a +} + +func StringValue(a *string) string { + if a == nil { + return "" + } + return *a +} + +func Int(a int) *int { + return &a +} + +func IntValue(a *int) int { + if a == nil { + return 0 + } + return *a +} + +func Int8(a int8) *int8 { + return &a +} + +func Int8Value(a *int8) int8 { + if a == nil { + return 0 + } + return *a +} + +func Int16(a int16) *int16 { + return &a +} + +func Int16Value(a *int16) int16 { + if a == nil { + return 0 + } + return *a +} + +func Int32(a int32) *int32 { + return &a +} + +func Int32Value(a *int32) int32 { + if a == nil { + return 0 + } + return *a +} + +func Int64(a int64) *int64 { + return &a +} + +func Int64Value(a *int64) int64 { + if a == nil { + return 0 + } + return *a +} + +func Bool(a bool) *bool { + return &a +} + +func BoolValue(a *bool) bool { + if a == nil { + return false + } + return *a +} + +func Uint(a uint) *uint { + return &a +} + +func UintValue(a *uint) uint { + if a == nil { + return 0 + } + return *a +} + +func Uint8(a uint8) *uint8 { + return &a +} + +func Uint8Value(a *uint8) uint8 { + if a == nil { + return 0 + } + return *a +} + +func Uint16(a uint16) *uint16 { + return &a +} + +func Uint16Value(a *uint16) uint16 { + if a == nil { + return 0 + } + return *a +} + +func Uint32(a uint32) *uint32 { + return &a +} + +func Uint32Value(a *uint32) uint32 { + if a == nil { + return 0 + } + return *a +} + +func Uint64(a uint64) *uint64 { + return &a +} + +func Uint64Value(a *uint64) uint64 { + if a == nil { + return 0 + } + return *a +} + +func Float32(a float32) *float32 { + return &a +} + +func Float32Value(a *float32) float32 { + if a == nil { + return 0 + } + return *a +} + +func Float64(a float64) *float64 { + return &a +} + +func Float64Value(a *float64) float64 { + if a == nil { + return 0 + } + return *a +} + +func Time(a time.Time) *time.Time { + return &a +} + +func TimeValue(a *time.Time) time.Time { + if a == nil { + return time.Now() + } + return *a +} + +func IntSlice(a []int) []*int { + if a == nil { + return nil + } + res := make([]*int, len(a)) + for i := 0; i < len(a); i++ { + res[i] = &a[i] + } + return res +} + +func IntValueSlice(a []*int) []int { + if a == nil { + return nil + } + res := make([]int, len(a)) + for i := 0; i < len(a); i++ { + if a[i] != nil { + res[i] = *a[i] + } + } + return res +} + +func Int8Slice(a []int8) []*int8 { + if a == nil { + return nil + } + res := make([]*int8, len(a)) + for i := 0; i < len(a); i++ { + res[i] = &a[i] + } + return res +} + +func Int8ValueSlice(a []*int8) []int8 { + if a == nil { + return nil + } + res := make([]int8, len(a)) + for i := 0; i < len(a); i++ { + if a[i] != nil { + res[i] = *a[i] + } + } + return res +} + +func Int16Slice(a []int16) []*int16 { + if a == nil { + return nil + } + res := make([]*int16, len(a)) + for i := 0; i < len(a); i++ { + res[i] = &a[i] + } + return res +} + +func Int16ValueSlice(a []*int16) []int16 { + if a == nil { + return nil + } + res := make([]int16, len(a)) + for i := 0; i < len(a); i++ { + if a[i] != nil { + res[i] = *a[i] + } + } + return res +} + +func Int32Slice(a []int32) []*int32 { + if a == nil { + return nil + } + res := make([]*int32, len(a)) + for i := 0; i < len(a); i++ { + res[i] = &a[i] + } + return res +} + +func Int32ValueSlice(a []*int32) []int32 { + if a == nil { + return nil + } + res := make([]int32, len(a)) + for i := 0; i < len(a); i++ { + if a[i] != nil { + res[i] = *a[i] + } + } + return res +} + +func Int64Slice(a []int64) []*int64 { + if a == nil { + return nil + } + res := make([]*int64, len(a)) + for i := 0; i < len(a); i++ { + res[i] = &a[i] + } + return res +} + +func Int64ValueSlice(a []*int64) []int64 { + if a == nil { + return nil + } + res := make([]int64, len(a)) + for i := 0; i < len(a); i++ { + if a[i] != nil { + res[i] = *a[i] + } + } + return res +} + +func UintSlice(a []uint) []*uint { + if a == nil { + return nil + } + res := make([]*uint, len(a)) + for i := 0; i < len(a); i++ { + res[i] = &a[i] + } + return res +} + +func UintValueSlice(a []*uint) []uint { + if a == nil { + return nil + } + res := make([]uint, len(a)) + for i := 0; i < len(a); i++ { + if a[i] != nil { + res[i] = *a[i] + } + } + return res +} + +func Uint8Slice(a []uint8) []*uint8 { + if a == nil { + return nil + } + res := make([]*uint8, len(a)) + for i := 0; i < len(a); i++ { + res[i] = &a[i] + } + return res +} + +func Uint8ValueSlice(a []*uint8) []uint8 { + if a == nil { + return nil + } + res := make([]uint8, len(a)) + for i := 0; i < len(a); i++ { + if a[i] != nil { + res[i] = *a[i] + } + } + return res +} + +func Uint16Slice(a []uint16) []*uint16 { + if a == nil { + return nil + } + res := make([]*uint16, len(a)) + for i := 0; i < len(a); i++ { + res[i] = &a[i] + } + return res +} + +func Uint16ValueSlice(a []*uint16) []uint16 { + if a == nil { + return nil + } + res := make([]uint16, len(a)) + for i := 0; i < len(a); i++ { + if a[i] != nil { + res[i] = *a[i] + } + } + return res +} + +func Uint32Slice(a []uint32) []*uint32 { + if a == nil { + return nil + } + res := make([]*uint32, len(a)) + for i := 0; i < len(a); i++ { + res[i] = &a[i] + } + return res +} + +func Uint32ValueSlice(a []*uint32) []uint32 { + if a == nil { + return nil + } + res := make([]uint32, len(a)) + for i := 0; i < len(a); i++ { + if a[i] != nil { + res[i] = *a[i] + } + } + return res +} + +func Uint64Slice(a []uint64) []*uint64 { + if a == nil { + return nil + } + res := make([]*uint64, len(a)) + for i := 0; i < len(a); i++ { + res[i] = &a[i] + } + return res +} + +func Uint64ValueSlice(a []*uint64) []uint64 { + if a == nil { + return nil + } + res := make([]uint64, len(a)) + for i := 0; i < len(a); i++ { + if a[i] != nil { + res[i] = *a[i] + } + } + return res +} + +func Float32Slice(a []float32) []*float32 { + if a == nil { + return nil + } + res := make([]*float32, len(a)) + for i := 0; i < len(a); i++ { + res[i] = &a[i] + } + return res +} + +func Float32ValueSlice(a []*float32) []float32 { + if a == nil { + return nil + } + res := make([]float32, len(a)) + for i := 0; i < len(a); i++ { + if a[i] != nil { + res[i] = *a[i] + } + } + return res +} + +func Float64Slice(a []float64) []*float64 { + if a == nil { + return nil + } + res := make([]*float64, len(a)) + for i := 0; i < len(a); i++ { + res[i] = &a[i] + } + return res +} + +func Float64ValueSlice(a []*float64) []float64 { + if a == nil { + return nil + } + res := make([]float64, len(a)) + for i := 0; i < len(a); i++ { + if a[i] != nil { + res[i] = *a[i] + } + } + return res +} + +func StringSlice(a []string) []*string { + if a == nil { + return nil + } + res := make([]*string, len(a)) + for i := 0; i < len(a); i++ { + res[i] = &a[i] + } + return res +} + +func StringSliceValue(a []*string) []string { + if a == nil { + return nil + } + res := make([]string, len(a)) + for i := 0; i < len(a); i++ { + if a[i] != nil { + res[i] = *a[i] + } + } + return res +} + +func BoolSlice(a []bool) []*bool { + if a == nil { + return nil + } + res := make([]*bool, len(a)) + for i := 0; i < len(a); i++ { + res[i] = &a[i] + } + return res +} + +func BoolSliceValue(a []*bool) []bool { + if a == nil { + return nil + } + res := make([]bool, len(a)) + for i := 0; i < len(a); i++ { + if a[i] != nil { + res[i] = *a[i] + } + } + return res +} diff --git a/trans/trans_test.go b/trans/trans_test.go new file mode 100644 index 0000000..c075321 --- /dev/null +++ b/trans/trans_test.go @@ -0,0 +1,169 @@ +package trans + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" +) + +func Test_Trans(t *testing.T) { + str := String("tea") + strVal := StringValue(str) + assert.Equal(t, "tea", strVal) + assert.Equal(t, "", StringValue(nil)) + + strSlice := StringSlice([]string{"tea"}) + strSliceVal := StringSliceValue(strSlice) + assert.Equal(t, []string{"tea"}, strSliceVal) + assert.Nil(t, StringSlice(nil)) + assert.Nil(t, StringSliceValue(nil)) + + b := Bool(true) + bVal := BoolValue(b) + assert.Equal(t, true, bVal) + assert.Equal(t, false, BoolValue(nil)) + + bSlice := BoolSlice([]bool{false}) + bSliceVal := BoolSliceValue(bSlice) + assert.Equal(t, []bool{false}, bSliceVal) + assert.Nil(t, BoolSlice(nil)) + assert.Nil(t, BoolSliceValue(nil)) + + f64 := Float64(2.00) + f64Val := Float64Value(f64) + assert.Equal(t, 2.00, f64Val) + assert.Equal(t, float64(0), Float64Value(nil)) + + f32 := Float32(2.00) + f32Val := Float32Value(f32) + assert.Equal(t, float32(2.00), f32Val) + assert.Equal(t, float32(0), Float32Value(nil)) + + f64Slice := Float64Slice([]float64{2.00}) + f64SliceVal := Float64ValueSlice(f64Slice) + assert.Equal(t, []float64{2.00}, f64SliceVal) + assert.Nil(t, Float64Slice(nil)) + assert.Nil(t, Float64ValueSlice(nil)) + + f32Slice := Float32Slice([]float32{2.00}) + f32SliceVal := Float32ValueSlice(f32Slice) + assert.Equal(t, []float32{2.00}, f32SliceVal) + assert.Nil(t, Float32Slice(nil)) + assert.Nil(t, Float32ValueSlice(nil)) + + i := Int(1) + iVal := IntValue(i) + assert.Equal(t, 1, iVal) + assert.Equal(t, 0, IntValue(nil)) + + i8 := Int8(int8(1)) + i8Val := Int8Value(i8) + assert.Equal(t, int8(1), i8Val) + assert.Equal(t, int8(0), Int8Value(nil)) + + i16 := Int16(int16(1)) + i16Val := Int16Value(i16) + assert.Equal(t, int16(1), i16Val) + assert.Equal(t, int16(0), Int16Value(nil)) + + i32 := Int32(int32(1)) + i32Val := Int32Value(i32) + assert.Equal(t, int32(1), i32Val) + assert.Equal(t, int32(0), Int32Value(nil)) + + i64 := Int64(int64(1)) + i64Val := Int64Value(i64) + assert.Equal(t, int64(1), i64Val) + assert.Equal(t, int64(0), Int64Value(nil)) + + iSlice := IntSlice([]int{1}) + iSliceVal := IntValueSlice(iSlice) + assert.Equal(t, []int{1}, iSliceVal) + assert.Nil(t, IntSlice(nil)) + assert.Nil(t, IntValueSlice(nil)) + + i8Slice := Int8Slice([]int8{1}) + i8ValSlice := Int8ValueSlice(i8Slice) + assert.Equal(t, []int8{1}, i8ValSlice) + assert.Nil(t, Int8Slice(nil)) + assert.Nil(t, Int8ValueSlice(nil)) + + i16Slice := Int16Slice([]int16{1}) + i16ValSlice := Int16ValueSlice(i16Slice) + assert.Equal(t, []int16{1}, i16ValSlice) + assert.Nil(t, Int16Slice(nil)) + assert.Nil(t, Int16ValueSlice(nil)) + + i32Slice := Int32Slice([]int32{1}) + i32ValSlice := Int32ValueSlice(i32Slice) + assert.Equal(t, []int32{1}, i32ValSlice) + assert.Nil(t, Int32Slice(nil)) + assert.Nil(t, Int32ValueSlice(nil)) + + i64Slice := Int64Slice([]int64{1}) + i64ValSlice := Int64ValueSlice(i64Slice) + assert.Equal(t, []int64{1}, i64ValSlice) + assert.Nil(t, Int64Slice(nil)) + assert.Nil(t, Int64ValueSlice(nil)) + + ui := Uint(1) + uiVal := UintValue(ui) + assert.Equal(t, uint(1), uiVal) + assert.Equal(t, uint(0), UintValue(nil)) + + ui8 := Uint8(uint8(1)) + ui8Val := Uint8Value(ui8) + assert.Equal(t, uint8(1), ui8Val) + assert.Equal(t, uint8(0), Uint8Value(nil)) + + ui16 := Uint16(uint16(1)) + ui16Val := Uint16Value(ui16) + assert.Equal(t, uint16(1), ui16Val) + assert.Equal(t, uint16(0), Uint16Value(nil)) + + ui32 := Uint32(uint32(1)) + ui32Val := Uint32Value(ui32) + assert.Equal(t, uint32(1), ui32Val) + assert.Equal(t, uint32(0), Uint32Value(nil)) + + ui64 := Uint64(uint64(1)) + ui64Val := Uint64Value(ui64) + assert.Equal(t, uint64(1), ui64Val) + assert.Equal(t, uint64(0), Uint64Value(nil)) + + uiSlice := UintSlice([]uint{1}) + uiValSlice := UintValueSlice(uiSlice) + assert.Equal(t, []uint{1}, uiValSlice) + assert.Nil(t, UintSlice(nil)) + assert.Nil(t, UintValueSlice(nil)) + + ui8Slice := Uint8Slice([]uint8{1}) + ui8ValSlice := Uint8ValueSlice(ui8Slice) + assert.Equal(t, []uint8{1}, ui8ValSlice) + assert.Nil(t, Uint8Slice(nil)) + assert.Nil(t, Uint8ValueSlice(nil)) + + ui16Slice := Uint16Slice([]uint16{1}) + ui16ValSlice := Uint16ValueSlice(ui16Slice) + assert.Equal(t, []uint16{1}, ui16ValSlice) + assert.Nil(t, Uint16Slice(nil)) + assert.Nil(t, Uint16ValueSlice(nil)) + + ui32Slice := Uint32Slice([]uint32{1}) + ui32ValSlice := Uint32ValueSlice(ui32Slice) + assert.Equal(t, []uint32{1}, ui32ValSlice) + assert.Nil(t, Uint32Slice(nil)) + assert.Nil(t, Uint32ValueSlice(nil)) + + ui64Slice := Uint64Slice([]uint64{1}) + ui64ValSlice := Uint64ValueSlice(ui64Slice) + assert.Equal(t, []uint64{1}, ui64ValSlice) + assert.Nil(t, Uint64Slice(nil)) + assert.Nil(t, Uint64ValueSlice(nil)) + + tm := Time(time.Now()) + tmVal := TimeValue(tm) + assert.Equal(t, time.Now(), tmVal) + assert.Equal(t, time.Now(), TimeValue(nil)) +}