mirror of
https://gitee.com/johng/gf
synced 2026-06-24 00:40:38 +08:00
Compare commits
26 Commits
v2.1.0-rc2
...
v2.1.0-rc4
| Author | SHA1 | Date | |
|---|---|---|---|
| 0639becccc | |||
| 88844649eb | |||
| 31c5d5a5f5 | |||
| 6abbc57c96 | |||
| 39af6e51c4 | |||
| ef04c8a09e | |||
| 4505d61604 | |||
| 04d32e7a91 | |||
| 26066965c3 | |||
| 7f199527f8 | |||
| ea79b3cbb8 | |||
| 0ca81bd11a | |||
| 4d13ffdc26 | |||
| 331a29024e | |||
| 6aa5c2b2ef | |||
| 8c969b2a84 | |||
| 0d7e28ee75 | |||
| ab5062663e | |||
| 896b9fa105 | |||
| 6a01275499 | |||
| 61bf0a0092 | |||
| d7c5a08d20 | |||
| 350ee9f0a2 | |||
| 7753fc6fe1 | |||
| 24f5b2782d | |||
| 853d7aaf8f |
34
.github/workflows/gf.yml
vendored
34
.github/workflows/gf.yml
vendored
@ -28,7 +28,7 @@ jobs:
|
||||
services:
|
||||
# Redis backend server.
|
||||
redis:
|
||||
image : redis
|
||||
image : loads/redis:latest
|
||||
options: >-
|
||||
--health-cmd "redis-cli ping"
|
||||
--health-interval 10s
|
||||
@ -40,7 +40,7 @@ jobs:
|
||||
|
||||
# MySQL backend server.
|
||||
mysql:
|
||||
image: mysql:5.7
|
||||
image: loads/mysql:5.7
|
||||
env:
|
||||
MYSQL_DATABASE : test
|
||||
MYSQL_ROOT_PASSWORD: 12345678
|
||||
@ -50,7 +50,7 @@ jobs:
|
||||
|
||||
# PostgreSQL backend server.
|
||||
postgres:
|
||||
image: postgres:13
|
||||
image: loads/postgres:13
|
||||
env:
|
||||
POSTGRES_PASSWORD: 12345678
|
||||
POSTGRES_USER: root
|
||||
@ -67,7 +67,7 @@ jobs:
|
||||
|
||||
# MSSQL backend server.
|
||||
mssql:
|
||||
image: mcmoe/mssqldocker:latest
|
||||
image: loads/mssqldocker:latest
|
||||
env:
|
||||
ACCEPT_EULA: Y
|
||||
SA_PASSWORD: LoremIpsum86
|
||||
@ -85,21 +85,35 @@ jobs:
|
||||
|
||||
# ClickHouse backend server.
|
||||
clickhouse-server:
|
||||
image: yandex/clickhouse-server
|
||||
image: loads/clickhouse-server:latest
|
||||
ports:
|
||||
- 9000:9000
|
||||
- 8123:8123
|
||||
- 9001:9001
|
||||
|
||||
polaris:
|
||||
image: huyuanxin/polaris-server-with-config:latest
|
||||
image: houseme/polaris-server-with-config:latest
|
||||
ports:
|
||||
- 8090:8090
|
||||
- 8091:8091
|
||||
|
||||
#oracle 11g server
|
||||
oracle-server:
|
||||
image: loads/oracle-xe-11g-r2:latest
|
||||
env:
|
||||
ORACLE_ALLOW_REMOTE: true
|
||||
ORACLE_SID: XE
|
||||
ORACLE_DB_USER_NAME: system
|
||||
ORACLE_DB_PASSWORD: oracle
|
||||
ports:
|
||||
- 1521:1521
|
||||
|
||||
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
go: ["1.15", "1.16", "1.17"]
|
||||
goarch: ["386", "amd64"]
|
||||
go: [ "1.15", "1.16", "1.17" ]
|
||||
goarch: [ "386", "amd64" ]
|
||||
|
||||
|
||||
steps:
|
||||
@ -130,7 +144,9 @@ jobs:
|
||||
dirpath=$(dirname $file)
|
||||
|
||||
if [ "oracle" = $(basename $dirpath) ]; then
|
||||
continue 1
|
||||
if ! go version|grep -q "1.17"; then
|
||||
continue 1
|
||||
fi
|
||||
fi
|
||||
|
||||
cd $dirpath
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
## This file contains all available configuration options
|
||||
## with their default values.
|
||||
#
|
||||
|
||||
# See https://github.com/golangci/golangci-lint#config-file
|
||||
run:
|
||||
issues-exit-code: 1 #Default
|
||||
|
||||
@ -6,7 +6,6 @@ require (
|
||||
github.com/gogf/gf/contrib/drivers/mssql/v2 v2.0.6
|
||||
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.0.6
|
||||
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.0.6
|
||||
github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.0.6
|
||||
github.com/gogf/gf/v2 v2.0.6
|
||||
github.com/olekukonko/tablewriter v0.0.5
|
||||
)
|
||||
|
||||
@ -66,8 +66,6 @@ github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9
|
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mattn/go-sqlite3 v1.14.10 h1:MLn+5bFRlWMGoSRmJour3CL1w/qL96mvipqpwQW/Sfk=
|
||||
github.com/mattn/go-sqlite3 v1.14.10/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
|
||||
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
|
||||
|
||||
@ -22,7 +22,7 @@ import (
|
||||
_ "github.com/gogf/gf/contrib/drivers/mssql/v2"
|
||||
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
|
||||
_ "github.com/gogf/gf/contrib/drivers/pgsql/v2"
|
||||
_ "github.com/gogf/gf/contrib/drivers/sqlite/v2"
|
||||
//_ "github.com/gogf/gf/contrib/drivers/sqlite/v2"
|
||||
//_ "github.com/gogf/gf/contrib/drivers/oracle/v2"
|
||||
)
|
||||
|
||||
|
||||
@ -15,6 +15,16 @@ var (
|
||||
goimportsPath = gproc.SearchBinaryPath("goimports") // gofmtPath is the binary path of command `goimports`.
|
||||
)
|
||||
|
||||
func init() {
|
||||
// Wraps the command binary path with char '"' if there's space char in the path.
|
||||
if gstr.Contains(gofmtPath, " ") {
|
||||
gofmtPath = fmt.Sprintf(`"%s"`, gofmtPath)
|
||||
}
|
||||
if gstr.Contains(goimportsPath, " ") {
|
||||
goimportsPath = fmt.Sprintf(`"%s"`, goimportsPath)
|
||||
}
|
||||
}
|
||||
|
||||
// GoFmt formats the source file using command `gofmt -w -s PATH`.
|
||||
func GoFmt(path string) {
|
||||
if gofmtPath == "" {
|
||||
|
||||
@ -14,6 +14,7 @@ import (
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/internal/deepcopy"
|
||||
"github.com/gogf/gf/v2/internal/empty"
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"github.com/gogf/gf/v2/internal/rwmutex"
|
||||
@ -820,3 +821,14 @@ func (a *Array) Walk(f func(value interface{}) interface{}) *Array {
|
||||
func (a *Array) IsEmpty() bool {
|
||||
return a.Len() == 0
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (a *Array) DeepCopy() interface{} {
|
||||
a.mu.RLock()
|
||||
defer a.mu.RUnlock()
|
||||
newSlice := make([]interface{}, len(a.array))
|
||||
for i, v := range a.array {
|
||||
newSlice[i] = deepcopy.Copy(v)
|
||||
}
|
||||
return NewArrayFrom(newSlice, a.mu.IsSafe())
|
||||
}
|
||||
|
||||
@ -799,3 +799,12 @@ func (a *IntArray) Walk(f func(value int) int) *IntArray {
|
||||
func (a *IntArray) IsEmpty() bool {
|
||||
return a.Len() == 0
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (a *IntArray) DeepCopy() interface{} {
|
||||
a.mu.RLock()
|
||||
defer a.mu.RUnlock()
|
||||
newSlice := make([]int, len(a.array))
|
||||
copy(newSlice, a.array)
|
||||
return NewIntArrayFrom(newSlice, a.mu.IsSafe())
|
||||
}
|
||||
|
||||
@ -812,3 +812,12 @@ func (a *StrArray) Walk(f func(value string) string) *StrArray {
|
||||
func (a *StrArray) IsEmpty() bool {
|
||||
return a.Len() == 0
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (a *StrArray) DeepCopy() interface{} {
|
||||
a.mu.RLock()
|
||||
defer a.mu.RUnlock()
|
||||
newSlice := make([]string, len(a.array))
|
||||
copy(newSlice, a.array)
|
||||
return NewStrArrayFrom(newSlice, a.mu.IsSafe())
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ import (
|
||||
"math"
|
||||
"sort"
|
||||
|
||||
"github.com/gogf/gf/v2/internal/deepcopy"
|
||||
"github.com/gogf/gf/v2/internal/empty"
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"github.com/gogf/gf/v2/internal/rwmutex"
|
||||
@ -796,3 +797,14 @@ func (a *SortedArray) getComparator() func(a, b interface{}) int {
|
||||
}
|
||||
return a.comparator
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (a *SortedArray) DeepCopy() interface{} {
|
||||
a.mu.RLock()
|
||||
defer a.mu.RUnlock()
|
||||
newSlice := make([]interface{}, len(a.array))
|
||||
for i, v := range a.array {
|
||||
newSlice[i] = deepcopy.Copy(v)
|
||||
}
|
||||
return NewSortedArrayFrom(newSlice, a.comparator, a.mu.IsSafe())
|
||||
}
|
||||
|
||||
@ -744,3 +744,12 @@ func (a *SortedIntArray) getComparator() func(a, b int) int {
|
||||
}
|
||||
return a.comparator
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (a *SortedIntArray) DeepCopy() interface{} {
|
||||
a.mu.RLock()
|
||||
defer a.mu.RUnlock()
|
||||
newSlice := make([]int, len(a.array))
|
||||
copy(newSlice, a.array)
|
||||
return NewSortedIntArrayFrom(newSlice, a.mu.IsSafe())
|
||||
}
|
||||
|
||||
@ -757,3 +757,12 @@ func (a *SortedStrArray) getComparator() func(a, b string) int {
|
||||
}
|
||||
return a.comparator
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (a *SortedStrArray) DeepCopy() interface{} {
|
||||
a.mu.RLock()
|
||||
defer a.mu.RUnlock()
|
||||
newSlice := make([]string, len(a.array))
|
||||
copy(newSlice, a.array)
|
||||
return NewSortedStrArrayFrom(newSlice, a.mu.IsSafe())
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ import (
|
||||
"bytes"
|
||||
"container/list"
|
||||
|
||||
"github.com/gogf/gf/v2/internal/deepcopy"
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"github.com/gogf/gf/v2/internal/rwmutex"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
@ -546,3 +547,23 @@ func (l *List) UnmarshalValue(value interface{}) (err error) {
|
||||
l.PushBacks(array)
|
||||
return err
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (l *List) DeepCopy() interface{} {
|
||||
l.mu.RLock()
|
||||
defer l.mu.RUnlock()
|
||||
|
||||
if l.list == nil {
|
||||
return nil
|
||||
}
|
||||
var (
|
||||
length = l.list.Len()
|
||||
values = make([]interface{}, length)
|
||||
)
|
||||
if length > 0 {
|
||||
for i, e := 0, l.list.Front(); i < length; i, e = i+1, e.Next() {
|
||||
values[i] = deepcopy.Copy(e.Value)
|
||||
}
|
||||
}
|
||||
return NewFrom(values, l.mu.IsSafe())
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ package gmap
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
"github.com/gogf/gf/v2/internal/deepcopy"
|
||||
"github.com/gogf/gf/v2/internal/empty"
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"github.com/gogf/gf/v2/internal/rwmutex"
|
||||
@ -72,7 +73,7 @@ func (m *AnyAnyMap) Map() map[interface{}]interface{} {
|
||||
return data
|
||||
}
|
||||
|
||||
// MapCopy returns a copy of the underlying data of the hash map.
|
||||
// MapCopy returns a shallow copy of the underlying data of the hash map.
|
||||
func (m *AnyAnyMap) MapCopy() map[interface{}]interface{} {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
@ -497,3 +498,14 @@ func (m *AnyAnyMap) UnmarshalValue(value interface{}) (err error) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (m *AnyAnyMap) DeepCopy() interface{} {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
data := make(map[interface{}]interface{}, len(m.data))
|
||||
for k, v := range m.data {
|
||||
data[k] = deepcopy.Copy(v)
|
||||
}
|
||||
return NewFrom(data, m.mu.IsSafe())
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ package gmap
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
"github.com/gogf/gf/v2/internal/deepcopy"
|
||||
"github.com/gogf/gf/v2/internal/empty"
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"github.com/gogf/gf/v2/internal/rwmutex"
|
||||
@ -499,3 +500,14 @@ func (m *IntAnyMap) UnmarshalValue(value interface{}) (err error) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (m *IntAnyMap) DeepCopy() interface{} {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
data := make(map[int]interface{}, len(m.data))
|
||||
for k, v := range m.data {
|
||||
data[k] = deepcopy.Copy(v)
|
||||
}
|
||||
return NewIntAnyMapFrom(data, m.mu.IsSafe())
|
||||
}
|
||||
|
||||
@ -470,3 +470,14 @@ func (m *IntIntMap) UnmarshalValue(value interface{}) (err error) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (m *IntIntMap) DeepCopy() interface{} {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
data := make(map[int]int, len(m.data))
|
||||
for k, v := range m.data {
|
||||
data[k] = v
|
||||
}
|
||||
return NewIntIntMapFrom(data, m.mu.IsSafe())
|
||||
}
|
||||
|
||||
@ -470,3 +470,14 @@ func (m *IntStrMap) UnmarshalValue(value interface{}) (err error) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (m *IntStrMap) DeepCopy() interface{} {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
data := make(map[int]string, len(m.data))
|
||||
for k, v := range m.data {
|
||||
data[k] = v
|
||||
}
|
||||
return NewIntStrMapFrom(data, m.mu.IsSafe())
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ package gmap
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
"github.com/gogf/gf/v2/internal/deepcopy"
|
||||
"github.com/gogf/gf/v2/internal/empty"
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"github.com/gogf/gf/v2/internal/rwmutex"
|
||||
@ -485,3 +486,14 @@ func (m *StrAnyMap) UnmarshalValue(value interface{}) (err error) {
|
||||
m.data = gconv.Map(value)
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (m *StrAnyMap) DeepCopy() interface{} {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
data := make(map[string]interface{}, len(m.data))
|
||||
for k, v := range m.data {
|
||||
data[k] = deepcopy.Copy(v)
|
||||
}
|
||||
return NewStrAnyMapFrom(data, m.mu.IsSafe())
|
||||
}
|
||||
|
||||
@ -474,3 +474,14 @@ func (m *StrIntMap) UnmarshalValue(value interface{}) (err error) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (m *StrIntMap) DeepCopy() interface{} {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
data := make(map[string]int, len(m.data))
|
||||
for k, v := range m.data {
|
||||
data[k] = v
|
||||
}
|
||||
return NewStrIntMapFrom(data, m.mu.IsSafe())
|
||||
}
|
||||
|
||||
@ -463,3 +463,14 @@ func (m *StrStrMap) UnmarshalValue(value interface{}) (err error) {
|
||||
m.data = gconv.MapStrStr(value)
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (m *StrStrMap) DeepCopy() interface{} {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
data := make(map[string]string, len(m.data))
|
||||
for k, v := range m.data {
|
||||
data[k] = v
|
||||
}
|
||||
return NewStrStrMapFrom(data, m.mu.IsSafe())
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ import (
|
||||
|
||||
"github.com/gogf/gf/v2/container/glist"
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
"github.com/gogf/gf/v2/internal/deepcopy"
|
||||
"github.com/gogf/gf/v2/internal/empty"
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"github.com/gogf/gf/v2/internal/rwmutex"
|
||||
@ -590,3 +591,19 @@ func (m *ListMap) UnmarshalValue(value interface{}) (err error) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (m *ListMap) DeepCopy() interface{} {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
data := make(map[interface{}]interface{}, len(m.data))
|
||||
if m.list != nil {
|
||||
var node *gListMapNode
|
||||
m.list.IteratorAsc(func(e *glist.Element) bool {
|
||||
node = e.Value.(*gListMapNode)
|
||||
data[node.key] = deepcopy.Copy(node.value)
|
||||
return true
|
||||
})
|
||||
}
|
||||
return NewListMapFrom(data, m.mu.IsSafe())
|
||||
}
|
||||
|
||||
@ -510,3 +510,14 @@ func (set *Set) UnmarshalValue(value interface{}) (err error) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (set *Set) DeepCopy() interface{} {
|
||||
set.mu.RLock()
|
||||
defer set.mu.RUnlock()
|
||||
data := make(map[interface{}]struct{}, len(set.data))
|
||||
for k, v := range set.data {
|
||||
data[k] = v
|
||||
}
|
||||
return NewFrom(data, set.mu.IsSafe())
|
||||
}
|
||||
|
||||
@ -469,3 +469,18 @@ func (set *IntSet) UnmarshalValue(value interface{}) (err error) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (set *IntSet) DeepCopy() interface{} {
|
||||
set.mu.RLock()
|
||||
defer set.mu.RUnlock()
|
||||
var (
|
||||
slice = make([]int, len(set.data))
|
||||
index = 0
|
||||
)
|
||||
for k := range set.data {
|
||||
slice[index] = k
|
||||
index++
|
||||
}
|
||||
return NewIntSetFrom(slice, set.mu.IsSafe())
|
||||
}
|
||||
|
||||
@ -499,3 +499,18 @@ func (set *StrSet) UnmarshalValue(value interface{}) (err error) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (set *StrSet) DeepCopy() interface{} {
|
||||
set.mu.RLock()
|
||||
defer set.mu.RUnlock()
|
||||
var (
|
||||
slice = make([]string, len(set.data))
|
||||
index = 0
|
||||
)
|
||||
for k := range set.data {
|
||||
slice[index] = k
|
||||
index++
|
||||
}
|
||||
return NewStrSetFrom(slice, set.mu.IsSafe())
|
||||
}
|
||||
|
||||
@ -96,3 +96,8 @@ func (v *Bool) UnmarshalValue(value interface{}) error {
|
||||
v.Set(gconv.Bool(value))
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (v *Bool) DeepCopy() interface{} {
|
||||
return NewBool(v.Val())
|
||||
}
|
||||
|
||||
@ -75,3 +75,8 @@ func (v *Byte) UnmarshalValue(value interface{}) error {
|
||||
v.Set(gconv.Byte(value))
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (v *Byte) DeepCopy() interface{} {
|
||||
return NewByte(v.Val())
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ func NewBytes(value ...[]byte) *Bytes {
|
||||
return t
|
||||
}
|
||||
|
||||
// Clone clones and returns a new concurrent-safe object for []byte type.
|
||||
// Clone clones and returns a new shallow copy object for []byte type.
|
||||
func (v *Bytes) Clone() *Bytes {
|
||||
return NewBytes(v.Val())
|
||||
}
|
||||
@ -83,3 +83,11 @@ func (v *Bytes) UnmarshalValue(value interface{}) error {
|
||||
v.Set(gconv.Bytes(value))
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (v *Bytes) DeepCopy() interface{} {
|
||||
oldBytes := v.Val()
|
||||
newBytes := make([]byte, len(oldBytes))
|
||||
copy(newBytes, oldBytes)
|
||||
return NewBytes(newBytes)
|
||||
}
|
||||
|
||||
@ -87,3 +87,8 @@ func (v *Float32) UnmarshalValue(value interface{}) error {
|
||||
v.Set(gconv.Float32(value))
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (v *Float32) DeepCopy() interface{} {
|
||||
return NewFloat32(v.Val())
|
||||
}
|
||||
|
||||
@ -87,3 +87,8 @@ func (v *Float64) UnmarshalValue(value interface{}) error {
|
||||
v.Set(gconv.Float64(value))
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (v *Float64) DeepCopy() interface{} {
|
||||
return NewFloat64(v.Val())
|
||||
}
|
||||
|
||||
@ -75,3 +75,8 @@ func (v *Int) UnmarshalValue(value interface{}) error {
|
||||
v.Set(gconv.Int(value))
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (v *Int) DeepCopy() interface{} {
|
||||
return NewInt(v.Val())
|
||||
}
|
||||
|
||||
@ -75,3 +75,8 @@ func (v *Int32) UnmarshalValue(value interface{}) error {
|
||||
v.Set(gconv.Int32(value))
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (v *Int32) DeepCopy() interface{} {
|
||||
return NewInt32(v.Val())
|
||||
}
|
||||
|
||||
@ -75,3 +75,8 @@ func (v *Int64) UnmarshalValue(value interface{}) error {
|
||||
v.Set(gconv.Int64(value))
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (v *Int64) DeepCopy() interface{} {
|
||||
return NewInt64(v.Val())
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ package gtype
|
||||
import (
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/gogf/gf/v2/internal/deepcopy"
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
@ -71,3 +72,8 @@ func (v *Interface) UnmarshalValue(value interface{}) error {
|
||||
v.Set(value)
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (v *Interface) DeepCopy() interface{} {
|
||||
return NewInterface(deepcopy.Copy(v.Val()))
|
||||
}
|
||||
|
||||
@ -75,3 +75,8 @@ func (v *Uint) UnmarshalValue(value interface{}) error {
|
||||
v.Set(gconv.Uint(value))
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (v *Uint) DeepCopy() interface{} {
|
||||
return NewUint(v.Val())
|
||||
}
|
||||
|
||||
@ -75,3 +75,8 @@ func (v *Uint32) UnmarshalValue(value interface{}) error {
|
||||
v.Set(gconv.Uint32(value))
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (v *Uint32) DeepCopy() interface{} {
|
||||
return NewUint32(v.Val())
|
||||
}
|
||||
|
||||
@ -75,3 +75,8 @@ func (v *Uint64) UnmarshalValue(value interface{}) error {
|
||||
v.Set(gconv.Uint64(value))
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (v *Uint64) DeepCopy() interface{} {
|
||||
return NewUint64(v.Val())
|
||||
}
|
||||
|
||||
@ -11,9 +11,11 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gtype"
|
||||
"github.com/gogf/gf/v2/internal/deepcopy"
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/gogf/gf/v2/util/gutil"
|
||||
)
|
||||
|
||||
// Var is an universal variable type implementer.
|
||||
@ -37,6 +39,11 @@ func New(value interface{}, safe ...bool) *Var {
|
||||
}
|
||||
}
|
||||
|
||||
// Copy does a deep copy of current Var and returns a pointer to this Var.
|
||||
func (v *Var) Copy() *Var {
|
||||
return New(gutil.Copy(v.Val()), v.safe)
|
||||
}
|
||||
|
||||
// Clone does a shallow copy of current Var and returns a pointer to this Var.
|
||||
func (v *Var) Clone() *Var {
|
||||
return New(v.Val(), v.safe)
|
||||
@ -188,3 +195,8 @@ func (v *Var) UnmarshalValue(value interface{}) error {
|
||||
v.Set(value)
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeepCopy implements interface for deep copy of current type.
|
||||
func (v *Var) DeepCopy() interface{} {
|
||||
return New(deepcopy.Copy(v.Val()), v.safe)
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
@ -303,3 +304,27 @@ func Test_UnmarshalValue(t *testing.T) {
|
||||
t.Assert(v.Var.String(), "v")
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Copy(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
src := g.Map{
|
||||
"k1": "v1",
|
||||
"k2": "v2",
|
||||
}
|
||||
srcVar := gvar.New(src)
|
||||
dstVar := srcVar.Copy()
|
||||
t.Assert(srcVar.Map(), src)
|
||||
t.Assert(dstVar.Map(), src)
|
||||
|
||||
dstVar.Map()["k3"] = "v3"
|
||||
t.Assert(srcVar.Map(), g.Map{
|
||||
"k1": "v1",
|
||||
"k2": "v2",
|
||||
})
|
||||
t.Assert(dstVar.Map(), g.Map{
|
||||
"k1": "v1",
|
||||
"k2": "v2",
|
||||
"k3": "v3",
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@ -75,8 +75,7 @@ Note:
|
||||
- It does not support `InsertIgnore/InsertGetId` features.
|
||||
- It does not support `Save/Replace` features.
|
||||
- It does not support `Transaction` feature.
|
||||
- It does not support `Transaction` feature.
|
||||
|
||||
- It does not support `RowsAffected` feature.
|
||||
|
||||
# Custom Drivers
|
||||
|
||||
|
||||
@ -10,19 +10,23 @@ package clickhouse
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/ClickHouse/clickhouse-go"
|
||||
|
||||
"github.com/ClickHouse/clickhouse-go/v2"
|
||||
"github.com/gogf/gf/v2/container/gmap"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/google/uuid"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Driver is the driver for postgresql database.
|
||||
@ -32,13 +36,23 @@ type Driver struct {
|
||||
|
||||
var (
|
||||
// tableFieldsMap caches the table information retrieved from database.
|
||||
tableFieldsMap = gmap.New(true)
|
||||
errUnsupportedInsertIgnore = errors.New("unsupported method: InsertIgnore")
|
||||
errUnsupportedInsertGetId = errors.New("unsupported method: InsertGetId")
|
||||
errUnsupportedReplace = errors.New("unsupported method: Replace")
|
||||
errUnsupportedBegin = errors.New("unsupported method: Begin")
|
||||
errUnsupportedTransaction = errors.New("unsupported method: Transaction")
|
||||
errSQLNull = errors.New("SQL cannot be null")
|
||||
tableFieldsMap = gmap.New(true)
|
||||
|
||||
errUnsupportedInsertIgnore = errors.New("unsupported method:InsertIgnore")
|
||||
errUnsupportedInsertGetId = errors.New("unsupported method:InsertGetId")
|
||||
errUnsupportedReplace = errors.New("unsupported method:Replace")
|
||||
errUnsupportedBegin = errors.New("unsupported method:Begin")
|
||||
errUnsupportedTransaction = errors.New("unsupported method:Transaction")
|
||||
)
|
||||
|
||||
const (
|
||||
updateFilterPattern = `(?i)UPDATE[\s]+?(\w+[\.]?\w+)[\s]+?SET`
|
||||
deleteFilterPattern = `(?i)DELETE[\s]+?FROM[\s]+?(\w+[\.]?\w+)`
|
||||
filterTypePattern = `(?i)^UPDATE|DELETE`
|
||||
replaceSchemaPattern = `@(.+?)/([\w\.\-]+)+`
|
||||
needParsedSqlInCtx gctx.StrKey = "NeedParsedSql"
|
||||
OrmTagForStruct = "orm"
|
||||
driverName = "clickhouse"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -62,27 +76,28 @@ func (d *Driver) New(core *gdb.Core, node *gdb.ConfigNode) (gdb.DB, error) {
|
||||
|
||||
// Open creates and returns an underlying sql.DB object for clickhouse.
|
||||
func (d *Driver) Open(config *gdb.ConfigNode) (*sql.DB, error) {
|
||||
var (
|
||||
source string
|
||||
driver = "clickhouse"
|
||||
)
|
||||
// clickhouse://username:password@host1:9000,host2:9000/database?dial_timeout=200ms&max_execution_time=60
|
||||
if config.Link != "" {
|
||||
source = config.Link
|
||||
// Custom changing the schema in runtime.
|
||||
if config.Name != "" {
|
||||
source, _ = gregex.ReplaceString(`@(.+?)/([\w\.\-]+)+`, "@$1/"+config.Name, source)
|
||||
config.Link, _ = gregex.ReplaceString(replaceSchemaPattern, "@$1/"+config.Name, config.Link)
|
||||
} else {
|
||||
// If no schema, the link is matched for replacement
|
||||
dbName, _ := gregex.MatchString(replaceSchemaPattern, config.Link)
|
||||
if len(dbName) > 0 {
|
||||
config.Name = dbName[len(dbName)-1]
|
||||
}
|
||||
}
|
||||
} else if config.Pass != "" {
|
||||
source = fmt.Sprintf(
|
||||
"clickhouse://%s:%s@%s:%s/%s?charset=%s&debug=%s",
|
||||
config.User, config.Pass, config.Host, config.Port, config.Name, config.Charset, gconv.String(config.Debug))
|
||||
config.Link = fmt.Sprintf(
|
||||
"clickhouse://%s:%s@%s:%s/%s?charset=%s&debug=%t",
|
||||
config.User, url.PathEscape(config.Pass), config.Host, config.Port, config.Name, config.Charset, config.Debug)
|
||||
} else {
|
||||
source = fmt.Sprintf(
|
||||
"clickhouse://%s@%s:%s/%s?charset=%s&debug=%s",
|
||||
config.User, config.Host, config.Port, config.Name, config.Charset, gconv.String(config.Debug))
|
||||
config.Link = fmt.Sprintf(
|
||||
"clickhouse://%s@%s:%s/%s?charset=%s&debug=%t",
|
||||
config.User, config.Host, config.Port, config.Name, config.Charset, config.Debug)
|
||||
}
|
||||
db, err := sql.Open(driver, source)
|
||||
db, err := sql.Open(driverName, config.Link)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -133,7 +148,7 @@ func (d *Driver) TableFields(
|
||||
if link, err = d.SlaveLink(useSchema); err != nil {
|
||||
return nil
|
||||
}
|
||||
getColumnsSql := fmt.Sprintf("select name,position,default_expression,comment from `system`.columns c where database = '%s' and `table` = '%s'", d.GetConfig().Name, table)
|
||||
getColumnsSql := fmt.Sprintf("select name,position,default_expression,comment,type,is_in_partition_key,is_in_sorting_key,is_in_primary_key,is_in_sampling_key from `system`.columns c where database = '%s' and `table` = '%s'", d.GetConfig().Name, table)
|
||||
result, err = d.DoSelect(ctx, link, getColumnsSql)
|
||||
if err != nil {
|
||||
return nil
|
||||
@ -215,29 +230,55 @@ func (d *Driver) ping(conn *sql.DB) error {
|
||||
func (d *Driver) DoFilter(
|
||||
ctx context.Context, link gdb.Link, originSql string, args []interface{},
|
||||
) (newSql string, newArgs []interface{}, err error) {
|
||||
// It replaces STD SQL to Clickhouse SQL grammar.
|
||||
// MySQL eg: UPDATE `table` SET xxx
|
||||
// Clickhouse eg: ALTER TABLE `table` UPDATE xxx
|
||||
// MySQL eg: DELETE FROM `table`
|
||||
// Clickhouse eg: ALTER TABLE `table` DELETE WHERE filter_expr
|
||||
result, err := gregex.MatchString("(?i)^UPDATE|DELETE", originSql)
|
||||
if len(args) == 0 {
|
||||
return originSql, args, nil
|
||||
}
|
||||
|
||||
var index int
|
||||
// Convert placeholder char '?' to string "$x".
|
||||
originSql, _ = gregex.ReplaceStringFunc(`\?`, originSql, func(s string) string {
|
||||
index++
|
||||
return fmt.Sprintf(`$%d`, index)
|
||||
})
|
||||
|
||||
// Only SQL generated through the framework is processed.
|
||||
if !d.getNeedParsedSqlFromCtx(ctx) {
|
||||
return originSql, args, nil
|
||||
}
|
||||
|
||||
// replace STD SQL to Clickhouse SQL grammar
|
||||
modeRes, err := gregex.MatchString(filterTypePattern, strings.TrimSpace(originSql))
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if len(result) != 0 {
|
||||
sqlSlice := strings.Split(originSql, " ")
|
||||
if len(sqlSlice) < 3 {
|
||||
return "", nil, errSQLNull
|
||||
if len(modeRes) == 0 {
|
||||
return originSql, args, nil
|
||||
}
|
||||
|
||||
// Only delete/ UPDATE statements require filter
|
||||
switch strings.ToUpper(modeRes[0]) {
|
||||
case "UPDATE":
|
||||
// MySQL eg: UPDATE table_name SET field1=new-value1, field2=new-value2 [WHERE Clause]
|
||||
// Clickhouse eg: ALTER TABLE [db.]table UPDATE column1 = expr1 [, ...] WHERE filter_expr
|
||||
newSql, err = gregex.ReplaceStringFuncMatch(updateFilterPattern, originSql, func(s []string) string {
|
||||
return fmt.Sprintf("ALTER TABLE %s UPDATE", s[1])
|
||||
})
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
ck := []string{"ALTER", "TABLE"}
|
||||
switch strings.ToUpper(result[0]) {
|
||||
case "UPDATE":
|
||||
sqlSlice = append(append(append(ck, sqlSlice[1]), result[0]), sqlSlice[3:]...)
|
||||
return strings.Join(sqlSlice, " "), args, nil
|
||||
case "DELETE":
|
||||
sqlSlice = append(append(append(ck, sqlSlice[2]), result[0]), sqlSlice[3:]...)
|
||||
return strings.Join(sqlSlice, " "), args, nil
|
||||
return newSql, args, nil
|
||||
|
||||
case "DELETE":
|
||||
// MySQL eg: DELETE FROM table_name [WHERE Clause]
|
||||
// Clickhouse eg: ALTER TABLE [db.]table [ON CLUSTER cluster] DELETE WHERE filter_expr
|
||||
newSql, err = gregex.ReplaceStringFuncMatch(deleteFilterPattern, originSql, func(s []string) string {
|
||||
return fmt.Sprintf("ALTER TABLE %s DELETE", s[1])
|
||||
})
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
return newSql, args, nil
|
||||
|
||||
}
|
||||
return originSql, args, nil
|
||||
}
|
||||
@ -295,6 +336,82 @@ func (d *Driver) DoInsert(
|
||||
return stdSqlResult, tx.Commit()
|
||||
}
|
||||
|
||||
// ConvertDataForRecord converting for any data that will be inserted into table/collection as a record.
|
||||
func (d *Driver) ConvertDataForRecord(ctx context.Context, value interface{}) (map[string]interface{}, error) {
|
||||
m := gconv.Map(value, OrmTagForStruct)
|
||||
|
||||
// transforms a value of a particular type
|
||||
for k, v := range m {
|
||||
switch itemValue := v.(type) {
|
||||
|
||||
case time.Time:
|
||||
m[k] = itemValue
|
||||
// If the time is zero, it then updates it to nil,
|
||||
// which will insert/update the value to database as "null".
|
||||
if itemValue.IsZero() {
|
||||
m[k] = nil
|
||||
}
|
||||
|
||||
case uuid.UUID:
|
||||
m[k] = itemValue
|
||||
|
||||
case *time.Time:
|
||||
m[k] = itemValue
|
||||
// If the time is zero, it then updates it to nil,
|
||||
// which will insert/update the value to database as "null".
|
||||
if itemValue == nil || itemValue.IsZero() {
|
||||
m[k] = nil
|
||||
}
|
||||
|
||||
case gtime.Time:
|
||||
// for gtime type, needs to get time.Time
|
||||
m[k] = itemValue.Time
|
||||
// If the time is zero, it then updates it to nil,
|
||||
// which will insert/update the value to database as "null".
|
||||
if itemValue.IsZero() {
|
||||
m[k] = nil
|
||||
}
|
||||
|
||||
case *gtime.Time:
|
||||
// for gtime type, needs to get time.Time
|
||||
if itemValue != nil {
|
||||
m[k] = itemValue.Time
|
||||
}
|
||||
// If the time is zero, it then updates it to nil,
|
||||
// which will insert/update the value to database as "null".
|
||||
if itemValue == nil || itemValue.IsZero() {
|
||||
m[k] = nil
|
||||
}
|
||||
|
||||
default:
|
||||
// if the other type implements valuer for the driver package
|
||||
// the converted result is used
|
||||
// otherwise the interface data is committed
|
||||
valuer, ok := itemValue.(driver.Valuer)
|
||||
if !ok {
|
||||
m[k] = itemValue
|
||||
continue
|
||||
}
|
||||
convertedValue, err := valuer.Value()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m[k] = convertedValue
|
||||
}
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (d *Driver) DoDelete(ctx context.Context, link gdb.Link, table string, condition string, args ...interface{}) (result sql.Result, err error) {
|
||||
ctx = d.injectNeedParsedSql(ctx)
|
||||
return d.Core.DoDelete(ctx, link, table, condition, args...)
|
||||
}
|
||||
|
||||
func (d *Driver) DoUpdate(ctx context.Context, link gdb.Link, table string, data interface{}, condition string, args ...interface{}) (result sql.Result, err error) {
|
||||
ctx = d.injectNeedParsedSql(ctx)
|
||||
return d.Core.DoUpdate(ctx, link, table, data, condition, args...)
|
||||
}
|
||||
|
||||
// InsertIgnore Other queries for modifying data parts are not supported: REPLACE, MERGE, UPSERT, INSERT UPDATE.
|
||||
func (d *Driver) InsertIgnore(ctx context.Context, table string, data interface{}, batch ...int) (sql.Result, error) {
|
||||
return nil, errUnsupportedInsertIgnore
|
||||
@ -317,3 +434,17 @@ func (d *Driver) Begin(ctx context.Context) (tx *gdb.TX, err error) {
|
||||
func (d *Driver) Transaction(ctx context.Context, f func(ctx context.Context, tx *gdb.TX) error) error {
|
||||
return errUnsupportedTransaction
|
||||
}
|
||||
|
||||
func (d *Driver) injectNeedParsedSql(ctx context.Context) context.Context {
|
||||
if ctx.Value(needParsedSqlInCtx) != nil {
|
||||
return ctx
|
||||
}
|
||||
return context.WithValue(ctx, needParsedSqlInCtx, true)
|
||||
}
|
||||
|
||||
func (d *Driver) getNeedParsedSqlFromCtx(ctx context.Context) bool {
|
||||
if ctx.Value(needParsedSqlInCtx) != nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@ -3,6 +3,10 @@ package clickhouse
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/util/guid"
|
||||
"github.com/google/uuid"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -13,18 +17,103 @@ import (
|
||||
"github.com/gogf/gf/v2/util/grand"
|
||||
)
|
||||
|
||||
// table DDL
|
||||
// CREATE TABLE visits
|
||||
// (
|
||||
// id UInt64,
|
||||
// duration Float64,
|
||||
// url String,
|
||||
// created DateTime
|
||||
//)
|
||||
// ENGINE = MergeTree()
|
||||
// PRIMARY KEY id
|
||||
// ORDER BY id
|
||||
func InitClickhouse() gdb.DB {
|
||||
const (
|
||||
sqlVisitsDDL = `
|
||||
CREATE TABLE IF NOT EXISTS visits (
|
||||
id UInt64,
|
||||
duration Float64,
|
||||
url String,
|
||||
created DateTime
|
||||
) ENGINE = MergeTree()
|
||||
PRIMARY KEY id
|
||||
ORDER BY id
|
||||
`
|
||||
dimSqlDDL = `
|
||||
CREATE TABLE IF NOT EXISTS dim (
|
||||
"code" String COMMENT '编码',
|
||||
"translation" String COMMENT '译文',
|
||||
"superior" UInt64 COMMENT '上级ID',
|
||||
"row_number" UInt16 COMMENT '行号',
|
||||
"is_active" UInt8 COMMENT '是否激活',
|
||||
"is_preset" UInt8 COMMENT '是否预置',
|
||||
"category" String COMMENT '类别',
|
||||
"tree_path" Array(String) COMMENT '树路径',
|
||||
"id" UInt64 COMMENT '代理主键ID',
|
||||
"scd" UInt64 COMMENT '缓慢变化维ID',
|
||||
"version" UInt64 COMMENT 'Merge版本ID',
|
||||
"sign" Int8 COMMENT '标识位',
|
||||
"created_by" UInt64 COMMENT '创建者ID',
|
||||
"created_at" DateTime64(3,'Asia/Shanghai') COMMENT '创建时间',
|
||||
"updated_by" UInt64 COMMENT '最后修改者ID',
|
||||
"updated_at" DateTime64(3,'Asia/Shanghai') COMMENT '最后修改时间',
|
||||
"updated_tick" UInt16 COMMENT '累计修改次数'
|
||||
) ENGINE = ReplacingMergeTree("version")
|
||||
ORDER BY ("id","scd")
|
||||
COMMENT '会计准则';
|
||||
`
|
||||
dimSqlDML = `
|
||||
insert into dim (code, translation, superior, row_number, is_active, is_preset, category, tree_path, id, scd, version, sign, created_by, created_at, updated_by, updated_at, updated_tick)
|
||||
values ('CN', '{"zh_CN":"中国大陆会计准则","en_US":"Chinese mainland accounting legislation"}', 0, 1, 1, 1, 1, '[''CN'']', 607972403489804288, 0, 0, 0, 607536279118155777, '2017-09-06 00:00:00', 607536279118155777, '2017-09-06 00:00:00', 0),
|
||||
('HK', '{"zh_CN":"中国香港会计准则","en_US":"Chinese Hong Kong accounting legislation"}', 0, 2, 1, 1, 1, '[''HK'']', 607972558544834566, 0, 0, 0, 607536279118155777, '2017-09-06 00:00:00', 607536279118155777, '2017-09-06 00:00:00', 0);
|
||||
`
|
||||
factSqlDDL = `
|
||||
CREATE TABLE IF NOT EXISTS fact (
|
||||
"adjustment_level" UInt64 COMMENT '调整层ID',
|
||||
"data_version" UInt64 COMMENT '数据版本ID',
|
||||
"accounting_legislation" UInt64 COMMENT '会计准则ID',
|
||||
"fiscal_year" UInt16 COMMENT '会计年度',
|
||||
"fiscal_period" UInt8 COMMENT '会计期间',
|
||||
"fiscal_year_period" UInt32 COMMENT '会计年度期间',
|
||||
"legal_entity" UInt64 COMMENT '法人主体ID',
|
||||
"cost_center" UInt64 COMMENT '成本中心ID',
|
||||
"legal_entity_partner" UInt64 COMMENT '内部关联方ID',
|
||||
"financial_posting" UInt64 COMMENT '凭证头ID',
|
||||
"line" UInt16 COMMENT '行号',
|
||||
"general_ledger_account" UInt64 COMMENT '总账科目ID',
|
||||
"debit" Decimal64(9) COMMENT '借方金额',
|
||||
"credit" Decimal64(9) COMMENT '贷方金额',
|
||||
"transaction_currency" UInt64 COMMENT '交易币种ID',
|
||||
"debit_tc" Decimal64(9) COMMENT '借方金额(交易币种)',
|
||||
"credit_tc" Decimal64(9) COMMENT '贷方金额(交易币种)',
|
||||
"posting_date" Date32 COMMENT '过账日期',
|
||||
"gc_year" UInt16 COMMENT '公历年',
|
||||
"gc_quarter" UInt8 COMMENT '公历季',
|
||||
"gc_month" UInt8 COMMENT '公历月',
|
||||
"gc_week" UInt8 COMMENT '公历周',
|
||||
"raw_info" String COMMENT '源信息',
|
||||
"summary" String COMMENT '摘要',
|
||||
"id" UInt64 COMMENT '代理主键ID',
|
||||
"version" UInt64 COMMENT 'Merge版本ID',
|
||||
"sign" Int8 COMMENT '标识位'
|
||||
) ENGINE = ReplacingMergeTree("version")
|
||||
ORDER BY ("adjustment_level","data_version","legal_entity","fiscal_year","fiscal_period","financial_posting","line")
|
||||
PARTITION BY ("adjustment_level","data_version","legal_entity","fiscal_year","fiscal_period")
|
||||
COMMENT '数据主表';
|
||||
`
|
||||
factSqlDML = `
|
||||
insert into fact (adjustment_level, data_version, accounting_legislation, fiscal_year, fiscal_period, fiscal_year_period, legal_entity, cost_center, legal_entity_partner, financial_posting, line, general_ledger_account, debit, credit, transaction_currency, debit_tc, credit_tc, posting_date, gc_year, gc_quarter, gc_month, gc_week, raw_info, summary, id, version, sign)
|
||||
values (607970943242866688, 607973669943119880, 607972403489804288, 2022, 3, 202203, 607974511316307985, 0, 607976190010986520, 607996702456025136, 1, 607985607569838111, 8674.39, 0, 607974898261823505, 8674.39, 0, '2022-03-05', 2022, 1, 3, 11, '{}', '摘要', 607992882741121073, 0, 0),
|
||||
(607970943242866688, 607973669943119880, 607972403489804288, 2022, 4, 202204, 607974511316307985, 0, 607976190010986520, 607993586419503145, 1, 607985607569838111, 9999.88, 0, 607974898261823505, 9999.88, 0, '2022-04-10', 2022, 2, 4, 18, '{}', '摘要', 607996939140599857, 0, 0);
|
||||
`
|
||||
expmSqlDDL = `
|
||||
CREATE TABLE IF NOT EXISTS data_type (
|
||||
Col1 UInt8 COMMENT '列1'
|
||||
, Col2 Nullable(String) COMMENT '列2'
|
||||
, Col3 FixedString(3) COMMENT '列3'
|
||||
, Col4 String COMMENT '列4'
|
||||
, Col5 Map(String, UInt8) COMMENT '列5'
|
||||
, Col6 Array(String) COMMENT '列6'
|
||||
, Col7 Tuple(String, UInt8, Array(Map(String, String))) COMMENT '列7'
|
||||
, Col8 DateTime COMMENT '列8'
|
||||
, Col9 UUID COMMENT '列9'
|
||||
, Col10 DateTime COMMENT '列10'
|
||||
) ENGINE = MergeTree()
|
||||
PRIMARY KEY Col4
|
||||
ORDER BY Col4
|
||||
`
|
||||
)
|
||||
|
||||
func clickhouseConfigDB() gdb.DB {
|
||||
connect, err := gdb.New(gdb.ConfigNode{
|
||||
Host: "127.0.0.1",
|
||||
Port: "9000",
|
||||
@ -38,135 +127,150 @@ func InitClickhouse() gdb.DB {
|
||||
return connect
|
||||
}
|
||||
|
||||
func TestDriverClickhouse_Create(t *testing.T) {
|
||||
gtest.AssertNil(createClickhouseTable(InitClickhouse()))
|
||||
}
|
||||
|
||||
func createClickhouseTable(connect gdb.DB) error {
|
||||
sqlStr := "CREATE TABLE IF NOT EXISTS visits (id UInt64,duration Float64,url String,created DateTime) ENGINE = MergeTree() PRIMARY KEY id ORDER BY id"
|
||||
_, err := connect.Exec(context.Background(), sqlStr)
|
||||
func createClickhouseTableVisits(connect gdb.DB) error {
|
||||
_, err := connect.Exec(context.Background(), sqlVisitsDDL)
|
||||
return err
|
||||
}
|
||||
|
||||
func dropClickhouseTable(conn gdb.DB) {
|
||||
func createClickhouseTableDim(connect gdb.DB) error {
|
||||
_, err := connect.Exec(context.Background(), dimSqlDDL)
|
||||
return err
|
||||
}
|
||||
|
||||
func createClickhouseTableFact(connect gdb.DB) error {
|
||||
_, err := connect.Exec(context.Background(), factSqlDDL)
|
||||
return err
|
||||
}
|
||||
|
||||
func createClickhouseExampleTable(connect gdb.DB) error {
|
||||
_, err := connect.Exec(context.Background(), expmSqlDDL)
|
||||
return err
|
||||
}
|
||||
|
||||
func dropClickhouseTableVisits(conn gdb.DB) {
|
||||
sqlStr := fmt.Sprintf("DROP TABLE IF EXISTS `visits`")
|
||||
_, _ = conn.Exec(context.Background(), sqlStr)
|
||||
}
|
||||
|
||||
func dropClickhouseTableDim(conn gdb.DB) {
|
||||
sqlStr := fmt.Sprintf("DROP TABLE IF EXISTS `dim`")
|
||||
_, _ = conn.Exec(context.Background(), sqlStr)
|
||||
}
|
||||
|
||||
func dropClickhouseTableFact(conn gdb.DB) {
|
||||
sqlStr := fmt.Sprintf("DROP TABLE IF EXISTS `fact`")
|
||||
_, _ = conn.Exec(context.Background(), sqlStr)
|
||||
}
|
||||
|
||||
func dropClickhouseExampleTable(conn gdb.DB) {
|
||||
sqlStr := fmt.Sprintf("DROP TABLE IF EXISTS `data_type`")
|
||||
_, _ = conn.Exec(context.Background(), sqlStr)
|
||||
}
|
||||
|
||||
func TestDriverClickhouse_Create(t *testing.T) {
|
||||
gtest.AssertNil(createClickhouseTableVisits(clickhouseConfigDB()))
|
||||
}
|
||||
|
||||
func TestDriverClickhouse_New(t *testing.T) {
|
||||
connect := InitClickhouse()
|
||||
connect := clickhouseConfigDB()
|
||||
gtest.AssertNE(connect, nil)
|
||||
gtest.AssertNil(connect.PingMaster())
|
||||
gtest.AssertNil(connect.PingSlave())
|
||||
}
|
||||
|
||||
func TestDriverClickhouse_OpenLink_Ping(t *testing.T) {
|
||||
connect := clickhouseConfigDB()
|
||||
gtest.AssertNE(connect, nil)
|
||||
gtest.AssertNil(connect.PingMaster())
|
||||
}
|
||||
|
||||
func TestDriverClickhouse_Tables(t *testing.T) {
|
||||
connect := InitClickhouse()
|
||||
gtest.AssertEQ(createClickhouseTable(connect), nil)
|
||||
defer dropClickhouseTable(connect)
|
||||
connect := clickhouseConfigDB()
|
||||
gtest.AssertEQ(createClickhouseTableVisits(connect), nil)
|
||||
defer dropClickhouseTableVisits(connect)
|
||||
tables, err := connect.Tables(context.Background())
|
||||
gtest.AssertNil(err)
|
||||
gtest.AssertNE(len(tables), 0)
|
||||
}
|
||||
|
||||
func TestDriverClickhouse_TableFields_Use_Config(t *testing.T) {
|
||||
connect := clickhouseConfigDB()
|
||||
gtest.AssertNil(createClickhouseTableVisits(connect))
|
||||
defer dropClickhouseTableVisits(connect)
|
||||
field, err := connect.TableFields(context.Background(), "visits")
|
||||
gtest.AssertNil(err)
|
||||
gtest.AssertEQ(len(field), 4)
|
||||
gtest.AssertNQ(field, nil)
|
||||
}
|
||||
|
||||
func TestDriverClickhouse_TableFields_Use_Link(t *testing.T) {
|
||||
connect := clickhouseConfigDB()
|
||||
gtest.AssertNil(createClickhouseTableVisits(connect))
|
||||
defer dropClickhouseTableVisits(connect)
|
||||
field, err := connect.TableFields(context.Background(), "visits")
|
||||
gtest.AssertNil(err)
|
||||
gtest.AssertEQ(len(field), 4)
|
||||
gtest.AssertNQ(field, nil)
|
||||
}
|
||||
|
||||
func TestDriverClickhouse_Transaction(t *testing.T) {
|
||||
connect := InitClickhouse()
|
||||
defer dropClickhouseTable(connect)
|
||||
connect := clickhouseConfigDB()
|
||||
defer dropClickhouseTableVisits(connect)
|
||||
gtest.AssertNE(connect.Transaction(context.Background(), func(ctx context.Context, tx *gdb.TX) error {
|
||||
return nil
|
||||
}), nil)
|
||||
}
|
||||
|
||||
func TestDriverClickhouse_DoDelete(t *testing.T) {
|
||||
connect := InitClickhouse()
|
||||
gtest.AssertEQ(createClickhouseTable(connect), nil)
|
||||
defer dropClickhouseTable(connect)
|
||||
_, err := connect.Model("visits").Where("created >", "2021-01-01 00:00:00").Delete()
|
||||
gtest.AssertNil(err)
|
||||
}
|
||||
|
||||
func TestDriverClickhouse_DoUpdate(t *testing.T) {
|
||||
connect := InitClickhouse()
|
||||
gtest.AssertEQ(createClickhouseTable(connect), nil)
|
||||
defer dropClickhouseTable(connect)
|
||||
_, err := connect.Model("visits").Where("created > ", "2021-01-01 15:15:15").Data(g.Map{
|
||||
"created": time.Now().Format("2006-01-02 15:04:05"),
|
||||
}).Update()
|
||||
gtest.AssertNil(err)
|
||||
_, err = connect.Model("visits").Data(g.Map{
|
||||
"created": time.Now().Format("2006-01-02 15:04:05"),
|
||||
}).Update()
|
||||
gtest.AssertNE(err, nil)
|
||||
_, err = connect.Model("visits").Update()
|
||||
gtest.AssertNE(err, nil)
|
||||
}
|
||||
|
||||
func TestDriverClickhouse_Select(t *testing.T) {
|
||||
connect := InitClickhouse()
|
||||
gtest.AssertEQ(createClickhouseTable(connect), nil)
|
||||
defer dropClickhouseTable(connect)
|
||||
data, err := connect.Model("visits").All()
|
||||
gtest.AssertNil(err)
|
||||
gtest.AssertEQ(len(data), 0)
|
||||
}
|
||||
|
||||
func TestDriver_InsertIgnore(t *testing.T) {
|
||||
connect := InitClickhouse()
|
||||
func TestDriverClickhouse_InsertIgnore(t *testing.T) {
|
||||
connect := clickhouseConfigDB()
|
||||
_, err := connect.InsertIgnore(context.Background(), "", nil)
|
||||
gtest.AssertEQ(err, errUnsupportedInsertIgnore)
|
||||
}
|
||||
|
||||
func TestDriver_InsertAndGetId(t *testing.T) {
|
||||
connect := InitClickhouse()
|
||||
func TestDriverClickhouse_InsertAndGetId(t *testing.T) {
|
||||
connect := clickhouseConfigDB()
|
||||
_, err := connect.InsertAndGetId(context.Background(), "", nil)
|
||||
gtest.AssertEQ(err, errUnsupportedInsertGetId)
|
||||
}
|
||||
|
||||
func TestDriver_Replace(t *testing.T) {
|
||||
connect := InitClickhouse()
|
||||
_, err := connect.Replace(context.Background(), "", nil)
|
||||
gtest.AssertEQ(err, errUnsupportedReplace)
|
||||
}
|
||||
|
||||
func TestDriverClickhouse_DoInsertOne(t *testing.T) {
|
||||
connect := InitClickhouse()
|
||||
gtest.AssertEQ(createClickhouseTable(connect), nil)
|
||||
defer dropClickhouseTable(connect)
|
||||
func TestDriverClickhouse_InsertOne(t *testing.T) {
|
||||
connect := clickhouseConfigDB()
|
||||
gtest.AssertEQ(createClickhouseTableVisits(connect), nil)
|
||||
defer dropClickhouseTableVisits(connect)
|
||||
_, err := connect.Model("visits").Data(g.Map{
|
||||
"id": grand.Intn(999),
|
||||
"duration": float64(grand.Intn(999)),
|
||||
"url": gconv.String(grand.Intn(999)),
|
||||
"created": time.Now().Format("2006-01-02 15:04:05"),
|
||||
"created": time.Now(),
|
||||
}).Insert()
|
||||
gtest.AssertNil(err)
|
||||
}
|
||||
|
||||
func TestDriver_DoInsertMany(t *testing.T) {
|
||||
connect := InitClickhouse()
|
||||
gtest.AssertEQ(createClickhouseTable(connect), nil)
|
||||
defer dropClickhouseTable(connect)
|
||||
func TestDriverClickhouse_InsertMany(t *testing.T) {
|
||||
connect := clickhouseConfigDB()
|
||||
gtest.AssertEQ(createClickhouseTableVisits(connect), nil)
|
||||
defer dropClickhouseTableVisits(connect)
|
||||
tx, err := connect.Begin(context.Background())
|
||||
gtest.AssertEQ(err, errUnsupportedBegin)
|
||||
gtest.AssertNil(tx)
|
||||
}
|
||||
|
||||
func TestDriverClickhouse_DoInsert(t *testing.T) {
|
||||
connect := InitClickhouse()
|
||||
gtest.AssertEQ(createClickhouseTable(connect), nil)
|
||||
func TestDriverClickhouse_Insert(t *testing.T) {
|
||||
connect := clickhouseConfigDB()
|
||||
gtest.AssertEQ(createClickhouseTableVisits(connect), nil)
|
||||
defer dropClickhouseTableVisits(connect)
|
||||
type insertItem struct {
|
||||
Id int `orm:"id"`
|
||||
Duration float64 `orm:"duration"`
|
||||
Url string `orm:"url"`
|
||||
Created string `orm:"created"`
|
||||
Id uint64 `orm:"id"`
|
||||
Duration float64 `orm:"duration"`
|
||||
Url string `orm:"url"`
|
||||
Created time.Time `orm:"created"`
|
||||
}
|
||||
var (
|
||||
insertUrl = "https://goframe.org"
|
||||
total = 0
|
||||
item = insertItem{
|
||||
Id: 0,
|
||||
Duration: 1,
|
||||
Url: insertUrl,
|
||||
Created: time.Now().Format("2006-01-02 15:04:05"),
|
||||
Created: time.Now(),
|
||||
}
|
||||
)
|
||||
_, err := connect.Model("visits").Data(item).Insert()
|
||||
@ -176,13 +280,12 @@ func TestDriverClickhouse_DoInsert(t *testing.T) {
|
||||
total, err = connect.Model("visits").Count()
|
||||
gtest.AssertNil(err)
|
||||
gtest.AssertEQ(total, 2)
|
||||
list := []*insertItem{}
|
||||
var list []*insertItem
|
||||
for i := 0; i < 50; i++ {
|
||||
list = append(list, &insertItem{
|
||||
Id: grand.Intn(999),
|
||||
Duration: float64(grand.Intn(999)),
|
||||
Url: insertUrl,
|
||||
Created: time.Now().Format("2006-01-02 15:04:05"),
|
||||
Created: time.Now(),
|
||||
})
|
||||
}
|
||||
_, err = connect.Model("visits").Data(list).Insert()
|
||||
@ -192,63 +295,248 @@ func TestDriverClickhouse_DoInsert(t *testing.T) {
|
||||
total, err = connect.Model("visits").Count()
|
||||
gtest.AssertNil(err)
|
||||
gtest.AssertEQ(total, 102)
|
||||
dropClickhouseTable(connect)
|
||||
}
|
||||
|
||||
func TestDriverClickhouse_DoExec(t *testing.T) {
|
||||
connect := InitClickhouse()
|
||||
gtest.AssertNil(createClickhouseTable(connect))
|
||||
defer dropClickhouseTable(connect)
|
||||
func TestDriverClickhouse_Insert_Use_Exec(t *testing.T) {
|
||||
connect := clickhouseConfigDB()
|
||||
gtest.AssertEQ(createClickhouseTableFact(connect), nil)
|
||||
defer dropClickhouseTableFact(connect)
|
||||
_, err := connect.Exec(context.Background(), factSqlDML)
|
||||
gtest.AssertNil(err)
|
||||
}
|
||||
|
||||
func TestDriverClickhouse_Delete(t *testing.T) {
|
||||
connect := clickhouseConfigDB()
|
||||
gtest.AssertEQ(createClickhouseTableVisits(connect), nil)
|
||||
defer dropClickhouseTableVisits(connect)
|
||||
_, err := connect.Model("visits").Where("created >", "2021-01-01 00:00:00").Delete()
|
||||
gtest.AssertNil(err)
|
||||
_, err = connect.Model("visits").
|
||||
Where("created >", "2021-01-01 00:00:00").
|
||||
Where("duration > ", 0).
|
||||
Where("url is not null").
|
||||
Delete()
|
||||
gtest.AssertNil(err)
|
||||
}
|
||||
|
||||
func TestDriverClickhouse_Update(t *testing.T) {
|
||||
connect := clickhouseConfigDB()
|
||||
gtest.AssertEQ(createClickhouseTableVisits(connect), nil)
|
||||
defer dropClickhouseTableVisits(connect)
|
||||
_, err := connect.Model("visits").Where("created > ", "2021-01-01 15:15:15").Data(g.Map{
|
||||
"created": time.Now().Format("2006-01-02 15:04:05"),
|
||||
}).Update()
|
||||
gtest.AssertNil(err)
|
||||
_, err = connect.Model("visits").
|
||||
Where("created > ", "2021-01-01 15:15:15").
|
||||
Where("duration > ", 0).
|
||||
Where("url is not null").
|
||||
Data(g.Map{
|
||||
"created": time.Now().Format("2006-01-02 15:04:05"),
|
||||
}).Update()
|
||||
}
|
||||
|
||||
func TestDriverClickhouse_Replace(t *testing.T) {
|
||||
connect := clickhouseConfigDB()
|
||||
_, err := connect.Replace(context.Background(), "", nil)
|
||||
gtest.AssertEQ(err, errUnsupportedReplace)
|
||||
}
|
||||
|
||||
func TestDriverClickhouse_DoFilter(t *testing.T) {
|
||||
rawSQL := "select * from visits where 1 = 1"
|
||||
this := Driver{}
|
||||
replaceSQL, _, err := this.DoFilter(context.Background(), nil, rawSQL, []interface{}{1})
|
||||
gtest.AssertNil(err)
|
||||
gtest.AssertEQ(rawSQL, replaceSQL)
|
||||
|
||||
// this SQL can't run ,clickhouse will report an error because there is no WHERE statement
|
||||
rawSQL = "update visit set url = '1'"
|
||||
replaceSQL, _, err = this.DoFilter(context.Background(), nil, rawSQL, []interface{}{1})
|
||||
gtest.AssertNil(err)
|
||||
|
||||
// this SQL can't run ,clickhouse will report an error because there is no WHERE statement
|
||||
rawSQL = "delete from visit"
|
||||
replaceSQL, _, err = this.DoFilter(context.Background(), nil, rawSQL, []interface{}{1})
|
||||
gtest.AssertNil(err)
|
||||
|
||||
ctx := this.injectNeedParsedSql(context.Background())
|
||||
rawSQL = "UPDATE visit SET url = '1' WHERE url = '0'"
|
||||
replaceSQL, _, err = this.DoFilter(ctx, nil, rawSQL, []interface{}{1})
|
||||
gtest.AssertNil(err)
|
||||
gtest.AssertEQ(replaceSQL, "ALTER TABLE visit UPDATE url = '1' WHERE url = '0'")
|
||||
|
||||
rawSQL = "DELETE FROM visit WHERE url = '0'"
|
||||
replaceSQL, _, err = this.DoFilter(ctx, nil, rawSQL, []interface{}{1})
|
||||
gtest.AssertNil(err)
|
||||
gtest.AssertEQ(replaceSQL, "ALTER TABLE visit DELETE WHERE url = '0'")
|
||||
}
|
||||
|
||||
func TestDriverClickhouse_Select(t *testing.T) {
|
||||
connect := clickhouseConfigDB()
|
||||
gtest.AssertNil(createClickhouseTableVisits(connect))
|
||||
defer dropClickhouseTableVisits(connect)
|
||||
_, err := connect.Model("visits").Data(g.Map{
|
||||
"url": "goframe.org",
|
||||
"duration": float64(1),
|
||||
}).Insert()
|
||||
gtest.AssertNil(err)
|
||||
temp, err := connect.Model("visits").Where("url", "goframe.org").Where("duration >= ", 1).One()
|
||||
gtest.AssertNil(err)
|
||||
gtest.AssertEQ(temp.IsEmpty(), false)
|
||||
_, err = connect.Model("visits").Data(g.Map{
|
||||
"url": "goframe.org",
|
||||
"duration": float64(2),
|
||||
}).Insert()
|
||||
gtest.AssertNil(err)
|
||||
data, err := connect.Model("visits").Where("url", "goframe.org").Where("duration >= ", 1).All()
|
||||
gtest.AssertNil(err)
|
||||
gtest.AssertEQ(len(data), 2)
|
||||
}
|
||||
|
||||
func TestDriverClickhouse_Exec_OPTIMIZE(t *testing.T) {
|
||||
connect := clickhouseConfigDB()
|
||||
gtest.AssertNil(createClickhouseTableVisits(connect))
|
||||
defer dropClickhouseTableVisits(connect)
|
||||
sqlStr := "OPTIMIZE table visits"
|
||||
_, err := connect.Exec(context.Background(), sqlStr)
|
||||
gtest.AssertNil(err)
|
||||
}
|
||||
|
||||
func TestDriver_DoFilter(t *testing.T) {
|
||||
rawSQL := "select * from visits where 1 = 1"
|
||||
this := Driver{}
|
||||
replaceSQL, _, err := this.DoFilter(nil, nil, rawSQL, nil)
|
||||
func TestDriverClickhouse_ExecInsert(t *testing.T) {
|
||||
connect := clickhouseConfigDB()
|
||||
gtest.AssertEQ(createClickhouseTableDim(connect), nil)
|
||||
defer dropClickhouseTableDim(connect)
|
||||
_, err := connect.Exec(context.Background(), dimSqlDML)
|
||||
gtest.AssertNil(err)
|
||||
gtest.AssertEQ(rawSQL, replaceSQL)
|
||||
rawSQL = "update visit set url = '1'"
|
||||
replaceSQL, _, err = this.DoFilter(nil, nil, rawSQL, nil)
|
||||
gtest.AssertNil(err)
|
||||
// this SQL can't run ,clickhouse will report an error because there is no WHERE statement
|
||||
gtest.AssertEQ(replaceSQL, "ALTER TABLE visit update url = '1'")
|
||||
rawSQL = "delete from visit"
|
||||
replaceSQL, _, err = this.DoFilter(nil, nil, rawSQL, nil)
|
||||
gtest.AssertNil(err)
|
||||
// this SQL can't run ,clickhouse will report an error because there is no WHERE statement
|
||||
gtest.AssertEQ(replaceSQL, "ALTER TABLE visit delete")
|
||||
|
||||
rawSQL = "update visit set url = '1' where url = '0'"
|
||||
replaceSQL, _, err = this.DoFilter(nil, nil, rawSQL, nil)
|
||||
gtest.AssertNil(err)
|
||||
// this SQL can't run ,clickhouse will report an error because there is no WHERE statement
|
||||
gtest.AssertEQ(replaceSQL, "ALTER TABLE visit update url = '1' where url = '0'")
|
||||
rawSQL = "delete from visit where url='0'"
|
||||
replaceSQL, _, err = this.DoFilter(nil, nil, rawSQL, nil)
|
||||
gtest.AssertNil(err)
|
||||
// this SQL can't run ,clickhouse will report an error because there is no WHERE statement
|
||||
gtest.AssertEQ(replaceSQL, "ALTER TABLE visit delete where url='0'")
|
||||
}
|
||||
|
||||
func TestDriver_TableFields(t *testing.T) {
|
||||
connect := InitClickhouse()
|
||||
gtest.AssertNil(createClickhouseTable(connect))
|
||||
defer dropClickhouseTable(connect)
|
||||
field, err := connect.TableFields(context.Background(), "visits")
|
||||
func TestDriverClickhouse_NilTime(t *testing.T) {
|
||||
connect := clickhouseConfigDB()
|
||||
gtest.AssertNil(createClickhouseExampleTable(connect))
|
||||
defer dropClickhouseExampleTable(connect)
|
||||
type testNilTime struct {
|
||||
Col1 uint8
|
||||
Col2 string
|
||||
Col3 string
|
||||
Col4 string
|
||||
Col5 map[string]uint8
|
||||
Col6 []string
|
||||
Col7 []interface{}
|
||||
Col8 *time.Time
|
||||
Col9 uuid.UUID
|
||||
Col10 *gtime.Time
|
||||
}
|
||||
insertData := []*testNilTime{}
|
||||
for i := 0; i < 10000; i++ {
|
||||
insertData = append(insertData, &testNilTime{
|
||||
Col4: "Inc.",
|
||||
Col9: uuid.New(),
|
||||
Col7: []interface{}{ // Tuple(String, UInt8, Array(Map(String, String)))
|
||||
"String Value", uint8(5), []map[string]string{
|
||||
map[string]string{"key": "value"},
|
||||
map[string]string{"key": "value"},
|
||||
map[string]string{"key": "value"},
|
||||
}},
|
||||
})
|
||||
}
|
||||
_, err := connect.Model("data_type").Data(insertData).Insert()
|
||||
gtest.AssertNil(err)
|
||||
gtest.AssertEQ(len(field), 4)
|
||||
gtest.AssertNQ(field, nil)
|
||||
count, err := connect.Model("data_type").Where("Col4", "Inc.").Count()
|
||||
gtest.AssertNil(err)
|
||||
gtest.AssertEQ(count, 10000)
|
||||
}
|
||||
|
||||
func TestDriver_OpenLink(t *testing.T) {
|
||||
connect, err := gdb.New(gdb.ConfigNode{
|
||||
Link: "clickhouse://default@127.0.0.1:9000/default?dial_timeout=200ms&max_execution_time=60&skip_verify=true&secure=false&compress=true",
|
||||
func TestDriverClickhouse_BatchInsert(t *testing.T) {
|
||||
// example from
|
||||
// https://github.com/ClickHouse/clickhouse-go/blob/v2/examples/std/batch/main.go
|
||||
connect := clickhouseConfigDB()
|
||||
gtest.AssertNil(createClickhouseExampleTable(connect))
|
||||
defer dropClickhouseExampleTable(connect)
|
||||
insertData := []g.Map{}
|
||||
for i := 0; i < 10000; i++ {
|
||||
insertData = append(insertData, g.Map{
|
||||
"Col1": uint8(42),
|
||||
"Col2": "ClickHouse",
|
||||
"Col3": "Inc",
|
||||
"Col4": guid.S(),
|
||||
"Col5": map[string]uint8{"key": 1}, // Map(String, UInt8)
|
||||
"Col6": []string{"Q", "W", "E", "R", "T", "Y"}, // Array(String)
|
||||
"Col7": []interface{}{ // Tuple(String, UInt8, Array(Map(String, String)))
|
||||
"String Value", uint8(5), []map[string]string{
|
||||
map[string]string{"key": "value"},
|
||||
map[string]string{"key": "value"},
|
||||
map[string]string{"key": "value"},
|
||||
},
|
||||
},
|
||||
"Col8": gtime.Now(),
|
||||
"Col9": uuid.New(),
|
||||
"Col10": nil,
|
||||
})
|
||||
}
|
||||
_, err := connect.Model("data_type").Data(insertData).Insert()
|
||||
gtest.AssertNil(err)
|
||||
count, err := connect.Model("data_type").Where("Col2", "ClickHouse").Where("Col3", "Inc").Count()
|
||||
gtest.AssertNil(err)
|
||||
gtest.AssertEQ(count, 10000)
|
||||
}
|
||||
|
||||
func TestDriverClickhouse_Open(t *testing.T) {
|
||||
// link
|
||||
// DSM
|
||||
// clickhouse://username:password@host1:9000,host2:9000/database?dial_timeout=200ms&max_execution_time=60
|
||||
link := "clickhouse://default@127.0.0.1:9000,127.0.0.1:9000/default?dial_timeout=200ms&max_execution_time=60"
|
||||
db, err := gdb.New(gdb.ConfigNode{
|
||||
Link: link,
|
||||
Type: "clickhouse",
|
||||
})
|
||||
gtest.AssertNil(err)
|
||||
gtest.AssertNE(connect, nil)
|
||||
gtest.AssertNil(connect.PingMaster())
|
||||
gtest.AssertNil(db.PingMaster())
|
||||
}
|
||||
|
||||
func TestDriverClickhouse_ReplaceConfig(t *testing.T) {
|
||||
db := &Driver{}
|
||||
// parse link's name set to config
|
||||
c1 := &gdb.ConfigNode{}
|
||||
c1.Link = "clickhouse://default@127.0.0.1:9000,127.0.0.1:9000/default?dial_timeout=200ms&max_execution_time=60"
|
||||
_, _ = db.Open(c1)
|
||||
gtest.AssertEQ(c1.Name, "default")
|
||||
// replace link's name from config
|
||||
c2 := &gdb.ConfigNode{}
|
||||
c2.Name = "clickhouseJohn"
|
||||
c2.Link = "clickhouse://default@127.0.0.1:9000,127.0.0.1:9000/default?dial_timeout=200ms&max_execution_time=60"
|
||||
_, _ = db.Open(c2)
|
||||
gtest.AssertEQ(strings.Contains(c2.Link, "clickhouseJohn"), true)
|
||||
}
|
||||
|
||||
func TestDriverClickhouse_TableFields(t *testing.T) {
|
||||
connect := clickhouseConfigDB()
|
||||
gtest.AssertNil(createClickhouseExampleTable(connect))
|
||||
defer dropClickhouseExampleTable(connect)
|
||||
dataTypeTable, err := connect.TableFields(context.Background(), "data_type")
|
||||
gtest.AssertNil(err)
|
||||
gtest.AssertNE(dataTypeTable, nil)
|
||||
|
||||
var result = map[string][]interface{}{
|
||||
"Col1": {1, "Col1", "UInt8", false, "", "", "", "列1"},
|
||||
"Col2": {2, "Col2", "String", true, "", "", "", "列2"},
|
||||
"Col3": {3, "Col3", "FixedString(3)", false, "", "", "", "列3"},
|
||||
"Col4": {4, "Col4", "String", false, "", "", "", "列4"},
|
||||
"Col5": {5, "Col5", "Map(String, UInt8)", false, "", "", "", "列5"},
|
||||
"Col6": {6, "Col6", "Array(String)", false, "", "", "", "列6"},
|
||||
"Col7": {7, "Col7", "Tuple(String, UInt8, Array(Map(String, String)))", false, "", "", "", "列7"},
|
||||
"Col8": {8, "Col8", "DateTime", false, "", "", "", "列8"},
|
||||
"Col9": {9, "Col9", "UUID", false, "", "", "", "列9"},
|
||||
"Col10": {10, "Col10", "DateTime", false, "", "", "", "列10"},
|
||||
}
|
||||
for k, v := range result {
|
||||
_, ok := dataTypeTable[k]
|
||||
gtest.AssertEQ(ok, true)
|
||||
gtest.AssertEQ(dataTypeTable[k].Index, v[0])
|
||||
gtest.AssertEQ(dataTypeTable[k].Name, v[1])
|
||||
gtest.AssertEQ(dataTypeTable[k].Type, v[2])
|
||||
gtest.AssertEQ(dataTypeTable[k].Null, v[3])
|
||||
gtest.AssertEQ(dataTypeTable[k].Key, v[4])
|
||||
gtest.AssertEQ(dataTypeTable[k].Default, v[5])
|
||||
gtest.AssertEQ(dataTypeTable[k].Comment, v[7])
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,8 +3,13 @@ module github.com/gogf/gf/contrib/drivers/clickhouse/v2
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/ClickHouse/clickhouse-go v1.5.2
|
||||
github.com/ClickHouse/clickhouse-go/v2 v2.0.14
|
||||
github.com/gogf/gf/v2 v2.0.0
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||
)
|
||||
|
||||
replace github.com/gogf/gf/v2 => ../../../
|
||||
replace (
|
||||
github.com/ClickHouse/clickhouse-go/v2 => github.com/gogf/clickhouse-go/v2 v2.0.14-compatible
|
||||
github.com/gogf/gf/v2 => ../../../
|
||||
)
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I=
|
||||
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||
github.com/ClickHouse/clickhouse-go v1.5.2 h1:yXgaOZ8WEHrd+okvZXjzulSt1zS33nM4ujfx9lVncl8=
|
||||
github.com/ClickHouse/clickhouse-go v1.5.2/go.mod h1:EaI/sW7Azgz9UATzd5ZdZHRUhHgv5+JMS9NSr2smCJI=
|
||||
github.com/bkaradzic/go-lz4 v1.0.0 h1:RXc4wYsyz985CkXXeX04y4VnZFGG8Rd43pRaHsOXAKk=
|
||||
github.com/ClickHouse/clickhouse-go v1.5.4 h1:cKjXeYLNWVJIx2J1K6H2CqyRmfwVJVY1OV1coaaFcI0=
|
||||
github.com/ClickHouse/clickhouse-go v1.5.4/go.mod h1:EaI/sW7Azgz9UATzd5ZdZHRUhHgv5+JMS9NSr2smCJI=
|
||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
|
||||
github.com/bkaradzic/go-lz4 v1.0.0/go.mod h1:0YdlkowM3VswSROI7qDxhRvJ3sLhlFrRRwjwegp5jy4=
|
||||
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
|
||||
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
@ -11,7 +11,6 @@ github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5P
|
||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
||||
github.com/clbanning/mxj/v2 v2.5.5 h1:oT81vUeEiQQ/DcHbzSytRngP6Ky9O+L+0Bw0zSJag9E=
|
||||
github.com/clbanning/mxj/v2 v2.5.5/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s=
|
||||
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58 h1:F1EaeKL/ta07PY/k9Os/UFtwERei2/XzGemhpGnBKNg=
|
||||
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80=
|
||||
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=
|
||||
@ -29,10 +28,15 @@ github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
|
||||
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
|
||||
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
|
||||
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
|
||||
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
|
||||
github.com/gogf/clickhouse-go/v2 v2.0.14-compatible h1:eTT+USRgOZyTXyHyIFzJU+utFUsNVPmrzmQaKS9zdoM=
|
||||
github.com/gogf/clickhouse-go/v2 v2.0.14-compatible/go.mod h1:NdPxn4Kfffa6Tv14otrFtbV+zH6v2xHVfDf4KICt/0s=
|
||||
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
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=
|
||||
@ -50,6 +54,10 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
|
||||
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
|
||||
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
|
||||
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
||||
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/gorilla/handlers v1.4.2/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ=
|
||||
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0=
|
||||
@ -57,6 +65,8 @@ github.com/grokify/html-strip-tags-go v0.0.1/go.mod h1:2Su6romC5/1VXOQMaWL2yb618
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||
github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks=
|
||||
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo=
|
||||
github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
|
||||
@ -68,6 +78,7 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k
|
||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
||||
github.com/mkevac/debugcharts v0.0.0-20191222103121-ae1c48aa8615/go.mod h1:Ad7oeElCZqA1Ufj0U9/liOF4BtVepxRcTvr2ey7zTvM=
|
||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
|
||||
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
|
||||
@ -85,17 +96,32 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y
|
||||
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
|
||||
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
|
||||
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
|
||||
github.com/paulmach/orb v0.7.0 h1:l6uxkg+vRU9QJkBHtzvYpkVb09tCIRwnEHbY5MNMNqo=
|
||||
github.com/paulmach/orb v0.7.0/go.mod h1:FWRlTgl88VI1RBx/MkrwWDRhQ96ctqMCh8boXhmqB/A=
|
||||
github.com/paulmach/protoscan v0.2.1/go.mod h1:SpcSwydNLrxUGSDvXvO0P7g7AuhJ7lcKfDlhJCDw2gY=
|
||||
github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I=
|
||||
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
|
||||
github.com/pierrec/lz4/v4 v4.1.14 h1:+fL8AQEZtz/ijeNnpduH0bROTu0O3NZAlPjQxGn8LwE=
|
||||
github.com/pierrec/lz4/v4 v4.1.14/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
|
||||
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/shirou/gopsutil v2.19.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc=
|
||||
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
|
||||
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk=
|
||||
github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ=
|
||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
go.opentelemetry.io/otel v1.7.0 h1:Z2lA3Tdch0iDcrhJXDIlC94XE+bxok1F9B+4Lz/lGsM=
|
||||
go.opentelemetry.io/otel v1.7.0/go.mod h1:5BdUoMIz5WEs0vt0CUEMtSSaTSHBBVwrhnz7+nrD5xk=
|
||||
go.opentelemetry.io/otel/sdk v1.7.0 h1:4OmStpcKVOfvDOgCt7UriAPtKolwIhxpnSNI/yK+1B0=
|
||||
@ -105,11 +131,13 @@ go.opentelemetry.io/otel/trace v1.7.0/go.mod h1:fzLSB9nqR2eXzxPXb2JW9IKE+ScyXA48
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
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/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.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
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-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
|
||||
@ -118,15 +146,18 @@ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/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-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/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-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191220220014-0732a990476f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@ -138,8 +169,12 @@ golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0=
|
||||
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220429233432-b5fbb4746d32 h1:Js08h5hqB5xyWR789+QqueR6sDE8mk+YvpETZ+F6X9Y=
|
||||
golang.org/x/sys v0.0.0-20220429233432-b5fbb4746d32/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba h1:AyHWHCBVlIYI5rgEM3o+1PLd0sLPcIAoaUckGQMaWtw=
|
||||
golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
@ -148,7 +183,9 @@ golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 h1:GLw7MR8AfAG2GmGcmVgObF
|
||||
golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2/go.mod h1:EFNZuWvGYxIRUEX+K8UmCFwYmZjqcrnq15ZuVldZkZ0=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
|
||||
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=
|
||||
@ -162,8 +199,9 @@ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miE
|
||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
|
||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
|
||||
@ -13,14 +13,14 @@
|
||||
package mssql
|
||||
|
||||
import (
|
||||
_ "github.com/denisenkom/go-mssqldb"
|
||||
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
_ "github.com/denisenkom/go-mssqldb"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gmap"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
@ -299,6 +299,7 @@ ORDER BY a.id,a.colorder`,
|
||||
}
|
||||
fields = make(map[string]*gdb.TableField)
|
||||
for i, m := range result {
|
||||
|
||||
fields[m["Field"].String()] = &gdb.TableField{
|
||||
Index: i,
|
||||
Name: m["Field"].String(),
|
||||
|
||||
@ -63,32 +63,42 @@ func TestTableFields(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
createTable("t_user")
|
||||
defer dropTable("t_user")
|
||||
var expect map[string]string = map[string]string{
|
||||
"ID": "numeric(10,0)",
|
||||
"PASSPORT": "VARCHAR(45)",
|
||||
"PASSWORD": "CHAR(32)",
|
||||
"NICKNAME": "VARCHAR(45)",
|
||||
"CREATE_TIME": "time",
|
||||
var expect = map[string][]interface{}{
|
||||
"ID": {"numeric(10,0)", false, "PRI", "", "", ""},
|
||||
"PASSPORT": {"varchar(45)", true, "", "", "", ""},
|
||||
"PASSWORD": {"varchar(32)", true, "", "", "", ""},
|
||||
"NICKNAME": {"varchar(45)", true, "", "", "", ""},
|
||||
"CREATE_TIME": {"datetime", true, "", "", "", ""},
|
||||
}
|
||||
|
||||
res, err := db.TableFields(context.Background(), "t_user")
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
for k, _ := range expect {
|
||||
for k, v := range expect {
|
||||
_, ok := res[k]
|
||||
gtest.AssertEQ(ok, true)
|
||||
|
||||
gtest.AssertEQ(res[k].Name, k)
|
||||
gtest.AssertEQ(res[k].Type, v[0])
|
||||
gtest.AssertEQ(res[k].Null, v[1])
|
||||
gtest.AssertEQ(res[k].Key, v[2])
|
||||
gtest.AssertEQ(res[k].Default, v[3])
|
||||
gtest.AssertEQ(res[k].Extra, v[4])
|
||||
gtest.AssertEQ(res[k].Comment, v[5])
|
||||
}
|
||||
|
||||
res, err = db.TableFields(context.Background(), "t_user", "test")
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
for k, _ := range expect {
|
||||
for k, v := range expect {
|
||||
_, ok := res[k]
|
||||
gtest.AssertEQ(ok, true)
|
||||
|
||||
gtest.AssertEQ(res[k].Name, k)
|
||||
gtest.AssertEQ(res[k].Type, v[0])
|
||||
gtest.AssertEQ(res[k].Null, v[1])
|
||||
gtest.AssertEQ(res[k].Key, v[2])
|
||||
gtest.AssertEQ(res[k].Default, v[3])
|
||||
gtest.AssertEQ(res[k].Extra, v[4])
|
||||
gtest.AssertEQ(res[k].Comment, v[5])
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@ -13,6 +13,9 @@ import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gmap"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
@ -32,8 +35,15 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
if err := gdb.Register(`mysql`, New()); err != nil {
|
||||
panic(err)
|
||||
var (
|
||||
err error
|
||||
driverObj = New()
|
||||
driverNames = g.SliceStr{"mysql", "mariadb", "tidb"}
|
||||
)
|
||||
for _, driverName := range driverNames {
|
||||
if err = gdb.Register(driverName, driverObj); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -82,3 +82,27 @@ func Test_Model_InnerJoinOnField(t *testing.T) {
|
||||
t.Assert(r[1]["id"], "2")
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Model_FieldsPrefix(t *testing.T) {
|
||||
var (
|
||||
table1 = gtime.TimestampNanoStr() + "_table1"
|
||||
table2 = gtime.TimestampNanoStr() + "_table2"
|
||||
)
|
||||
createInitTable(table1)
|
||||
defer dropTable(table1)
|
||||
createInitTable(table2)
|
||||
defer dropTable(table2)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
r, err := db.Model(table1).
|
||||
FieldsPrefix(table1, "id").
|
||||
FieldsPrefix(table2, "nickname").
|
||||
LeftJoinOnField(table2, "id").
|
||||
WhereIn("id", g.Slice{1, 2}).
|
||||
Order("id asc").All()
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(r), 2)
|
||||
t.Assert(r[0]["id"], "1")
|
||||
t.Assert(r[0]["nickname"], "name_1")
|
||||
})
|
||||
}
|
||||
|
||||
@ -1,10 +1,36 @@
|
||||
module github.com/gogf/gf/contrib/drivers/oracle/v2
|
||||
|
||||
go 1.15
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.0.0
|
||||
github.com/mattn/go-oci8 v0.1.1
|
||||
github.com/sijms/go-ora/v2 v2.4.20
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.1.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||
github.com/clbanning/mxj/v2 v2.5.5 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/fatih/color v1.13.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.5.4 // indirect
|
||||
github.com/go-logr/logr v1.2.3 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/go-redis/redis/v8 v8.11.5 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/grokify/html-strip-tags-go v0.0.1 // indirect
|
||||
github.com/magiconair/properties v1.8.6 // indirect
|
||||
github.com/mattn/go-colorable v0.1.9 // indirect
|
||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.9 // indirect
|
||||
github.com/olekukonko/tablewriter v0.0.5 // indirect
|
||||
go.opentelemetry.io/otel v1.7.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk v1.7.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.7.0 // indirect
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
|
||||
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
|
||||
golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
|
||||
)
|
||||
|
||||
replace github.com/gogf/gf/v2 => ../../../
|
||||
|
||||
@ -34,7 +34,6 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W
|
||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||
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.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
@ -56,8 +55,6 @@ github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
github.com/mattn/go-oci8 v0.1.1 h1:aEUDxNAyDG0tv8CA3TArnDQNyc4EhnWlsfxRgDHABHM=
|
||||
github.com/mattn/go-oci8 v0.1.1/go.mod h1:wjDx6Xm9q7dFtHJvIlrI99JytznLw5wQ4R+9mNXJwGI=
|
||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||
@ -70,7 +67,6 @@ github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108
|
||||
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
|
||||
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
|
||||
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
|
||||
github.com/onsi/ginkgo/v2 v2.0.0 h1:CcuG/HvWNkkaqCUpJifQY8z7qEMBJya6aLPx6ftGyjQ=
|
||||
github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
|
||||
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||
@ -79,6 +75,8 @@ github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
|
||||
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
|
||||
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/sijms/go-ora/v2 v2.4.20 h1:9e3z7VLBQXRAHGiIda1GEFtRhfxata0LghyMZqvLKew=
|
||||
github.com/sijms/go-ora/v2 v2.4.20/go.mod h1:EHxlY6x7y9HAsdfumurRfTd+v8NrEOTR3Xl4FWlH6xk=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
|
||||
@ -142,7 +140,6 @@ golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
|
||||
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=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
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=
|
||||
@ -151,7 +148,6 @@ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miE
|
||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
//
|
||||
// Note:
|
||||
// 1. It needs manually import: _ "github.com/mattn/go-oci8"
|
||||
// 1. It needs manually import: _ "github.com/sijms/go-ora/v2"
|
||||
// 2. It does not support Save/Replace features.
|
||||
// 3. It does not support LastInsertId.
|
||||
|
||||
@ -13,15 +13,10 @@
|
||||
package oracle
|
||||
|
||||
import (
|
||||
_ "github.com/mattn/go-oci8"
|
||||
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
gora "github.com/sijms/go-ora/v2"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gmap"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
@ -30,6 +25,8 @@ import (
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Driver is the driver for oracle database.
|
||||
@ -65,9 +62,18 @@ func (d *Driver) New(core *gdb.Core, node *gdb.ConfigNode) (gdb.DB, error) {
|
||||
func (d *Driver) Open(config *gdb.ConfigNode) (db *sql.DB, err error) {
|
||||
var (
|
||||
source string
|
||||
underlyingDriverName = "oci8"
|
||||
underlyingDriverName = "oracle"
|
||||
)
|
||||
// [username/[password]@]host[:port][/service_name][?param1=value1&...¶mN=valueN]
|
||||
|
||||
options := map[string]string{
|
||||
"CONNECTION TIMEOUT": "60",
|
||||
"PREFETCH_ROWS": "25",
|
||||
}
|
||||
|
||||
if config.Debug {
|
||||
options["TRACE FILE"] = "oracle_trace.log"
|
||||
}
|
||||
// [username:[password]@]host[:port][/service_name][?param1=value1&...¶mN=valueN]
|
||||
if config.Link != "" {
|
||||
source = config.Link
|
||||
// Custom changing the schema in runtime.
|
||||
@ -75,10 +81,7 @@ func (d *Driver) Open(config *gdb.ConfigNode) (db *sql.DB, err error) {
|
||||
source, _ = gregex.ReplaceString(`@(.+?)/([\w\.\-]+)+`, "@$1/"+config.Name, source)
|
||||
}
|
||||
} else {
|
||||
source = fmt.Sprintf(
|
||||
"%s/%s@%s:%s/%s",
|
||||
config.User, config.Pass, config.Host, config.Port, config.Name,
|
||||
)
|
||||
source = gora.BuildUrl(config.Host, gconv.Int(config.Port), config.Name, config.User, config.Pass, options)
|
||||
}
|
||||
|
||||
if db, err = sql.Open(underlyingDriverName, source); err != nil {
|
||||
@ -99,8 +102,8 @@ func (d *Driver) FilteredLink() string {
|
||||
return ""
|
||||
}
|
||||
s, _ := gregex.ReplaceString(
|
||||
`(.+?)\s*/\s*(.+)\s*@\s*(.+)\s*:\s*(\d+)\s*/\s*(.+)`,
|
||||
`$1/xxx@$3:$4/$5`,
|
||||
`(.+?)\s*:\s*(.+)\s*@\s*(.+)\s*:\s*(\d+)\s*/\s*(.+)`,
|
||||
`$1:xxx@$3:$4/$5`,
|
||||
linkInfo,
|
||||
)
|
||||
return s
|
||||
@ -124,16 +127,7 @@ func (d *Driver) DoFilter(ctx context.Context, link gdb.Link, sql string, args [
|
||||
return fmt.Sprintf(":v%d", index)
|
||||
})
|
||||
newSql, _ = gregex.ReplaceString("\"", "", newSql)
|
||||
// Handle string datetime argument.
|
||||
for i, v := range args {
|
||||
if reflect.TypeOf(v).Kind() == reflect.String {
|
||||
valueStr := gconv.String(v)
|
||||
if gregex.IsMatchString(`^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$`, valueStr) {
|
||||
// args[i] = fmt.Sprintf(`TO_DATE('%s','yyyy-MM-dd HH:MI:SS')`, valueStr)
|
||||
args[i], _ = time.ParseInLocation("2006-01-02 15:04:05", valueStr, time.Local)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
newSql = d.parseSql(newSql)
|
||||
newArgs = args
|
||||
return
|
||||
@ -168,7 +162,7 @@ func (d *Driver) parseSql(sql string) string {
|
||||
strings.EqualFold(queryExpr[3], "LIMIT") == false {
|
||||
break
|
||||
}
|
||||
first, limit := 0, 0
|
||||
page, limit := 0, 0
|
||||
for i := 1; i < len(allMatch[index]); i++ {
|
||||
if len(strings.TrimSpace(allMatch[index][i])) == 0 {
|
||||
continue
|
||||
@ -176,8 +170,16 @@ func (d *Driver) parseSql(sql string) string {
|
||||
|
||||
if strings.HasPrefix(allMatch[index][i], "LIMIT") {
|
||||
if allMatch[index][i+2] != "" {
|
||||
first, _ = strconv.Atoi(allMatch[index][i+1])
|
||||
page, _ = strconv.Atoi(allMatch[index][i+1])
|
||||
limit, _ = strconv.Atoi(allMatch[index][i+2])
|
||||
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
|
||||
limit = (page/limit + 1) * limit
|
||||
|
||||
page, _ = strconv.Atoi(allMatch[index][i+1])
|
||||
} else {
|
||||
limit, _ = strconv.Atoi(allMatch[index][i+1])
|
||||
}
|
||||
@ -187,8 +189,8 @@ func (d *Driver) parseSql(sql string) string {
|
||||
sql = fmt.Sprintf(
|
||||
"SELECT * FROM "+
|
||||
"(SELECT GFORM.*, ROWNUM ROWNUM_ FROM (%s %s) GFORM WHERE ROWNUM <= %d)"+
|
||||
" WHERE ROWNUM_ >= %d",
|
||||
queryExpr[1], queryExpr[2], limit, first,
|
||||
" WHERE ROWNUM_ > %d",
|
||||
queryExpr[1], queryExpr[2], limit, page,
|
||||
)
|
||||
}
|
||||
return sql
|
||||
@ -241,7 +243,7 @@ SELECT
|
||||
CASE DATA_TYPE
|
||||
WHEN 'NUMBER' THEN DATA_TYPE||'('||DATA_PRECISION||','||DATA_SCALE||')'
|
||||
WHEN 'FLOAT' THEN DATA_TYPE||'('||DATA_PRECISION||','||DATA_SCALE||')'
|
||||
ELSE DATA_TYPE||'('||DATA_LENGTH||')' END AS TYPE
|
||||
ELSE DATA_TYPE||'('||DATA_LENGTH||')' END AS TYPE,NULLABLE
|
||||
FROM USER_TAB_COLUMNS WHERE TABLE_NAME = '%s' ORDER BY COLUMN_ID`,
|
||||
strings.ToUpper(table),
|
||||
)
|
||||
@ -256,10 +258,16 @@ FROM USER_TAB_COLUMNS WHERE TABLE_NAME = '%s' ORDER BY COLUMN_ID`,
|
||||
}
|
||||
fields = make(map[string]*gdb.TableField)
|
||||
for i, m := range result {
|
||||
fields[strings.ToLower(m["FIELD"].String())] = &gdb.TableField{
|
||||
isNull := false
|
||||
if m["NULLABLE"].String() == "Y" {
|
||||
isNull = true
|
||||
}
|
||||
|
||||
fields[m["FIELD"].String()] = &gdb.TableField{
|
||||
Index: i,
|
||||
Name: strings.ToLower(m["FIELD"].String()),
|
||||
Type: strings.ToLower(m["TYPE"].String()),
|
||||
Name: m["FIELD"].String(),
|
||||
Type: m["TYPE"].String(),
|
||||
Null: isNull,
|
||||
}
|
||||
}
|
||||
return fields
|
||||
@ -288,10 +296,10 @@ func (d *Driver) DoInsert(
|
||||
) (result sql.Result, err error) {
|
||||
switch option.InsertOption {
|
||||
case gdb.InsertOptionSave:
|
||||
return nil, gerror.NewCode(gcode.CodeNotSupported, `Save operation is not supported by mssql driver`)
|
||||
return nil, gerror.NewCode(gcode.CodeNotSupported, `Save operation is not supported by oracle driver`)
|
||||
|
||||
case gdb.InsertOptionReplace:
|
||||
return nil, gerror.NewCode(gcode.CodeNotSupported, `Replace operation is not supported by mssql driver`)
|
||||
return nil, gerror.NewCode(gcode.CodeNotSupported, `Replace operation is not supported by oracle driver`)
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
162
contrib/drivers/oracle/oracle_init_test.go
Normal file
162
contrib/drivers/oracle/oracle_init_test.go
Normal file
@ -0,0 +1,162 @@
|
||||
// Copyright 2019 gf Author(https://github.com/gogf/gf). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package oracle_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/container/garray"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
_ "github.com/sijms/go-ora/v2"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
db gdb.DB
|
||||
dblink gdb.DB
|
||||
dbErr gdb.DB
|
||||
ctx context.Context
|
||||
)
|
||||
|
||||
const (
|
||||
TableSize = 10
|
||||
TableName = "t_user"
|
||||
TestSchema1 = "test1"
|
||||
TestSchema2 = "test2"
|
||||
TableNamePrefix1 = "gf_"
|
||||
TestSchema = "XE"
|
||||
)
|
||||
|
||||
const (
|
||||
TestDbIP = "127.0.0.1"
|
||||
TestDbPort = "1521"
|
||||
TestDbUser = "system"
|
||||
TestDbPass = "oracle"
|
||||
TestDbName = "XE"
|
||||
TestDbType = "oracle"
|
||||
)
|
||||
|
||||
func init() {
|
||||
node := gdb.ConfigNode{
|
||||
Host: TestDbIP,
|
||||
Port: TestDbPort,
|
||||
User: TestDbUser,
|
||||
Pass: TestDbPass,
|
||||
Name: TestDbName,
|
||||
Type: TestDbType,
|
||||
Role: "master",
|
||||
Charset: "utf8",
|
||||
Weight: 1,
|
||||
MaxIdleConnCount: 10,
|
||||
MaxOpenConnCount: 10,
|
||||
}
|
||||
|
||||
nodeLink := gdb.ConfigNode{
|
||||
Type: TestDbType,
|
||||
Name: TestDbName,
|
||||
Link: fmt.Sprintf("%s://%s:%s@%s:%s/%s",
|
||||
TestDbType, TestDbUser, TestDbPass, TestDbIP, TestDbPort, TestDbName),
|
||||
}
|
||||
|
||||
nodeErr := gdb.ConfigNode{
|
||||
Host: TestDbIP,
|
||||
Port: TestDbPort,
|
||||
User: TestDbUser,
|
||||
Pass: "1234",
|
||||
Name: TestDbName,
|
||||
Type: TestDbType,
|
||||
Role: "master",
|
||||
Charset: "utf8",
|
||||
Weight: 1,
|
||||
}
|
||||
|
||||
gdb.AddConfigNode(gdb.DefaultGroupName, node)
|
||||
if r, err := gdb.New(node); err != nil {
|
||||
gtest.Fatal(err)
|
||||
} else {
|
||||
db = r
|
||||
}
|
||||
|
||||
gdb.AddConfigNode("dblink", nodeLink)
|
||||
if r, err := gdb.New(nodeLink); err != nil {
|
||||
gtest.Fatal(err)
|
||||
} else {
|
||||
dblink = r
|
||||
}
|
||||
|
||||
gdb.AddConfigNode("dbErr", nodeErr)
|
||||
if r, err := gdb.New(nodeErr); err != nil {
|
||||
gtest.Fatal(err)
|
||||
} else {
|
||||
dbErr = r
|
||||
}
|
||||
|
||||
ctx = context.Background()
|
||||
}
|
||||
|
||||
func createTable(table ...string) (name string) {
|
||||
if len(table) > 0 {
|
||||
name = table[0]
|
||||
} else {
|
||||
name = fmt.Sprintf("user_%d", gtime.Timestamp())
|
||||
}
|
||||
|
||||
dropTable(name)
|
||||
|
||||
if _, err := db.Exec(ctx, fmt.Sprintf(`
|
||||
CREATE TABLE %s (
|
||||
ID NUMBER(10) NOT NULL,
|
||||
PASSPORT VARCHAR(45) NOT NULL,
|
||||
PASSWORD CHAR(32) NOT NULL,
|
||||
NICKNAME VARCHAR(45) NOT NULL,
|
||||
CREATE_TIME varchar(45),
|
||||
PRIMARY KEY (ID))
|
||||
`, name)); err != nil {
|
||||
gtest.Fatal(err)
|
||||
}
|
||||
|
||||
//db.Schema("test")
|
||||
return
|
||||
}
|
||||
|
||||
func createInitTable(table ...string) (name string) {
|
||||
name = createTable(table...)
|
||||
array := garray.New(true)
|
||||
for i := 1; i <= TableSize; i++ {
|
||||
array.Append(g.Map{
|
||||
"id": i,
|
||||
"passport": fmt.Sprintf(`user_%d`, i),
|
||||
"password": fmt.Sprintf(`pass_%d`, i),
|
||||
"nickname": fmt.Sprintf(`name_%d`, i),
|
||||
"create_time": gtime.Now().String(),
|
||||
})
|
||||
}
|
||||
result, err := db.Insert(context.Background(), name, array.Slice())
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
n, e := result.RowsAffected()
|
||||
gtest.Assert(e, nil)
|
||||
gtest.Assert(n, TableSize)
|
||||
return
|
||||
}
|
||||
|
||||
func dropTable(table string) {
|
||||
count, err := db.GetCount(ctx, "SELECT COUNT(*) FROM USER_TABLES WHERE TABLE_NAME = ?", strings.ToUpper(table))
|
||||
if err != nil {
|
||||
gtest.Fatal(err)
|
||||
}
|
||||
|
||||
if count == 0 {
|
||||
return
|
||||
}
|
||||
if _, err := db.Exec(ctx, fmt.Sprintf("DROP TABLE %s", table)); err != nil {
|
||||
gtest.Fatal(err)
|
||||
}
|
||||
}
|
||||
665
contrib/drivers/oracle/oracle_z_basic_test.go
Normal file
665
contrib/drivers/oracle/oracle_z_basic_test.go
Normal file
@ -0,0 +1,665 @@
|
||||
// Copyright 2019 gf Author(https://github.com/gogf/gf). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package oracle_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTables(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
tables := []string{"t_user1", "pop", "haha"}
|
||||
|
||||
for _, v := range tables {
|
||||
createTable(v)
|
||||
}
|
||||
|
||||
result, err := db.Tables(ctx)
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
for i := 0; i < len(tables); i++ {
|
||||
find := false
|
||||
for j := 0; j < len(result); j++ {
|
||||
if strings.ToUpper(tables[i]) == result[j] {
|
||||
find = true
|
||||
break
|
||||
}
|
||||
}
|
||||
gtest.AssertEQ(find, true)
|
||||
}
|
||||
|
||||
result, err = db.Tables(ctx, TestSchema)
|
||||
gtest.Assert(err, nil)
|
||||
for i := 0; i < len(tables); i++ {
|
||||
find := false
|
||||
for j := 0; j < len(result); j++ {
|
||||
if strings.ToUpper(tables[i]) == result[j] {
|
||||
find = true
|
||||
break
|
||||
}
|
||||
}
|
||||
gtest.AssertEQ(find, true)
|
||||
}
|
||||
|
||||
for _, v := range tables {
|
||||
dropTable(v)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestTableFields(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
createTable("t_user")
|
||||
defer dropTable("t_user")
|
||||
var expect = map[string][]interface{}{
|
||||
"ID": {"NUMBER(10,0)", false},
|
||||
"PASSPORT": {"VARCHAR2(45)", false},
|
||||
"PASSWORD": {"CHAR(32)", false},
|
||||
"NICKNAME": {"VARCHAR2(45)", false},
|
||||
"CREATE_TIME": {"VARCHAR2(45)", true},
|
||||
}
|
||||
|
||||
_, err := dbErr.TableFields(ctx, "t_user")
|
||||
gtest.AssertNE(err, nil)
|
||||
|
||||
res, err := db.TableFields(ctx, "t_user")
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
for k, v := range expect {
|
||||
_, ok := res[k]
|
||||
gtest.AssertEQ(ok, true)
|
||||
|
||||
gtest.AssertEQ(res[k].Name, k)
|
||||
gtest.Assert(res[k].Type, v[0])
|
||||
gtest.Assert(res[k].Null, v[1])
|
||||
}
|
||||
|
||||
res, err = db.TableFields(ctx, "t_user", TestSchema)
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
for k, v := range expect {
|
||||
_, ok := res[k]
|
||||
gtest.AssertEQ(ok, true)
|
||||
|
||||
gtest.AssertEQ(res[k].Name, k)
|
||||
gtest.Assert(res[k].Type, v[0])
|
||||
gtest.Assert(res[k].Null, v[1])
|
||||
}
|
||||
})
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
_, err := db.TableFields(ctx, "t_user t_user2")
|
||||
gtest.AssertNE(err, nil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestFilteredLink(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
s := dblink.FilteredLink()
|
||||
gtest.AssertEQ(s, "oracle:xxx@127.0.0.1:1521/XE")
|
||||
})
|
||||
|
||||
}
|
||||
func TestDoInsert(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
createTable("t_user")
|
||||
defer dropTable("t_user")
|
||||
|
||||
i := 10
|
||||
data := g.Map{
|
||||
"ID": i,
|
||||
"PASSPORT": fmt.Sprintf(`t%d`, i),
|
||||
"PASSWORD": fmt.Sprintf(`p%d`, i),
|
||||
"NICKNAME": fmt.Sprintf(`T%d`, i),
|
||||
"CREATE_TIME": gtime.Now().String(),
|
||||
}
|
||||
_, err := db.Insert(ctx, "t_user", data)
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
})
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
createTable("t_user")
|
||||
defer dropTable("t_user")
|
||||
|
||||
i := 10
|
||||
data := g.Map{
|
||||
"ID": i,
|
||||
"PASSPORT": fmt.Sprintf(`t%d`, i),
|
||||
"PASSWORD": fmt.Sprintf(`p%d`, i),
|
||||
"NICKNAME": fmt.Sprintf(`T%d`, i),
|
||||
"CREATE_TIME": gtime.Now().String(),
|
||||
}
|
||||
_, err := db.Save(ctx, "t_user", data, 10)
|
||||
gtest.AssertNE(err, nil)
|
||||
|
||||
_, err = db.Replace(ctx, "t_user", data, 10)
|
||||
gtest.AssertNE(err, nil)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_DB_Ping(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
err1 := db.PingMaster()
|
||||
err2 := db.PingSlave()
|
||||
t.Assert(err1, nil)
|
||||
t.Assert(err2, nil)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_DB_Query(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
_, err := db.Query(ctx, "SELECT ? from dual", 1)
|
||||
t.AssertNil(err)
|
||||
|
||||
_, err = db.Query(ctx, "SELECT ?+? from dual", 1, 2)
|
||||
t.AssertNil(err)
|
||||
|
||||
_, err = db.Query(ctx, "SELECT ?+? from dual", g.Slice{1, 2})
|
||||
t.AssertNil(err)
|
||||
|
||||
_, err = db.Query(ctx, "ERROR")
|
||||
t.AssertNE(err, nil)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_DB_Exec(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
_, err := db.Exec(ctx, "SELECT ? from dual", 1)
|
||||
t.AssertNil(err)
|
||||
|
||||
_, err = db.Exec(ctx, "ERROR")
|
||||
t.AssertNE(err, nil)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_DB_Insert(t *testing.T) {
|
||||
table := createTable()
|
||||
defer dropTable(table)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
_, err := db.Insert(ctx, table, g.Map{
|
||||
"ID": 1,
|
||||
"PASSPORT": "t1",
|
||||
"PASSWORD": "25d55ad283aa400af464c76d713c07ad",
|
||||
"NICKNAME": "T1",
|
||||
"CREATE_TIME": gtime.Now().String(),
|
||||
})
|
||||
t.AssertNil(err)
|
||||
|
||||
// normal map
|
||||
result, err := db.Insert(ctx, table, g.Map{
|
||||
"ID": "2",
|
||||
"PASSPORT": "t2",
|
||||
"PASSWORD": "25d55ad283aa400af464c76d713c07ad",
|
||||
"NICKNAME": "name_2",
|
||||
"CREATE_TIME": gtime.Now().String(),
|
||||
})
|
||||
t.AssertNil(err)
|
||||
n, _ := result.RowsAffected()
|
||||
t.Assert(n, 1)
|
||||
|
||||
// struct
|
||||
type User struct {
|
||||
Id int `gconv:"ID"`
|
||||
Passport string `json:"PASSPORT"`
|
||||
Password string `gconv:"PASSWORD"`
|
||||
Nickname string `gconv:"NICKNAME"`
|
||||
CreateTime string `json:"CREATE_TIME"`
|
||||
}
|
||||
timeStr := gtime.Now().String()
|
||||
result, err = db.Insert(ctx, table, User{
|
||||
Id: 3,
|
||||
Passport: "user_3",
|
||||
Password: "25d55ad283aa400af464c76d713c07ad",
|
||||
Nickname: "name_3",
|
||||
CreateTime: timeStr,
|
||||
})
|
||||
t.AssertNil(err)
|
||||
n, _ = result.RowsAffected()
|
||||
t.Assert(n, 1)
|
||||
|
||||
one, err := db.Model(table).Where("ID", 3).One()
|
||||
t.AssertNil(err)
|
||||
fmt.Println(one)
|
||||
t.Assert(one["ID"].Int(), 3)
|
||||
t.Assert(one["PASSPORT"].String(), "user_3")
|
||||
t.Assert(one["PASSWORD"].String(), "25d55ad283aa400af464c76d713c07ad")
|
||||
t.Assert(one["NICKNAME"].String(), "name_3")
|
||||
t.Assert(one["CREATE_TIME"].GTime().String(), timeStr)
|
||||
|
||||
// *struct
|
||||
timeStr = gtime.Now().String()
|
||||
result, err = db.Insert(ctx, table, &User{
|
||||
Id: 4,
|
||||
Passport: "t4",
|
||||
Password: "25d55ad283aa400af464c76d713c07ad",
|
||||
Nickname: "name_4",
|
||||
CreateTime: timeStr,
|
||||
})
|
||||
t.AssertNil(err)
|
||||
n, _ = result.RowsAffected()
|
||||
t.Assert(n, 1)
|
||||
|
||||
one, err = db.Model(table).Where("ID", 4).One()
|
||||
t.AssertNil(err)
|
||||
t.Assert(one["ID"].Int(), 4)
|
||||
t.Assert(one["PASSPORT"].String(), "t4")
|
||||
t.Assert(one["PASSWORD"].String(), "25d55ad283aa400af464c76d713c07ad")
|
||||
t.Assert(one["NICKNAME"].String(), "name_4")
|
||||
t.Assert(one["CREATE_TIME"].GTime().String(), timeStr)
|
||||
|
||||
// batch with Insert
|
||||
timeStr = gtime.Now().String()
|
||||
r, err := db.Insert(ctx, table, g.Slice{
|
||||
g.Map{
|
||||
"ID": 200,
|
||||
"PASSPORT": "t200",
|
||||
"PASSWORD": "25d55ad283aa400af464c76d71qw07ad",
|
||||
"NICKNAME": "T200",
|
||||
"CREATE_TIME": timeStr,
|
||||
},
|
||||
g.Map{
|
||||
"ID": 300,
|
||||
"PASSPORT": "t300",
|
||||
"PASSWORD": "25d55ad283aa400af464c76d713c07ad",
|
||||
"NICKNAME": "T300",
|
||||
"CREATE_TIME": timeStr,
|
||||
},
|
||||
})
|
||||
t.AssertNil(err)
|
||||
n, _ = r.RowsAffected()
|
||||
t.Assert(n, 2)
|
||||
|
||||
one, err = db.Model(table).Where("ID", 200).One()
|
||||
t.AssertNil(err)
|
||||
t.Assert(one["ID"].Int(), 200)
|
||||
t.Assert(one["PASSPORT"].String(), "t200")
|
||||
t.Assert(one["PASSWORD"].String(), "25d55ad283aa400af464c76d71qw07ad")
|
||||
t.Assert(one["NICKNAME"].String(), "T200")
|
||||
t.Assert(one["CREATE_TIME"].GTime().String(), timeStr)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_DB_BatchInsert(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
table := createTable()
|
||||
defer dropTable(table)
|
||||
r, err := db.Insert(ctx, table, g.List{
|
||||
{
|
||||
"ID": 2,
|
||||
"PASSPORT": "t2",
|
||||
"PASSWORD": "25d55ad283aa400af464c76d713c07ad",
|
||||
"NICKNAME": "name_2",
|
||||
"CREATE_TIME": gtime.Now().String(),
|
||||
},
|
||||
{
|
||||
"ID": 3,
|
||||
"PASSPORT": "user_3",
|
||||
"PASSWORD": "25d55ad283aa400af464c76d713c07ad",
|
||||
"NICKNAME": "name_3",
|
||||
"CREATE_TIME": gtime.Now().String(),
|
||||
},
|
||||
}, 1)
|
||||
t.AssertNil(err)
|
||||
n, _ := r.RowsAffected()
|
||||
t.Assert(n, 2)
|
||||
|
||||
})
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
table := createTable()
|
||||
defer dropTable(table)
|
||||
// []interface{}
|
||||
r, err := db.Insert(ctx, table, g.Slice{
|
||||
g.Map{
|
||||
"ID": 2,
|
||||
"PASSPORT": "t2",
|
||||
"PASSWORD": "25d55ad283aa400af464c76d713c07ad",
|
||||
"NICKNAME": "name_2",
|
||||
"CREATE_TIME": gtime.Now().String(),
|
||||
},
|
||||
g.Map{
|
||||
"ID": 3,
|
||||
"PASSPORT": "user_3",
|
||||
"PASSWORD": "25d55ad283aa400af464c76d713c07ad",
|
||||
"NICKNAME": "name_3",
|
||||
"CREATE_TIME": gtime.Now().String(),
|
||||
},
|
||||
}, 1)
|
||||
t.AssertNil(err)
|
||||
n, _ := r.RowsAffected()
|
||||
t.Assert(n, 2)
|
||||
})
|
||||
|
||||
// batch insert map
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
table := createTable()
|
||||
defer dropTable(table)
|
||||
result, err := db.Insert(ctx, table, g.Map{
|
||||
"ID": 1,
|
||||
"PASSPORT": "t1",
|
||||
"PASSWORD": "p1",
|
||||
"NICKNAME": "T1",
|
||||
"CREATE_TIME": gtime.Now().String(),
|
||||
})
|
||||
t.AssertNil(err)
|
||||
n, _ := result.RowsAffected()
|
||||
t.Assert(n, 1)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_DB_BatchInsert_Struct(t *testing.T) {
|
||||
// batch insert struct
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
table := createTable()
|
||||
defer dropTable(table)
|
||||
|
||||
type User struct {
|
||||
Id int `c:"ID"`
|
||||
Passport string `c:"PASSPORT"`
|
||||
Password string `c:"PASSWORD"`
|
||||
NickName string `c:"NICKNAME"`
|
||||
CreateTime *gtime.Time `c:"CREATE_TIME"`
|
||||
}
|
||||
user := &User{
|
||||
Id: 1,
|
||||
Passport: "t1",
|
||||
Password: "p1",
|
||||
NickName: "T1",
|
||||
CreateTime: gtime.Now(),
|
||||
}
|
||||
result, err := db.Insert(ctx, table, user)
|
||||
t.AssertNil(err)
|
||||
n, _ := result.RowsAffected()
|
||||
t.Assert(n, 1)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_DB_Update(t *testing.T) {
|
||||
table := createInitTable()
|
||||
defer dropTable(table)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
result, err := db.Update(ctx, table, "password='987654321'", "id=3")
|
||||
t.AssertNil(err)
|
||||
n, _ := result.RowsAffected()
|
||||
t.Assert(n, 1)
|
||||
|
||||
one, err := db.Model(table).Where("ID", 3).One()
|
||||
t.AssertNil(err)
|
||||
t.Assert(one["ID"].Int(), 3)
|
||||
t.Assert(one["PASSPORT"].String(), "user_3")
|
||||
t.Assert(strings.TrimSpace(one["PASSWORD"].String()), "987654321")
|
||||
t.Assert(one["NICKNAME"].String(), "name_3")
|
||||
})
|
||||
}
|
||||
|
||||
func Test_DB_GetAll(t *testing.T) {
|
||||
table := createInitTable()
|
||||
defer dropTable(table)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
result, err := db.GetAll(ctx, fmt.Sprintf("SELECT * FROM %s WHERE id=?", table), 1)
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(result), 1)
|
||||
t.Assert(result[0]["ID"].Int(), 1)
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
result, err := db.GetAll(ctx, fmt.Sprintf("SELECT * FROM %s WHERE id=?", table), g.Slice{1})
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(result), 1)
|
||||
t.Assert(result[0]["ID"].Int(), 1)
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
result, err := db.GetAll(ctx, fmt.Sprintf("SELECT * FROM %s WHERE id in(?)", table), g.Slice{1, 2, 3})
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(result), 3)
|
||||
t.Assert(result[0]["ID"].Int(), 1)
|
||||
t.Assert(result[1]["ID"].Int(), 2)
|
||||
t.Assert(result[2]["ID"].Int(), 3)
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
result, err := db.GetAll(ctx, fmt.Sprintf("SELECT * FROM %s WHERE id in(?,?,?)", table), g.Slice{1, 2, 3})
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(result), 3)
|
||||
t.Assert(result[0]["ID"].Int(), 1)
|
||||
t.Assert(result[1]["ID"].Int(), 2)
|
||||
t.Assert(result[2]["ID"].Int(), 3)
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
result, err := db.GetAll(ctx, fmt.Sprintf("SELECT * FROM %s WHERE id in(?,?,?)", table), g.Slice{1, 2, 3}...)
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(result), 3)
|
||||
t.Assert(result[0]["ID"].Int(), 1)
|
||||
t.Assert(result[1]["ID"].Int(), 2)
|
||||
t.Assert(result[2]["ID"].Int(), 3)
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
result, err := db.GetAll(ctx, fmt.Sprintf("SELECT * FROM %s WHERE id>=? AND id <=?", table), g.Slice{1, 3})
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(result), 3)
|
||||
t.Assert(result[0]["ID"].Int(), 1)
|
||||
t.Assert(result[1]["ID"].Int(), 2)
|
||||
t.Assert(result[2]["ID"].Int(), 3)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_DB_GetOne(t *testing.T) {
|
||||
table := createInitTable()
|
||||
defer dropTable(table)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
record, err := db.GetOne(ctx, fmt.Sprintf("SELECT * FROM %s WHERE passport=?", table), "user_1")
|
||||
t.AssertNil(err)
|
||||
t.Assert(record["NICKNAME"].String(), "name_1")
|
||||
})
|
||||
}
|
||||
|
||||
func Test_DB_GetValue(t *testing.T) {
|
||||
table := createInitTable()
|
||||
defer dropTable(table)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
value, err := db.GetValue(ctx, fmt.Sprintf("SELECT id FROM %s WHERE passport=?", table), "user_3")
|
||||
t.AssertNil(err)
|
||||
t.Assert(value.Int(), 3)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_DB_GetCount(t *testing.T) {
|
||||
table := createInitTable()
|
||||
defer dropTable(table)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
count, err := db.GetCount(ctx, fmt.Sprintf("SELECT * FROM %s", table))
|
||||
t.AssertNil(err)
|
||||
t.Assert(count, TableSize)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_DB_GetStruct(t *testing.T) {
|
||||
table := createInitTable()
|
||||
defer dropTable(table)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
type User struct {
|
||||
Id int
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
CreateTime gtime.Time
|
||||
}
|
||||
user := new(User)
|
||||
err := db.GetScan(ctx, user, fmt.Sprintf("SELECT * FROM %s WHERE id=?", table), 3)
|
||||
t.AssertNil(err)
|
||||
t.Assert(user.NickName, "name_3")
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
type User struct {
|
||||
Id int
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
CreateTime *gtime.Time
|
||||
}
|
||||
user := new(User)
|
||||
err := db.GetScan(ctx, user, fmt.Sprintf("SELECT * FROM %s WHERE id=?", table), 3)
|
||||
t.AssertNil(err)
|
||||
t.Assert(user.NickName, "name_3")
|
||||
})
|
||||
}
|
||||
|
||||
func Test_DB_GetStructs(t *testing.T) {
|
||||
table := createInitTable()
|
||||
defer dropTable(table)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
type User struct {
|
||||
Id int
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
CreateTime gtime.Time
|
||||
}
|
||||
var users []User
|
||||
err := db.GetScan(ctx, &users, fmt.Sprintf("SELECT * FROM %s WHERE id>?", table), 1)
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(users), TableSize-1)
|
||||
t.Assert(users[0].Id, 2)
|
||||
t.Assert(users[1].Id, 3)
|
||||
t.Assert(users[2].Id, 4)
|
||||
t.Assert(users[0].NickName, "name_2")
|
||||
t.Assert(users[1].NickName, "name_3")
|
||||
t.Assert(users[2].NickName, "name_4")
|
||||
})
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
type User struct {
|
||||
Id int
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
CreateTime *gtime.Time
|
||||
}
|
||||
var users []User
|
||||
err := db.GetScan(ctx, &users, fmt.Sprintf("SELECT * FROM %s WHERE id>?", table), 1)
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(users), TableSize-1)
|
||||
t.Assert(users[0].Id, 2)
|
||||
t.Assert(users[1].Id, 3)
|
||||
t.Assert(users[2].Id, 4)
|
||||
t.Assert(users[0].NickName, "name_2")
|
||||
t.Assert(users[1].NickName, "name_3")
|
||||
t.Assert(users[2].NickName, "name_4")
|
||||
})
|
||||
}
|
||||
|
||||
func Test_DB_GetScan(t *testing.T) {
|
||||
table := createInitTable()
|
||||
defer dropTable(table)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
type User struct {
|
||||
Id int
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
CreateTime gtime.Time
|
||||
}
|
||||
user := new(User)
|
||||
err := db.GetScan(ctx, user, fmt.Sprintf("SELECT * FROM %s WHERE id=?", table), 3)
|
||||
t.AssertNil(err)
|
||||
t.Assert(user.NickName, "name_3")
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
type User struct {
|
||||
Id int
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
CreateTime gtime.Time
|
||||
}
|
||||
var user *User
|
||||
err := db.GetScan(ctx, &user, fmt.Sprintf("SELECT * FROM %s WHERE id=?", table), 3)
|
||||
t.AssertNil(err)
|
||||
t.Assert(user.NickName, "name_3")
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
type User struct {
|
||||
Id int
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
CreateTime *gtime.Time
|
||||
}
|
||||
user := new(User)
|
||||
err := db.GetScan(ctx, user, fmt.Sprintf("SELECT * FROM %s WHERE id=?", table), 3)
|
||||
t.AssertNil(err)
|
||||
t.Assert(user.NickName, "name_3")
|
||||
})
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
type User struct {
|
||||
Id int
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
CreateTime gtime.Time
|
||||
}
|
||||
var users []User
|
||||
err := db.GetScan(ctx, &users, fmt.Sprintf("SELECT * FROM %s WHERE id>?", table), 1)
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(users), TableSize-1)
|
||||
t.Assert(users[0].Id, 2)
|
||||
t.Assert(users[1].Id, 3)
|
||||
t.Assert(users[2].Id, 4)
|
||||
t.Assert(users[0].NickName, "name_2")
|
||||
t.Assert(users[1].NickName, "name_3")
|
||||
t.Assert(users[2].NickName, "name_4")
|
||||
})
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
type User struct {
|
||||
Id int
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
CreateTime *gtime.Time
|
||||
}
|
||||
var users []User
|
||||
err := db.GetScan(ctx, &users, fmt.Sprintf("SELECT * FROM %s WHERE id>?", table), 1)
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(users), TableSize-1)
|
||||
t.Assert(users[0].Id, 2)
|
||||
t.Assert(users[1].Id, 3)
|
||||
t.Assert(users[2].Id, 4)
|
||||
t.Assert(users[0].NickName, "name_2")
|
||||
t.Assert(users[1].NickName, "name_3")
|
||||
t.Assert(users[2].NickName, "name_4")
|
||||
})
|
||||
}
|
||||
|
||||
func Test_DB_Delete(t *testing.T) {
|
||||
table := createInitTable()
|
||||
defer dropTable(table)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
result, err := db.Delete(ctx, table, "1=1")
|
||||
t.AssertNil(err)
|
||||
n, _ := result.RowsAffected()
|
||||
t.Assert(n, TableSize)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Empty_Slice_Argument(t *testing.T) {
|
||||
table := createInitTable()
|
||||
defer dropTable(table)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
result, err := db.GetAll(ctx, fmt.Sprintf(`select * from %s where id in(?)`, table), g.Slice{})
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(result), 0)
|
||||
})
|
||||
}
|
||||
1113
contrib/drivers/oracle/oracle_z_model_test.go
Normal file
1113
contrib/drivers/oracle/oracle_z_model_test.go
Normal file
File diff suppressed because it is too large
Load Diff
@ -12,13 +12,13 @@
|
||||
package sqlite
|
||||
|
||||
import (
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gmap"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
package etcd
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
etcd3 "go.etcd.io/etcd/client/v3"
|
||||
@ -79,26 +80,34 @@ func NewWithClient(client *etcd3.Client, option ...Option) *Registry {
|
||||
}
|
||||
|
||||
// extractResponseToServices extracts etcd watch response context to service list.
|
||||
func extractResponseToServices(res *etcd3.GetResponse) ([]*gsvc.Service, error) {
|
||||
func extractResponseToServices(res *etcd3.GetResponse) ([]gsvc.Service, error) {
|
||||
if res == nil || res.Kvs == nil {
|
||||
return nil, nil
|
||||
}
|
||||
var (
|
||||
services []*gsvc.Service
|
||||
services []gsvc.Service
|
||||
serviceKey string
|
||||
serviceMap = make(map[string]*gsvc.Service)
|
||||
serviceMap = make(map[string]*gsvc.LocalService)
|
||||
)
|
||||
for _, kv := range res.Kvs {
|
||||
service, err := gsvc.NewServiceWithKV(kv.Key, kv.Value)
|
||||
service, err := gsvc.NewServiceWithKV(string(kv.Key), string(kv.Value))
|
||||
if err != nil {
|
||||
return services, err
|
||||
}
|
||||
if service != nil {
|
||||
serviceKey = service.KeyWithoutEndpoints()
|
||||
if s, ok := serviceMap[serviceKey]; ok {
|
||||
s.Endpoints = append(s.Endpoints, service.Endpoints...)
|
||||
localService, ok := service.(*gsvc.LocalService)
|
||||
if !ok {
|
||||
return nil, gerror.Newf(
|
||||
`service from "gsvc.NewServiceWithKV" is not "*gsvc.LocalService", but "%s"`,
|
||||
reflect.TypeOf(service),
|
||||
)
|
||||
}
|
||||
if localService != nil {
|
||||
serviceKey = localService.GetPrefix()
|
||||
var localServiceInMap *gsvc.LocalService
|
||||
if localServiceInMap, ok = serviceMap[serviceKey]; ok {
|
||||
localServiceInMap.Endpoints = append(localServiceInMap.Endpoints, localService.Endpoints...)
|
||||
} else {
|
||||
serviceMap[serviceKey] = service
|
||||
serviceMap[serviceKey] = localService
|
||||
services = append(services, service)
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,8 +15,12 @@ import (
|
||||
)
|
||||
|
||||
// Search is the etcd discovery search function.
|
||||
func (r *Registry) Search(ctx context.Context, in gsvc.SearchInput) ([]*gsvc.Service, error) {
|
||||
res, err := r.kv.Get(ctx, in.Key(), etcd3.WithPrefix())
|
||||
func (r *Registry) Search(ctx context.Context, in gsvc.SearchInput) ([]gsvc.Service, error) {
|
||||
if in.Prefix == "" && in.Name != "" {
|
||||
in.Prefix = gsvc.NewServiceWithName(in.Name).GetPrefix()
|
||||
}
|
||||
|
||||
res, err := r.kv.Get(ctx, in.Prefix, etcd3.WithPrefix())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -25,18 +29,12 @@ func (r *Registry) Search(ctx context.Context, in gsvc.SearchInput) ([]*gsvc.Ser
|
||||
return nil, err
|
||||
}
|
||||
// Service filter.
|
||||
filteredServices := make([]*gsvc.Service, 0)
|
||||
filteredServices := make([]gsvc.Service, 0)
|
||||
for _, v := range services {
|
||||
if in.Deployment != "" && in.Deployment != v.Deployment {
|
||||
if in.Name != "" && in.Name != v.GetName() {
|
||||
continue
|
||||
}
|
||||
if in.Namespace != "" && in.Namespace != v.Namespace {
|
||||
continue
|
||||
}
|
||||
if in.Name != "" && in.Name != v.Name {
|
||||
continue
|
||||
}
|
||||
if in.Version != "" && in.Version != v.Version {
|
||||
if in.Version != "" && in.Version != v.GetVersion() {
|
||||
continue
|
||||
}
|
||||
service := v
|
||||
|
||||
@ -16,19 +16,19 @@ import (
|
||||
)
|
||||
|
||||
// Register implements the gsvc.Register interface.
|
||||
func (r *Registry) Register(ctx context.Context, service *gsvc.Service) error {
|
||||
func (r *Registry) Register(ctx context.Context, service gsvc.Service) (gsvc.Service, error) {
|
||||
r.lease = etcd3.NewLease(r.client)
|
||||
grant, err := r.lease.Grant(ctx, int64(r.keepaliveTTL.Seconds()))
|
||||
if err != nil {
|
||||
return gerror.Wrapf(err, `etcd grant failed with keepalive ttl "%s"`, r.keepaliveTTL)
|
||||
return nil, gerror.Wrapf(err, `etcd grant failed with keepalive ttl "%s"`, r.keepaliveTTL)
|
||||
}
|
||||
var (
|
||||
key = service.Key()
|
||||
value = service.Value()
|
||||
key = service.GetKey()
|
||||
value = service.GetValue()
|
||||
)
|
||||
_, err = r.client.Put(ctx, key, value, etcd3.WithLease(grant.ID))
|
||||
if err != nil {
|
||||
return gerror.Wrapf(
|
||||
return nil, gerror.Wrapf(
|
||||
err,
|
||||
`etcd put failed with key "%s", value "%s", lease "%d"`,
|
||||
key, value, grant.ID,
|
||||
@ -41,16 +41,15 @@ func (r *Registry) Register(ctx context.Context, service *gsvc.Service) error {
|
||||
)
|
||||
keepAliceCh, err := r.client.KeepAlive(context.Background(), grant.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
go r.doKeepAlive(grant.ID, keepAliceCh)
|
||||
service.Separator = gsvc.DefaultSeparator
|
||||
return nil
|
||||
return service, nil
|
||||
}
|
||||
|
||||
// Deregister implements the gsvc.Deregister interface.
|
||||
func (r *Registry) Deregister(ctx context.Context, service *gsvc.Service) error {
|
||||
_, err := r.client.Delete(ctx, service.Key())
|
||||
func (r *Registry) Deregister(ctx context.Context, service gsvc.Service) error {
|
||||
_, err := r.client.Delete(ctx, service.GetKey())
|
||||
if r.lease != nil {
|
||||
_ = r.lease.Close()
|
||||
}
|
||||
|
||||
@ -35,15 +35,14 @@ func newWatcher(key string, client *etcd3.Client) (*watcher, error) {
|
||||
}
|
||||
w.ctx, w.cancel = context.WithCancel(context.Background())
|
||||
w.watchChan = w.watcher.Watch(w.ctx, key, etcd3.WithPrefix(), etcd3.WithRev(0))
|
||||
err := w.watcher.RequestProgress(context.Background())
|
||||
if err != nil {
|
||||
if err := w.watcher.RequestProgress(context.Background()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return w, nil
|
||||
}
|
||||
|
||||
// Proceed is used to watch the key.
|
||||
func (w *watcher) Proceed() ([]*gsvc.Service, error) {
|
||||
func (w *watcher) Proceed() ([]gsvc.Service, error) {
|
||||
select {
|
||||
case <-w.ctx.Done():
|
||||
return nil, w.ctx.Err()
|
||||
@ -58,7 +57,7 @@ func (w *watcher) Close() error {
|
||||
return w.watcher.Close()
|
||||
}
|
||||
|
||||
func (w *watcher) getServicesByPrefix() ([]*gsvc.Service, error) {
|
||||
func (w *watcher) getServicesByPrefix() ([]gsvc.Service, error) {
|
||||
res, err := w.kv.Get(w.ctx, w.key, etcd3.WithPrefix())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.15
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.0.0
|
||||
go.etcd.io/etcd/client/v3 v3.5.1
|
||||
go.etcd.io/etcd/client/v3 v3.5.4
|
||||
)
|
||||
|
||||
replace github.com/gogf/gf/v2 => ../../../
|
||||
|
||||
@ -160,7 +160,7 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
|
||||
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
|
||||
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
|
||||
github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
|
||||
github.com/prometheus/client_golang v1.11.1/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
|
||||
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
@ -189,12 +189,12 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
go.etcd.io/etcd/api/v3 v3.5.1 h1:v28cktvBq+7vGyJXF8G+rWJmj+1XUmMtqcLnH8hDocM=
|
||||
go.etcd.io/etcd/api/v3 v3.5.1/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.1 h1:XIQcHCFSG53bJETYeRJtIxdLv2EWRGxcfzR8lSnTH4E=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.1/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
|
||||
go.etcd.io/etcd/client/v3 v3.5.1 h1:oImGuV5LGKjCqXdjkMHCyWa5OO1gYKCnC/1sgdfj1Uk=
|
||||
go.etcd.io/etcd/client/v3 v3.5.1/go.mod h1:OnjH4M8OnAotwaB2l9bVgZzRFKru7/ZMoS46OtKyd3Q=
|
||||
go.etcd.io/etcd/api/v3 v3.5.4 h1:OHVyt3TopwtUQ2GKdd5wu3PmmipR4FTwCqoEjSyRdIc=
|
||||
go.etcd.io/etcd/api/v3 v3.5.4/go.mod h1:5GB2vv4A4AOn3yk7MftYGHkUfGtDHnEraIjym4dYz5A=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.4 h1:lrneYvz923dvC14R54XcA7FXoZ3mlGZAgmwhfm7HqOg=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.4/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
|
||||
go.etcd.io/etcd/client/v3 v3.5.4 h1:p83BUL3tAYS0OT/r0qglgc3M1JjhM0diV8DSWAhVXv4=
|
||||
go.etcd.io/etcd/client/v3 v3.5.4/go.mod h1:ZaRkVgBZC+L+dLCjTcF1hRXpgZXQPOvnA/Ak/gq3kiY=
|
||||
go.opentelemetry.io/otel v1.7.0 h1:Z2lA3Tdch0iDcrhJXDIlC94XE+bxok1F9B+4Lz/lGsM=
|
||||
go.opentelemetry.io/otel v1.7.0/go.mod h1:5BdUoMIz5WEs0vt0CUEMtSSaTSHBBVwrhnz7+nrD5xk=
|
||||
go.opentelemetry.io/otel/sdk v1.7.0 h1:4OmStpcKVOfvDOgCt7UriAPtKolwIhxpnSNI/yK+1B0=
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.15
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.0.0
|
||||
github.com/polarismesh/polaris-go v1.1.0
|
||||
github.com/polarismesh/polaris-go v1.2.0-beta.0.0.20220517041223-596a6a63b00f
|
||||
)
|
||||
|
||||
replace github.com/gogf/gf/v2 => ../../../
|
||||
|
||||
@ -62,8 +62,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
||||
github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI=
|
||||
github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
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=
|
||||
@ -74,7 +74,7 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
|
||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
||||
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
|
||||
github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
|
||||
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
|
||||
@ -149,6 +149,7 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
|
||||
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.4/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.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
|
||||
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
@ -250,8 +251,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
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/polarismesh/polaris-go v1.1.0 h1:nFvn3q3XaVFhzF7pBnIySrN0ZZBwvbbYXC5r2DpsQN0=
|
||||
github.com/polarismesh/polaris-go v1.1.0/go.mod h1:tquawfjEKp1W3ffNJQSzhfditjjoZ7tvhOCElN7Efzs=
|
||||
github.com/polarismesh/polaris-go v1.2.0-beta.0.0.20220517041223-596a6a63b00f h1:IL2vXn/LjasI79p2X0/j8DZ+XnV5wgnjNpO1PQjn9Bc=
|
||||
github.com/polarismesh/polaris-go v1.2.0-beta.0.0.20220517041223-596a6a63b00f/go.mod h1:xXTl4b5ybYkwvXZA+nc1HNyLK/bsHUg08R4ewTa9axc=
|
||||
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
|
||||
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
|
||||
@ -314,12 +315,12 @@ go.opentelemetry.io/otel/trace v1.7.0/go.mod h1:fzLSB9nqR2eXzxPXb2JW9IKE+ScyXA48
|
||||
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
|
||||
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
|
||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723 h1:sHOAIxRGBp443oHZIPB+HsUGaksVCXVQENPxwTfQdH4=
|
||||
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
|
||||
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
|
||||
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
|
||||
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
|
||||
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
|
||||
go.uber.org/zap v1.19.1 h1:ue41HOKd1vGURxrmeKIgELGb3jPW9DMUDGtsinblHwI=
|
||||
go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI=
|
||||
go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8=
|
||||
go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
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=
|
||||
@ -394,9 +395,9 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b
|
||||
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
|
||||
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA=
|
||||
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
@ -453,25 +454,31 @@ golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0=
|
||||
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 h1:nonptSpoQ4vQjyraW20DXPAglgQfVnM9ZC6MmNLMR60=
|
||||
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/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.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 h1:GLw7MR8AfAG2GmGcmVgObFOHXYypgGjnGno25RDwn3Y=
|
||||
golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2/go.mod h1:EFNZuWvGYxIRUEX+K8UmCFwYmZjqcrnq15ZuVldZkZ0=
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
@ -578,8 +585,9 @@ google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEY
|
||||
google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA=
|
||||
google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
||||
google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
||||
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987 h1:PDIOdWxZ8eRizhKa1AAvY53xsvLB1cWorMjslvY3VA8=
|
||||
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
||||
google.golang.org/genproto v0.0.0-20220504150022-98cd25cafc72 h1:iif0mpUetMBqcQPUoq+JnCcmzvfpp8wRx515va8wP1c=
|
||||
google.golang.org/genproto v0.0.0-20220504150022-98cd25cafc72/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
|
||||
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
|
||||
@ -594,8 +602,9 @@ google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM
|
||||
google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
||||
google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
|
||||
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
|
||||
google.golang.org/grpc v1.42.0 h1:XT2/MFpuPFsEX2fWh3YQtHkZ+WYZFQRfaUgLZYj/p6A=
|
||||
google.golang.org/grpc v1.42.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU=
|
||||
google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
|
||||
google.golang.org/grpc v1.46.2 h1:u+MLGgVf7vRdjEYZ8wDFhAVNmhkbJ5hmrA1LMWK1CAQ=
|
||||
google.golang.org/grpc v1.46.2/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
|
||||
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=
|
||||
@ -607,8 +616,10 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD
|
||||
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
|
||||
google.golang.org/protobuf v1.25.0/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 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
|
||||
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
||||
@ -8,20 +8,12 @@
|
||||
package polaris
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/polarismesh/polaris-go"
|
||||
"github.com/polarismesh/polaris-go/pkg/config"
|
||||
"github.com/polarismesh/polaris-go/pkg/model"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/net/gsvc"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -29,9 +21,9 @@ var (
|
||||
)
|
||||
|
||||
const (
|
||||
// instanceIDSeparator Instance id Separator.
|
||||
instanceIDSeparator = "-"
|
||||
endpointDelimiter = ":"
|
||||
metadataKeyKind = "kind"
|
||||
metadataKeyVersion = "version"
|
||||
)
|
||||
|
||||
type options struct {
|
||||
@ -169,55 +161,3 @@ func NewWithConfig(conf config.Configuration, opts ...Option) (r *Registry) {
|
||||
}
|
||||
return New(provider, consumer, opts...)
|
||||
}
|
||||
|
||||
func instancesToServiceInstances(instances []model.Instance) []*gsvc.Service {
|
||||
serviceInstances := make([]*gsvc.Service, 0, len(instances))
|
||||
for _, instance := range instances {
|
||||
if instance.IsHealthy() {
|
||||
serviceInstances = append(serviceInstances, instanceToServiceInstance(instance))
|
||||
}
|
||||
}
|
||||
return serviceInstances
|
||||
}
|
||||
|
||||
func instanceToServiceInstance(instance model.Instance) *gsvc.Service {
|
||||
metadata := instance.GetMetadata()
|
||||
names := strings.Split(instance.GetService(), instanceIDSeparator)
|
||||
if names != nil && len(names) > 4 {
|
||||
return &gsvc.Service{
|
||||
Prefix: names[0],
|
||||
Deployment: names[1],
|
||||
Namespace: names[2],
|
||||
Name: names[3],
|
||||
Version: metadata["version"],
|
||||
Metadata: gconv.Map(metadata),
|
||||
Endpoints: []string{fmt.Sprintf("%s:%d", instance.GetHost(), instance.GetPort())},
|
||||
Separator: instanceIDSeparator,
|
||||
}
|
||||
}
|
||||
|
||||
return &gsvc.Service{
|
||||
Name: instance.GetService(),
|
||||
Namespace: instance.GetNamespace(),
|
||||
Version: metadata["version"],
|
||||
Metadata: gconv.Map(metadata),
|
||||
Endpoints: []string{fmt.Sprintf("%s:%d", instance.GetHost(), instance.GetPort())},
|
||||
Separator: instanceIDSeparator,
|
||||
}
|
||||
}
|
||||
|
||||
// getHostAndPortFromEndpoint get host and port from endpoint.
|
||||
func getHostAndPortFromEndpoint(ctx context.Context, endpoint string) (host string, port int, err error) {
|
||||
endpoints := gstr.SplitAndTrim(endpoint, endpointDelimiter)
|
||||
if len(endpoints) < 2 {
|
||||
err = gerror.Newf(`invalid endpoint "%s"`, endpoint)
|
||||
return
|
||||
}
|
||||
host = endpoints[0]
|
||||
// port to int
|
||||
if port, err = strconv.Atoi(endpoints[1]); err != nil {
|
||||
err = gerror.Wrapf(err, `convert port string "%s" to int failed`, endpoints[1])
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@ -8,20 +8,28 @@ package polaris
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/polarismesh/polaris-go"
|
||||
"github.com/polarismesh/polaris-go/pkg/model"
|
||||
|
||||
"github.com/gogf/gf/v2/net/gsvc"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
// Search returns the service instances in memory according to the service name.
|
||||
func (r *Registry) Search(ctx context.Context, in gsvc.SearchInput) ([]*gsvc.Service, error) {
|
||||
in.Separator = instanceIDSeparator
|
||||
func (r *Registry) Search(ctx context.Context, in gsvc.SearchInput) ([]gsvc.Service, error) {
|
||||
if in.Prefix == "" && in.Name != "" {
|
||||
service := &Service{
|
||||
Service: gsvc.NewServiceWithName(in.Name),
|
||||
}
|
||||
in.Prefix = service.GetPrefix()
|
||||
}
|
||||
// get all instances
|
||||
instancesResponse, err := r.consumer.GetAllInstances(&polaris.GetAllInstancesRequest{
|
||||
GetAllInstancesRequest: model.GetAllInstancesRequest{
|
||||
Service: in.Key(),
|
||||
Service: in.Prefix,
|
||||
Namespace: r.opt.Namespace,
|
||||
Timeout: &r.opt.Timeout,
|
||||
RetryCount: &r.opt.RetryCount,
|
||||
@ -38,3 +46,44 @@ func (r *Registry) Search(ctx context.Context, in gsvc.SearchInput) ([]*gsvc.Ser
|
||||
func (r *Registry) Watch(ctx context.Context, serviceName string) (gsvc.Watcher, error) {
|
||||
return newWatcher(ctx, r.opt.Namespace, serviceName, r.consumer)
|
||||
}
|
||||
|
||||
func instancesToServiceInstances(instances []model.Instance) []gsvc.Service {
|
||||
serviceInstances := make([]gsvc.Service, 0, len(instances))
|
||||
for _, instance := range instances {
|
||||
if instance.IsHealthy() {
|
||||
serviceInstances = append(serviceInstances, instanceToServiceInstance(instance))
|
||||
}
|
||||
}
|
||||
return serviceInstances
|
||||
}
|
||||
|
||||
func instanceToServiceInstance(instance model.Instance) gsvc.Service {
|
||||
var (
|
||||
s *gsvc.LocalService
|
||||
metadata = instance.GetMetadata()
|
||||
names = strings.Split(instance.GetService(), instanceIDSeparator)
|
||||
endpoints = gsvc.NewEndpoints(fmt.Sprintf("%s:%d", instance.GetHost(), instance.GetPort()))
|
||||
)
|
||||
if names != nil && len(names) > 4 {
|
||||
s = &gsvc.LocalService{
|
||||
Head: names[0],
|
||||
Deployment: names[1],
|
||||
Namespace: names[2],
|
||||
Name: names[3],
|
||||
Version: metadata[metadataKeyVersion],
|
||||
Metadata: gconv.Map(metadata),
|
||||
Endpoints: endpoints,
|
||||
}
|
||||
} else {
|
||||
s = &gsvc.LocalService{
|
||||
Name: instance.GetService(),
|
||||
Namespace: instance.GetNamespace(),
|
||||
Version: metadata[metadataKeyVersion],
|
||||
Metadata: gconv.Map(metadata),
|
||||
Endpoints: endpoints,
|
||||
}
|
||||
}
|
||||
return &Service{
|
||||
Service: s,
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,47 +20,48 @@ import (
|
||||
)
|
||||
|
||||
// Register the registration.
|
||||
func (r *Registry) Register(ctx context.Context, serviceInstance *gsvc.Service) error {
|
||||
ids := make([]string, 0, len(serviceInstance.Endpoints))
|
||||
// set separator
|
||||
serviceInstance.Separator = instanceIDSeparator
|
||||
for _, endpoint := range serviceInstance.Endpoints {
|
||||
host, portNum, err := getHostAndPortFromEndpoint(ctx, endpoint)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *Registry) Register(ctx context.Context, service gsvc.Service) (gsvc.Service, error) {
|
||||
// Replace input service to custom service type.
|
||||
service = &Service{
|
||||
Service: service,
|
||||
}
|
||||
// Register logic.
|
||||
var (
|
||||
ids = make([]string, 0, len(service.GetEndpoints()))
|
||||
serviceVersion = service.GetVersion()
|
||||
)
|
||||
for _, endpoint := range service.GetEndpoints() {
|
||||
// medata
|
||||
var rmd map[string]interface{}
|
||||
if serviceInstance.Metadata == nil {
|
||||
if service.GetMetadata().IsEmpty() {
|
||||
rmd = map[string]interface{}{
|
||||
"kind": gsvc.DefaultProtocol,
|
||||
"version": serviceInstance.Version,
|
||||
metadataKeyKind: gsvc.DefaultProtocol,
|
||||
metadataKeyVersion: service.GetVersion(),
|
||||
}
|
||||
} else {
|
||||
rmd = make(map[string]interface{}, len(serviceInstance.Metadata)+2)
|
||||
rmd["kind"] = gsvc.DefaultProtocol
|
||||
if protocol, ok := serviceInstance.Metadata[gsvc.MDProtocol]; ok {
|
||||
rmd["kind"] = gconv.String(protocol)
|
||||
rmd = make(map[string]interface{}, len(service.GetMetadata())+2)
|
||||
rmd[metadataKeyKind] = gsvc.DefaultProtocol
|
||||
if protocol, ok := service.GetMetadata()[gsvc.MDProtocol]; ok {
|
||||
rmd[metadataKeyKind] = gconv.String(protocol)
|
||||
}
|
||||
rmd["version"] = serviceInstance.Version
|
||||
for k, v := range serviceInstance.Metadata {
|
||||
rmd[metadataKeyVersion] = serviceVersion
|
||||
for k, v := range service.GetMetadata() {
|
||||
rmd[k] = v
|
||||
}
|
||||
}
|
||||
// Register
|
||||
service, err := r.provider.Register(
|
||||
registeredService, err := r.provider.Register(
|
||||
&polaris.InstanceRegisterRequest{
|
||||
InstanceRegisterRequest: model.InstanceRegisterRequest{
|
||||
Service: serviceInstance.KeyWithoutEndpoints(),
|
||||
Service: service.GetPrefix(),
|
||||
ServiceToken: r.opt.ServiceToken,
|
||||
Namespace: r.opt.Namespace,
|
||||
Host: host,
|
||||
Port: portNum,
|
||||
Host: endpoint.Host(),
|
||||
Port: endpoint.Port(),
|
||||
Protocol: r.opt.Protocol,
|
||||
Weight: &r.opt.Weight,
|
||||
Priority: &r.opt.Priority,
|
||||
Version: &serviceInstance.Version,
|
||||
Version: &serviceVersion,
|
||||
Metadata: gconv.MapStrStr(rmd),
|
||||
Healthy: &r.opt.Healthy,
|
||||
Isolate: &r.opt.Isolate,
|
||||
@ -70,69 +71,36 @@ func (r *Registry) Register(ctx context.Context, serviceInstance *gsvc.Service)
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
instanceID := service.InstanceID
|
||||
|
||||
if r.opt.Heartbeat {
|
||||
// start heartbeat report
|
||||
go func() {
|
||||
ticker := time.NewTicker(time.Second * time.Duration(r.opt.TTL))
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
err = r.provider.Heartbeat(&polaris.InstanceHeartbeatRequest{
|
||||
InstanceHeartbeatRequest: model.InstanceHeartbeatRequest{
|
||||
Service: serviceInstance.KeyWithoutEndpoints(),
|
||||
Namespace: r.opt.Namespace,
|
||||
Host: host,
|
||||
Port: portNum,
|
||||
ServiceToken: r.opt.ServiceToken,
|
||||
InstanceID: instanceID,
|
||||
Timeout: &r.opt.Timeout,
|
||||
RetryCount: &r.opt.RetryCount,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, err.Error())
|
||||
continue
|
||||
}
|
||||
case <-r.c:
|
||||
g.Log().Debug(ctx, "stop heartbeat")
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
r.doHeartBeat(ctx, registeredService.InstanceID, service, endpoint)
|
||||
}
|
||||
ids = append(ids, instanceID)
|
||||
ids = append(ids, registeredService.InstanceID)
|
||||
}
|
||||
// need to set InstanceID for Deregister
|
||||
serviceInstance.ID = gstr.Join(ids, instanceIDSeparator)
|
||||
return nil
|
||||
service.(*Service).ID = gstr.Join(ids, instanceIDSeparator)
|
||||
return service, nil
|
||||
}
|
||||
|
||||
// Deregister the registration.
|
||||
func (r *Registry) Deregister(ctx context.Context, serviceInstance *gsvc.Service) error {
|
||||
func (r *Registry) Deregister(ctx context.Context, service gsvc.Service) error {
|
||||
r.c <- struct{}{}
|
||||
split := gstr.Split(serviceInstance.ID, instanceIDSeparator)
|
||||
serviceInstance.Separator = instanceIDSeparator
|
||||
for i, endpoint := range serviceInstance.Endpoints {
|
||||
host, portNum, err := getHostAndPortFromEndpoint(ctx, endpoint)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var (
|
||||
err error
|
||||
split = gstr.Split(service.(*Service).ID, instanceIDSeparator)
|
||||
)
|
||||
for i, endpoint := range service.GetEndpoints() {
|
||||
// Deregister
|
||||
err = r.provider.Deregister(
|
||||
&polaris.InstanceDeRegisterRequest{
|
||||
InstanceDeRegisterRequest: model.InstanceDeRegisterRequest{
|
||||
Service: serviceInstance.KeyWithoutEndpoints(),
|
||||
Service: service.GetPrefix(),
|
||||
ServiceToken: r.opt.ServiceToken,
|
||||
Namespace: r.opt.Namespace,
|
||||
InstanceID: split[i],
|
||||
Host: host,
|
||||
Port: portNum,
|
||||
Host: endpoint.Host(),
|
||||
Port: endpoint.Port(),
|
||||
Timeout: &r.opt.Timeout,
|
||||
RetryCount: &r.opt.RetryCount,
|
||||
},
|
||||
@ -144,3 +112,36 @@ func (r *Registry) Deregister(ctx context.Context, serviceInstance *gsvc.Service
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Registry) doHeartBeat(ctx context.Context, instanceID string, service gsvc.Service, endpoint gsvc.Endpoint) {
|
||||
go func() {
|
||||
ticker := time.NewTicker(time.Second * time.Duration(r.opt.TTL))
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
err := r.provider.Heartbeat(&polaris.InstanceHeartbeatRequest{
|
||||
InstanceHeartbeatRequest: model.InstanceHeartbeatRequest{
|
||||
Service: service.GetPrefix(),
|
||||
Namespace: r.opt.Namespace,
|
||||
Host: endpoint.Host(),
|
||||
Port: endpoint.Port(),
|
||||
ServiceToken: r.opt.ServiceToken,
|
||||
InstanceID: instanceID,
|
||||
Timeout: &r.opt.Timeout,
|
||||
RetryCount: &r.opt.RetryCount,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, err.Error())
|
||||
continue
|
||||
}
|
||||
g.Log().Debug(ctx, "heartbeat success")
|
||||
case <-r.c:
|
||||
g.Log().Debug(ctx, "stop heartbeat")
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
28
contrib/registry/polaris/polaris_service.go
Normal file
28
contrib/registry/polaris/polaris_service.go
Normal file
@ -0,0 +1,28 @@
|
||||
package polaris
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/net/gsvc"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
)
|
||||
|
||||
// Service for wrapping gsvc.Server and extends extra attributes for polaris purpose.
|
||||
type Service struct {
|
||||
gsvc.Service // Common service object.
|
||||
ID string // ID is the unique instance ID as registered, for some registrar server.
|
||||
}
|
||||
|
||||
// GetKey overwrites the GetKey function of gsvc.Service for replacing separator string.
|
||||
func (s *Service) GetKey() string {
|
||||
key := s.Service.GetKey()
|
||||
key = gstr.Replace(key, gsvc.DefaultSeparator, instanceIDSeparator)
|
||||
key = gstr.TrimLeft(key, instanceIDSeparator)
|
||||
return key
|
||||
}
|
||||
|
||||
// GetPrefix overwrites the GetPrefix function of gsvc.Service for replacing separator string.
|
||||
func (s *Service) GetPrefix() string {
|
||||
prefix := s.Service.GetPrefix()
|
||||
prefix = gstr.Replace(prefix, gsvc.DefaultSeparator, instanceIDSeparator)
|
||||
prefix = gstr.TrimLeft(prefix, instanceIDSeparator)
|
||||
return prefix
|
||||
}
|
||||
@ -22,7 +22,7 @@ type Watcher struct {
|
||||
Ctx context.Context
|
||||
Cancel context.CancelFunc
|
||||
Channel <-chan model.SubScribeEvent
|
||||
ServiceInstances []*gsvc.Service
|
||||
ServiceInstances []gsvc.Service
|
||||
}
|
||||
|
||||
func newWatcher(ctx context.Context, namespace string, serviceName string, consumer polaris.ConsumerAPI) (*Watcher, error) {
|
||||
@ -52,7 +52,7 @@ func newWatcher(ctx context.Context, namespace string, serviceName string, consu
|
||||
// 1.the first time to watch and the service instance list is not empty.
|
||||
// 2.any service instance changes found.
|
||||
// if the above two conditions are not met, it will block until the context deadline is exceeded or canceled
|
||||
func (w *Watcher) Proceed() ([]*gsvc.Service, error) {
|
||||
func (w *Watcher) Proceed() ([]gsvc.Service, error) {
|
||||
select {
|
||||
case <-w.Ctx.Done():
|
||||
return nil, w.Ctx.Err()
|
||||
@ -67,7 +67,7 @@ func (w *Watcher) Proceed() ([]*gsvc.Service, error) {
|
||||
if instanceEvent.DeleteEvent != nil {
|
||||
for _, instance := range instanceEvent.DeleteEvent.Instances {
|
||||
for i, serviceInstance := range w.ServiceInstances {
|
||||
if serviceInstance.ID == instance.GetId() {
|
||||
if serviceInstance.(*Service).ID == instance.GetId() {
|
||||
// remove equal
|
||||
if len(w.ServiceInstances) <= 1 {
|
||||
w.ServiceInstances = w.ServiceInstances[0:0]
|
||||
@ -82,7 +82,7 @@ func (w *Watcher) Proceed() ([]*gsvc.Service, error) {
|
||||
if instanceEvent.UpdateEvent != nil {
|
||||
for i, serviceInstance := range w.ServiceInstances {
|
||||
for _, update := range instanceEvent.UpdateEvent.UpdateList {
|
||||
if serviceInstance.ID == update.Before.GetId() {
|
||||
if serviceInstance.(*Service).ID == update.Before.GetId() {
|
||||
w.ServiceInstances[i] = instanceToServiceInstance(update.After)
|
||||
}
|
||||
}
|
||||
@ -90,7 +90,10 @@ func (w *Watcher) Proceed() ([]*gsvc.Service, error) {
|
||||
}
|
||||
// handle AddEvent
|
||||
if instanceEvent.AddEvent != nil {
|
||||
w.ServiceInstances = append(w.ServiceInstances, instancesToServiceInstances(instanceEvent.AddEvent.Instances)...)
|
||||
w.ServiceInstances = append(
|
||||
w.ServiceInstances,
|
||||
instancesToServiceInstances(instanceEvent.AddEvent.Instances)...,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,20 +30,19 @@ func TestRegistry(t *testing.T) {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
svc := &gsvc.Service{
|
||||
svc := &gsvc.LocalService{
|
||||
Name: "goframe-provider-0-tcp",
|
||||
Version: "test",
|
||||
Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"},
|
||||
Endpoints: []string{"127.0.0.1:9000"},
|
||||
Separator: instanceIDSeparator,
|
||||
Endpoints: gsvc.NewEndpoints("127.0.0.1:9000"),
|
||||
}
|
||||
|
||||
err := r.Register(ctx, svc)
|
||||
s, err := r.Register(ctx, svc)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = r.Deregister(ctx, svc)
|
||||
err = r.Deregister(ctx, s)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -59,54 +58,51 @@ func TestRegistryMany(t *testing.T) {
|
||||
WithTTL(100),
|
||||
)
|
||||
|
||||
svc := &gsvc.Service{
|
||||
svc := &gsvc.LocalService{
|
||||
Name: "goframe-provider-1-tcp",
|
||||
Version: "test",
|
||||
Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"},
|
||||
Endpoints: []string{"127.0.0.1:9000"},
|
||||
Separator: instanceIDSeparator,
|
||||
Endpoints: gsvc.NewEndpoints("127.0.0.1:9000"),
|
||||
}
|
||||
svc1 := &gsvc.Service{
|
||||
svc1 := &gsvc.LocalService{
|
||||
Name: "goframe-provider-2-tcp",
|
||||
Version: "test",
|
||||
Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"},
|
||||
Endpoints: []string{"127.0.0.1:9001"},
|
||||
Separator: instanceIDSeparator,
|
||||
Endpoints: gsvc.NewEndpoints("127.0.0.1:9001"),
|
||||
}
|
||||
svc2 := &gsvc.Service{
|
||||
svc2 := &gsvc.LocalService{
|
||||
Name: "goframe-provider-3-tcp",
|
||||
Version: "test",
|
||||
Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"},
|
||||
Endpoints: []string{"127.0.0.1:9002"},
|
||||
Separator: instanceIDSeparator,
|
||||
Endpoints: gsvc.NewEndpoints("127.0.0.1:9002"),
|
||||
}
|
||||
|
||||
err := r.Register(context.Background(), svc)
|
||||
s0, err := r.Register(context.Background(), svc)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = r.Register(context.Background(), svc1)
|
||||
s1, err := r.Register(context.Background(), svc1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = r.Register(context.Background(), svc2)
|
||||
s2, err := r.Register(context.Background(), svc2)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = r.Deregister(context.Background(), svc)
|
||||
err = r.Deregister(context.Background(), s0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = r.Deregister(context.Background(), svc1)
|
||||
err = r.Deregister(context.Background(), s1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = r.Deregister(context.Background(), svc2)
|
||||
err = r.Deregister(context.Background(), s2)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -124,26 +120,23 @@ func TestGetService(t *testing.T) {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
svc := &gsvc.Service{
|
||||
svc := &gsvc.LocalService{
|
||||
Name: "goframe-provider-4-tcp",
|
||||
Version: "test",
|
||||
Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"},
|
||||
Endpoints: []string{"127.0.0.1:9000"},
|
||||
Separator: instanceIDSeparator,
|
||||
Endpoints: gsvc.NewEndpoints("127.0.0.1:9000"),
|
||||
}
|
||||
|
||||
err := r.Register(ctx, svc)
|
||||
s, err := r.Register(ctx, svc)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
time.Sleep(time.Second * 1)
|
||||
serviceInstances, err := r.Search(ctx, gsvc.SearchInput{
|
||||
Prefix: svc.Prefix,
|
||||
Deployment: svc.Deployment,
|
||||
Namespace: svc.Namespace,
|
||||
Name: svc.Name,
|
||||
Version: svc.Version,
|
||||
Metadata: svc.Metadata,
|
||||
Prefix: s.GetPrefix(),
|
||||
Name: svc.Name,
|
||||
Version: svc.Version,
|
||||
Metadata: svc.Metadata,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -152,7 +145,7 @@ func TestGetService(t *testing.T) {
|
||||
g.Log().Info(ctx, instance)
|
||||
}
|
||||
|
||||
err = r.Deregister(ctx, svc)
|
||||
err = r.Deregister(ctx, s)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -170,20 +163,23 @@ func TestWatch(t *testing.T) {
|
||||
|
||||
ctx := gctx.New()
|
||||
|
||||
svc := &gsvc.Service{
|
||||
svc := &gsvc.LocalService{
|
||||
Name: "goframe-provider-4-tcp",
|
||||
Version: "test",
|
||||
Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"},
|
||||
Endpoints: []string{"127.0.0.1:9000"},
|
||||
Separator: instanceIDSeparator,
|
||||
Endpoints: gsvc.NewEndpoints("127.0.0.1:9000"),
|
||||
}
|
||||
|
||||
watch, err := r.Watch(context.Background(), svc.KeyWithoutEndpoints())
|
||||
s := &Service{
|
||||
Service: svc,
|
||||
}
|
||||
|
||||
watch, err := r.Watch(context.Background(), s.GetPrefix())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = r.Register(context.Background(), svc)
|
||||
s1, err := r.Register(context.Background(), svc)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -197,10 +193,10 @@ func TestWatch(t *testing.T) {
|
||||
}
|
||||
for _, instance := range next {
|
||||
// it will output one instance
|
||||
g.Log().Info(ctx, instance)
|
||||
g.Log().Info(ctx, "Register Proceed service: ", instance)
|
||||
}
|
||||
|
||||
err = r.Deregister(context.Background(), svc)
|
||||
err = r.Deregister(context.Background(), s1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -212,7 +208,7 @@ func TestWatch(t *testing.T) {
|
||||
}
|
||||
for _, instance := range next {
|
||||
// it will output nothing
|
||||
g.Log().Info(ctx, instance)
|
||||
g.Log().Info(ctx, "Deregister Proceed service: ", instance)
|
||||
}
|
||||
|
||||
err = watch.Close()
|
||||
@ -5,7 +5,7 @@ go 1.15
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.0.0
|
||||
go.opentelemetry.io/otel v1.7.0
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.3.0
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.7.0
|
||||
go.opentelemetry.io/otel/sdk v1.7.0
|
||||
)
|
||||
|
||||
|
||||
@ -18,12 +18,9 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
|
||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
|
||||
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
|
||||
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.2.1/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
|
||||
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/stdr v1.2.0/go.mod h1:YkVgnZu1ZjjL7xTxrfm/LLZBfkhTqSR1ydtm6jTKKwI=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
|
||||
@ -43,7 +40,6 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
|
||||
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.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
|
||||
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
|
||||
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
||||
@ -84,20 +80,16 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
|
||||
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
go.opentelemetry.io/otel v1.3.0/go.mod h1:PWIKzi6JCp7sM0k9yZ43VX+T345uNbAkDKwHVjb2PTs=
|
||||
go.opentelemetry.io/otel v1.7.0 h1:Z2lA3Tdch0iDcrhJXDIlC94XE+bxok1F9B+4Lz/lGsM=
|
||||
go.opentelemetry.io/otel v1.7.0/go.mod h1:5BdUoMIz5WEs0vt0CUEMtSSaTSHBBVwrhnz7+nrD5xk=
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.3.0 h1:HfydzioALdtcB26H5WHc4K47iTETJCdloL7VN579/L0=
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.3.0/go.mod h1:KoYHi1BtkUPncGSRtCe/eh1ijsnePhSkxwzz07vU0Fc=
|
||||
go.opentelemetry.io/otel/sdk v1.3.0/go.mod h1:rIo4suHNhQwBIPg9axF8V9CA72Wz2mKF1teNrup8yzs=
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.7.0 h1:wXgjiRldljksZkZrldGVe6XrG9u3kYDyQmkZwmm5dI0=
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.7.0/go.mod h1:PwQAOqBgqbLQRKlj466DuD2qyMjbtcPpfPfj+AqbSBs=
|
||||
go.opentelemetry.io/otel/sdk v1.7.0 h1:4OmStpcKVOfvDOgCt7UriAPtKolwIhxpnSNI/yK+1B0=
|
||||
go.opentelemetry.io/otel/sdk v1.7.0/go.mod h1:uTEOTwaqIVuTGiJN7ii13Ibp75wJmYUDe374q6cZwUU=
|
||||
go.opentelemetry.io/otel/trace v1.3.0/go.mod h1:c/VDhno8888bvQYmbYLqe41/Ldmr/KKunbvWM4/fEjk=
|
||||
go.opentelemetry.io/otel/trace v1.7.0 h1:O37Iogk1lEkMRXewVtZ1BBTVn5JEp8GrJvP92bJqC6o=
|
||||
go.opentelemetry.io/otel/trace v1.7.0/go.mod h1:fzLSB9nqR2eXzxPXb2JW9IKE+ScyXA48yyE4TNvoHqU=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
|
||||
@ -88,11 +88,15 @@ func (c *Core) ConvertDataForRecordValue(ctx context.Context, value interface{})
|
||||
case gtime.Time:
|
||||
if r.IsZero() {
|
||||
convertedValue = nil
|
||||
} else {
|
||||
convertedValue = r.Time
|
||||
}
|
||||
|
||||
case *gtime.Time:
|
||||
if r.IsZero() {
|
||||
convertedValue = nil
|
||||
} else {
|
||||
convertedValue = r.Time
|
||||
}
|
||||
|
||||
case *time.Time:
|
||||
|
||||
@ -128,15 +128,6 @@ func (c *Core) DoFilter(ctx context.Context, link Link, sql string, args []inter
|
||||
return sql, args, nil
|
||||
}
|
||||
|
||||
type sqlParsingHandlerInput struct {
|
||||
DoCommitInput
|
||||
FormattedSql string
|
||||
}
|
||||
|
||||
type sqlParsingHandlerOutput struct {
|
||||
DoCommitInput
|
||||
}
|
||||
|
||||
// DoCommit commits current sql and arguments to underlying sql driver.
|
||||
func (c *Core) DoCommit(ctx context.Context, in DoCommitInput) (out DoCommitOutput, err error) {
|
||||
// Inject internal data into ctx, especially for transaction creating.
|
||||
@ -266,7 +257,7 @@ func (c *Core) DoCommit(ctx context.Context, in DoCommitInput) (out DoCommitOutp
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
err = gerror.NewCodef(
|
||||
gcode.CodeDbOperationError,
|
||||
"%s, %s\n",
|
||||
"%s, %s",
|
||||
err.Error(),
|
||||
FormatSqlWithArgs(in.Sql, in.Args),
|
||||
)
|
||||
|
||||
@ -135,7 +135,6 @@ func (c *Core) Model(tableNameQueryOrStruct ...interface{}) *Model {
|
||||
extraArgs: extraArgs,
|
||||
}
|
||||
m.whereBuilder = m.Builder()
|
||||
m.whereBuilder.safe = &m.safe
|
||||
if defaultModelSafe {
|
||||
m.safe = true
|
||||
}
|
||||
|
||||
@ -12,7 +12,6 @@ import (
|
||||
|
||||
// WhereBuilder holds multiple where conditions in a group.
|
||||
type WhereBuilder struct {
|
||||
safe *bool // If nil, it uses the safe attribute of its model.
|
||||
model *Model // A WhereBuilder should be bound to certain Model.
|
||||
whereHolder []WhereHolder // Condition strings for where operation.
|
||||
}
|
||||
@ -28,10 +27,7 @@ type WhereHolder struct {
|
||||
|
||||
// Builder creates and returns a WhereBuilder.
|
||||
func (m *Model) Builder() *WhereBuilder {
|
||||
// The WhereBuilder is safe in default when it is created using Builder().
|
||||
var isSafe = true
|
||||
b := &WhereBuilder{
|
||||
safe: &isSafe,
|
||||
model: m,
|
||||
whereHolder: make([]WhereHolder, 0),
|
||||
}
|
||||
@ -41,23 +37,12 @@ func (m *Model) Builder() *WhereBuilder {
|
||||
// getBuilder creates and returns a cloned WhereBuilder of current WhereBuilder if `safe` is true,
|
||||
// or else it returns the current WhereBuilder.
|
||||
func (b *WhereBuilder) getBuilder() *WhereBuilder {
|
||||
var isSafe bool
|
||||
if b.safe != nil {
|
||||
isSafe = *b.safe
|
||||
} else {
|
||||
isSafe = b.model.safe
|
||||
}
|
||||
if !isSafe {
|
||||
return b
|
||||
} else {
|
||||
return b.Clone()
|
||||
}
|
||||
return b.Clone()
|
||||
}
|
||||
|
||||
// Clone clones and returns a WhereBuilder that is a copy of current one.
|
||||
func (b *WhereBuilder) Clone() *WhereBuilder {
|
||||
newBuilder := b.model.Builder()
|
||||
newBuilder.safe = b.safe
|
||||
newBuilder.whereHolder = make([]WhereHolder, len(b.whereHolder))
|
||||
copy(newBuilder.whereHolder, b.whereHolder)
|
||||
return newBuilder
|
||||
@ -125,6 +110,7 @@ func (b *WhereBuilder) convertWhereBuilder(where interface{}, args []interface{}
|
||||
switch v := where.(type) {
|
||||
case WhereBuilder:
|
||||
builder = &v
|
||||
|
||||
case *WhereBuilder:
|
||||
builder = v
|
||||
}
|
||||
|
||||
@ -27,44 +27,21 @@ func (m *Model) Fields(fieldNamesOrMapStruct ...interface{}) *Model {
|
||||
if length == 0 {
|
||||
return m
|
||||
}
|
||||
switch {
|
||||
// String slice.
|
||||
case length >= 2:
|
||||
return m.appendFieldsByStr(gstr.Join(
|
||||
m.mappingAndFilterToTableFields(gconv.Strings(fieldNamesOrMapStruct), true),
|
||||
",",
|
||||
))
|
||||
|
||||
// It needs type asserting.
|
||||
case length == 1:
|
||||
structOrMap := fieldNamesOrMapStruct[0]
|
||||
switch r := structOrMap.(type) {
|
||||
case string:
|
||||
return m.appendFieldsByStr(gstr.Join(
|
||||
m.mappingAndFilterToTableFields([]string{r}, false), ",",
|
||||
))
|
||||
case []string:
|
||||
return m.appendFieldsByStr(gstr.Join(
|
||||
m.mappingAndFilterToTableFields(r, true), ",",
|
||||
))
|
||||
case Raw, *Raw:
|
||||
return m.appendFieldsByStr(gconv.String(structOrMap))
|
||||
default:
|
||||
return m.appendFieldsByStr(gstr.Join(
|
||||
m.mappingAndFilterToTableFields(getFieldsFromStructOrMap(structOrMap), true), ",",
|
||||
))
|
||||
}
|
||||
fields := m.getFieldsFrom(fieldNamesOrMapStruct...)
|
||||
if len(fields) == 0 {
|
||||
return m
|
||||
}
|
||||
return m
|
||||
return m.appendFieldsByStr(gstr.Join(fields, ","))
|
||||
}
|
||||
|
||||
// FieldsPrefix performs as function Fields but add extra prefix for each field.
|
||||
func (m *Model) FieldsPrefix(prefix string, fieldNamesOrMapStruct ...interface{}) *Model {
|
||||
model := m.Fields(fieldNamesOrMapStruct...)
|
||||
array := gstr.SplitAndTrim(model.fields, ",")
|
||||
gstr.PrefixArray(array, prefix+".")
|
||||
model.fields = gstr.Join(array, ",")
|
||||
return model
|
||||
fields := m.getFieldsFrom(fieldNamesOrMapStruct...)
|
||||
if len(fields) == 0 {
|
||||
return m
|
||||
}
|
||||
gstr.PrefixArray(fields, prefix+".")
|
||||
return m.appendFieldsByStr(gstr.Join(fields, ","))
|
||||
}
|
||||
|
||||
// FieldsEx appends `fieldNamesOrMapStruct` to the excluded operation fields of the model,
|
||||
@ -78,28 +55,11 @@ func (m *Model) FieldsEx(fieldNamesOrMapStruct ...interface{}) *Model {
|
||||
if length == 0 {
|
||||
return m
|
||||
}
|
||||
model := m.getModel()
|
||||
switch {
|
||||
case length >= 2:
|
||||
model.fieldsEx = gstr.Join(
|
||||
m.mappingAndFilterToTableFields(gconv.Strings(fieldNamesOrMapStruct), true),
|
||||
",",
|
||||
)
|
||||
return model
|
||||
case length == 1:
|
||||
switch r := fieldNamesOrMapStruct[0].(type) {
|
||||
case string:
|
||||
model.fieldsEx = gstr.Join(m.mappingAndFilterToTableFields([]string{r}, false), ",")
|
||||
case []string:
|
||||
model.fieldsEx = gstr.Join(m.mappingAndFilterToTableFields(r, true), ",")
|
||||
case Raw, *Raw:
|
||||
model.fieldsEx = gconv.String(fieldNamesOrMapStruct[0])
|
||||
default:
|
||||
model.fieldsEx = gstr.Join(m.mappingAndFilterToTableFields(getFieldsFromStructOrMap(r), true), ",")
|
||||
}
|
||||
return model
|
||||
fields := m.getFieldsFrom(fieldNamesOrMapStruct...)
|
||||
if len(fields) == 0 {
|
||||
return m
|
||||
}
|
||||
return m
|
||||
return m.appendFieldsExByStr(gstr.Join(fields, ","))
|
||||
}
|
||||
|
||||
// FieldsExPrefix performs as function FieldsEx but add extra prefix for each field.
|
||||
@ -156,33 +116,6 @@ func (m *Model) FieldAvg(column string, as ...string) *Model {
|
||||
return m.appendFieldsByStr(fmt.Sprintf(`AVG(%s)%s`, m.QuoteWord(column), asStr))
|
||||
}
|
||||
|
||||
func (m *Model) appendFieldsByStr(fields string) *Model {
|
||||
if fields != "" {
|
||||
model := m.getModel()
|
||||
if model.fields == defaultFields {
|
||||
model.fields = ""
|
||||
}
|
||||
if model.fields != "" {
|
||||
model.fields += ","
|
||||
}
|
||||
model.fields += fields
|
||||
return model
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *Model) appendFieldsExByStr(fieldsEx string) *Model {
|
||||
if fieldsEx != "" {
|
||||
model := m.getModel()
|
||||
if model.fieldsEx != "" {
|
||||
model.fieldsEx += ","
|
||||
}
|
||||
model.fieldsEx += fieldsEx
|
||||
return model
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// GetFieldsStr retrieves and returns all fields from the table, joined with char ','.
|
||||
// The optional parameter `prefix` specifies the prefix for each field, eg: GetFieldsStr("u.").
|
||||
func (m *Model) GetFieldsStr(prefix ...string) string {
|
||||
@ -251,3 +184,62 @@ func (m *Model) GetFieldsExStr(fields string, prefix ...string) string {
|
||||
func (m *Model) HasField(field string) (bool, error) {
|
||||
return m.db.GetCore().HasField(m.GetCtx(), m.tablesInit, field)
|
||||
}
|
||||
|
||||
func (m *Model) getFieldsFrom(fieldNamesOrMapStruct ...interface{}) []string {
|
||||
length := len(fieldNamesOrMapStruct)
|
||||
if length == 0 {
|
||||
return nil
|
||||
}
|
||||
switch {
|
||||
// String slice.
|
||||
case length >= 2:
|
||||
return m.mappingAndFilterToTableFields(gconv.Strings(fieldNamesOrMapStruct), true)
|
||||
|
||||
// It needs type asserting.
|
||||
case length == 1:
|
||||
structOrMap := fieldNamesOrMapStruct[0]
|
||||
switch r := structOrMap.(type) {
|
||||
case string:
|
||||
return m.mappingAndFilterToTableFields([]string{r}, false)
|
||||
|
||||
case []string:
|
||||
return m.mappingAndFilterToTableFields(r, true)
|
||||
|
||||
case Raw, *Raw:
|
||||
return []string{gconv.String(structOrMap)}
|
||||
|
||||
default:
|
||||
return m.mappingAndFilterToTableFields(getFieldsFromStructOrMap(structOrMap), true)
|
||||
}
|
||||
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Model) appendFieldsByStr(fields string) *Model {
|
||||
if fields != "" {
|
||||
model := m.getModel()
|
||||
if model.fields == defaultFields {
|
||||
model.fields = ""
|
||||
}
|
||||
if model.fields != "" {
|
||||
model.fields += ","
|
||||
}
|
||||
model.fields += fields
|
||||
return model
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *Model) appendFieldsExByStr(fieldsEx string) *Model {
|
||||
if fieldsEx != "" {
|
||||
model := m.getModel()
|
||||
if model.fieldsEx != "" {
|
||||
model.fieldsEx += ","
|
||||
}
|
||||
model.fieldsEx += fieldsEx
|
||||
return model
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
@ -3,18 +3,20 @@ module github.com/gogf/gf/example
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/contrib/registry/etcd/v2 v2.0.0-rc2
|
||||
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.1.0-rc3
|
||||
github.com/gogf/gf/contrib/registry/etcd/v2 v2.1.0-rc3.0.20220523034830-510fa3faf03f
|
||||
github.com/gogf/gf/contrib/registry/polaris/v2 v2.0.0-rc2
|
||||
github.com/gogf/gf/contrib/trace/jaeger/v2 v2.0.0-rc2
|
||||
github.com/gogf/gf/v2 v2.0.0
|
||||
github.com/gogf/katyusha v0.3.1-0.20220128101623-e25b27a99b29
|
||||
github.com/gogf/gf/v2 v2.1.0-rc3.0.20220523034830-510fa3faf03f
|
||||
github.com/gogf/katyusha v0.4.0
|
||||
github.com/gogo/protobuf v1.3.2
|
||||
github.com/golang/protobuf v1.5.2
|
||||
github.com/polarismesh/polaris-go v1.1.0
|
||||
google.golang.org/grpc v1.46.0
|
||||
github.com/polarismesh/polaris-go v1.2.0-beta.0.0.20220517041223-596a6a63b00f
|
||||
google.golang.org/grpc v1.46.2
|
||||
)
|
||||
|
||||
replace (
|
||||
github.com/gogf/gf/contrib/drivers/mysql/v2 => ../contrib/drivers/mysql/
|
||||
github.com/gogf/gf/contrib/registry/etcd/v2 => ../contrib/registry/etcd/
|
||||
github.com/gogf/gf/contrib/registry/polaris/v2 => ../contrib/registry/polaris/
|
||||
github.com/gogf/gf/contrib/trace/jaeger/v2 => ../contrib/trace/jaeger/
|
||||
|
||||
@ -32,11 +32,9 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX
|
||||
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
|
||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/toml v1.0.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||
github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I=
|
||||
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
|
||||
github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw=
|
||||
github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw=
|
||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
@ -52,8 +50,6 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce
|
||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
|
||||
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
||||
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
|
||||
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
@ -66,8 +62,6 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
||||
github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI=
|
||||
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
@ -86,8 +80,6 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m
|
||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ=
|
||||
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
|
||||
github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
|
||||
@ -107,23 +99,20 @@ github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vb
|
||||
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
|
||||
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
|
||||
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
|
||||
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.2.1/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
|
||||
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/stdr v1.2.0/go.mod h1:YkVgnZu1ZjjL7xTxrfm/LLZBfkhTqSR1ydtm6jTKKwI=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
|
||||
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
|
||||
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
|
||||
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/gogf/katyusha v0.3.0/go.mod h1:AknlfKGS7HjZfLiz74Nd/eL2uq7bg+9aucZgfvXw8vQ=
|
||||
github.com/gogf/katyusha v0.3.1-0.20220128101623-e25b27a99b29 h1:s28bNu6QekQG3XFFB3G6YV3AGvQz8Uj4lBu/WXIeF28=
|
||||
github.com/gogf/katyusha v0.3.1-0.20220128101623-e25b27a99b29/go.mod h1:vb72az4+b2cn1gHfJ5n2sESbfQ0jM7iO55DNt2RQ7mc=
|
||||
github.com/gogf/katyusha/example v0.0.0-20220128090236-a633147589ae/go.mod h1:DSPRXlHUWIRpXa2v8eKpVh0eGwdCiqXBng3wnn8B62g=
|
||||
github.com/gogf/katyusha v0.4.0 h1:mQVfXHhzC+UQf11Q8HAk9IOhQZ1VMXqGUqezyywZUOs=
|
||||
github.com/gogf/katyusha v0.4.0/go.mod h1:nqsIWBsImnq9+OLlfB6iNef6ZLRyR2L1Bnk9h2aZvKs=
|
||||
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
||||
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||
@ -233,15 +222,13 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo=
|
||||
github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
|
||||
github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U=
|
||||
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
|
||||
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
|
||||
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
|
||||
@ -279,12 +266,13 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
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/polarismesh/polaris-go v1.1.0 h1:nFvn3q3XaVFhzF7pBnIySrN0ZZBwvbbYXC5r2DpsQN0=
|
||||
github.com/polarismesh/polaris-go v1.1.0/go.mod h1:tquawfjEKp1W3ffNJQSzhfditjjoZ7tvhOCElN7Efzs=
|
||||
github.com/polarismesh/polaris-go v1.2.0-beta.0.0.20220517041223-596a6a63b00f h1:IL2vXn/LjasI79p2X0/j8DZ+XnV5wgnjNpO1PQjn9Bc=
|
||||
github.com/polarismesh/polaris-go v1.2.0-beta.0.0.20220517041223-596a6a63b00f/go.mod h1:xXTl4b5ybYkwvXZA+nc1HNyLK/bsHUg08R4ewTa9axc=
|
||||
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
|
||||
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
|
||||
github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
|
||||
github.com/prometheus/client_golang v1.11.1/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
|
||||
github.com/prometheus/client_golang v1.12.1 h1:ZiaPsmm9uiBeaSMRznKsCDNtPCS0T3JVDGF+06gjBzk=
|
||||
github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY=
|
||||
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||
@ -303,8 +291,6 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O
|
||||
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
|
||||
github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU=
|
||||
github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
|
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
@ -314,7 +300,6 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykE
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
|
||||
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
|
||||
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
@ -333,42 +318,35 @@ github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
go.etcd.io/etcd/api/v3 v3.5.1 h1:v28cktvBq+7vGyJXF8G+rWJmj+1XUmMtqcLnH8hDocM=
|
||||
go.etcd.io/etcd/api/v3 v3.5.1/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.1 h1:XIQcHCFSG53bJETYeRJtIxdLv2EWRGxcfzR8lSnTH4E=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.1/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
|
||||
go.etcd.io/etcd/client/v3 v3.5.1 h1:oImGuV5LGKjCqXdjkMHCyWa5OO1gYKCnC/1sgdfj1Uk=
|
||||
go.etcd.io/etcd/client/v3 v3.5.1/go.mod h1:OnjH4M8OnAotwaB2l9bVgZzRFKru7/ZMoS46OtKyd3Q=
|
||||
go.etcd.io/etcd/api/v3 v3.5.4 h1:OHVyt3TopwtUQ2GKdd5wu3PmmipR4FTwCqoEjSyRdIc=
|
||||
go.etcd.io/etcd/api/v3 v3.5.4/go.mod h1:5GB2vv4A4AOn3yk7MftYGHkUfGtDHnEraIjym4dYz5A=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.4 h1:lrneYvz923dvC14R54XcA7FXoZ3mlGZAgmwhfm7HqOg=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.4/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
|
||||
go.etcd.io/etcd/client/v3 v3.5.4 h1:p83BUL3tAYS0OT/r0qglgc3M1JjhM0diV8DSWAhVXv4=
|
||||
go.etcd.io/etcd/client/v3 v3.5.4/go.mod h1:ZaRkVgBZC+L+dLCjTcF1hRXpgZXQPOvnA/Ak/gq3kiY=
|
||||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
||||
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
|
||||
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||
go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||
go.opentelemetry.io/otel v1.3.0/go.mod h1:PWIKzi6JCp7sM0k9yZ43VX+T345uNbAkDKwHVjb2PTs=
|
||||
go.opentelemetry.io/otel v1.7.0 h1:Z2lA3Tdch0iDcrhJXDIlC94XE+bxok1F9B+4Lz/lGsM=
|
||||
go.opentelemetry.io/otel v1.7.0/go.mod h1:5BdUoMIz5WEs0vt0CUEMtSSaTSHBBVwrhnz7+nrD5xk=
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.3.0 h1:HfydzioALdtcB26H5WHc4K47iTETJCdloL7VN579/L0=
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.3.0/go.mod h1:KoYHi1BtkUPncGSRtCe/eh1ijsnePhSkxwzz07vU0Fc=
|
||||
go.opentelemetry.io/otel/sdk v1.3.0/go.mod h1:rIo4suHNhQwBIPg9axF8V9CA72Wz2mKF1teNrup8yzs=
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.7.0 h1:wXgjiRldljksZkZrldGVe6XrG9u3kYDyQmkZwmm5dI0=
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.7.0/go.mod h1:PwQAOqBgqbLQRKlj466DuD2qyMjbtcPpfPfj+AqbSBs=
|
||||
go.opentelemetry.io/otel/sdk v1.7.0 h1:4OmStpcKVOfvDOgCt7UriAPtKolwIhxpnSNI/yK+1B0=
|
||||
go.opentelemetry.io/otel/sdk v1.7.0/go.mod h1:uTEOTwaqIVuTGiJN7ii13Ibp75wJmYUDe374q6cZwUU=
|
||||
go.opentelemetry.io/otel/trace v1.3.0/go.mod h1:c/VDhno8888bvQYmbYLqe41/Ldmr/KKunbvWM4/fEjk=
|
||||
go.opentelemetry.io/otel/trace v1.7.0 h1:O37Iogk1lEkMRXewVtZ1BBTVn5JEp8GrJvP92bJqC6o=
|
||||
go.opentelemetry.io/otel/trace v1.7.0/go.mod h1:fzLSB9nqR2eXzxPXb2JW9IKE+ScyXA48yyE4TNvoHqU=
|
||||
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
|
||||
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
|
||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
|
||||
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
|
||||
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
|
||||
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
|
||||
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
|
||||
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
|
||||
go.uber.org/multierr v1.7.0 h1:zaiO/rmgFjbmCXdSYJWQcdvOCsthmdaHfr3Gm2Kx4Ec=
|
||||
go.uber.org/multierr v1.7.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
|
||||
go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
|
||||
go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI=
|
||||
go.uber.org/zap v1.20.0 h1:N4oPlghZwYG55MlU6LXk/Zp00FVNE9X9wrYO8CEs4lc=
|
||||
go.uber.org/zap v1.20.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw=
|
||||
go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8=
|
||||
go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
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=
|
||||
@ -444,10 +422,10 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b
|
||||
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
|
||||
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk=
|
||||
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2 h1:NWy5+hlRbC7HK+PmcXVUmW1IMyFce7to56IUvhUFm7Y=
|
||||
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
@ -515,11 +493,11 @@ golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0=
|
||||
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 h1:nonptSpoQ4vQjyraW20DXPAglgQfVnM9ZC6MmNLMR60=
|
||||
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
@ -641,8 +619,8 @@ google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6D
|
||||
google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
||||
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
||||
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0=
|
||||
google.golang.org/genproto v0.0.0-20220126215142-9970aeb2e350 h1:YxHp5zqIcAShDEvRr5/0rVESVS+njYF68PSdazrNLJo=
|
||||
google.golang.org/genproto v0.0.0-20220126215142-9970aeb2e350/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
|
||||
google.golang.org/genproto v0.0.0-20220504150022-98cd25cafc72 h1:iif0mpUetMBqcQPUoq+JnCcmzvfpp8wRx515va8wP1c=
|
||||
google.golang.org/genproto v0.0.0-20220504150022-98cd25cafc72/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
|
||||
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
|
||||
@ -658,11 +636,9 @@ google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM
|
||||
google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
|
||||
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
|
||||
google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
|
||||
google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34=
|
||||
google.golang.org/grpc v1.42.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU=
|
||||
google.golang.org/grpc v1.44.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU=
|
||||
google.golang.org/grpc v1.46.0 h1:oCjezcn6g6A75TGoKYBPgKmVBLexhYLM6MebdrPApP8=
|
||||
google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
|
||||
google.golang.org/grpc v1.46.2 h1:u+MLGgVf7vRdjEYZ8wDFhAVNmhkbJ5hmrA1LMWK1CAQ=
|
||||
google.golang.org/grpc v1.46.2/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
|
||||
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=
|
||||
@ -675,8 +651,9 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj
|
||||
google.golang.org/protobuf v1.25.0/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.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
|
||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
|
||||
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
||||
@ -6,15 +6,18 @@ import (
|
||||
|
||||
"github.com/gogf/gf/contrib/registry/etcd/v2"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/gsel"
|
||||
"github.com/gogf/gf/v2/net/gsvc"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gsvc.SetRegistry(etcd.New(`127.0.0.1:2379`))
|
||||
gsel.SetBuilder(gsel.NewBuilderRoundRobin())
|
||||
|
||||
client := g.Client()
|
||||
for i := 0; i < 100; i++ {
|
||||
res, err := g.Client().Get(gctx.New(), `http://hello.svc/`)
|
||||
res, err := client.Get(gctx.New(), `http://hello.svc/`)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -1,13 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/polarismesh/polaris-go/api"
|
||||
"github.com/polarismesh/polaris-go/pkg/config"
|
||||
|
||||
"github.com/gogf/gf/contrib/registry/polaris/v2"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/gsvc"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
@ -15,8 +16,13 @@ import (
|
||||
|
||||
func main() {
|
||||
conf := config.NewDefaultConfiguration([]string{"192.168.100.222:8091"})
|
||||
conf.Consumer.LocalCache.SetPersistDir("/tmp/polaris/backup")
|
||||
err := api.SetLoggersDir("/tmp/polaris/log")
|
||||
if err != nil {
|
||||
g.Log().Fatal(context.Background(), err)
|
||||
}
|
||||
|
||||
gsvc.SetRegistry(polaris.NewWithConfig(conf, polaris.WithTTL(100)))
|
||||
gsvc.SetRegistry(polaris.NewWithConfig(conf, polaris.WithTTL(10)))
|
||||
|
||||
for i := 0; i < 100; i++ {
|
||||
res, err := g.Client().Get(gctx.New(), `http://hello.svc/`)
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/polarismesh/polaris-go/api"
|
||||
"github.com/polarismesh/polaris-go/pkg/config"
|
||||
|
||||
"github.com/gogf/gf/contrib/registry/polaris/v2"
|
||||
@ -11,9 +14,14 @@ import (
|
||||
|
||||
func main() {
|
||||
conf := config.NewDefaultConfiguration([]string{"192.168.100.222:8091"})
|
||||
conf.Consumer.LocalCache.SetPersistDir("/tmp/polaris/backup")
|
||||
err := api.SetLoggersDir("/tmp/polaris/log")
|
||||
if err != nil {
|
||||
g.Log().Fatal(context.Background(), err)
|
||||
}
|
||||
|
||||
// TTL egt 2*time.Second
|
||||
gsvc.SetRegistry(polaris.NewWithConfig(conf, polaris.WithTTL(100)))
|
||||
gsvc.SetRegistry(polaris.NewWithConfig(conf, polaris.WithTTL(10)))
|
||||
|
||||
s := g.Server(`hello.svc`)
|
||||
s.BindHandler("/", func(r *ghttp.Request) {
|
||||
|
||||
@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/katyusha/krpc"
|
||||
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
|
||||
|
||||
"github.com/gogf/gf/contrib/trace/jaeger/v2"
|
||||
"github.com/gogf/gf/example/trace/grpc_with_db/protobuf/user"
|
||||
@ -13,6 +13,7 @@ import (
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gcache"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/gogf/katyusha/krpc"
|
||||
)
|
||||
|
||||
type server struct{}
|
||||
|
||||
@ -5,6 +5,8 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
|
||||
|
||||
"github.com/gogf/gf/contrib/trace/jaeger/v2"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
|
||||
@ -53,45 +53,24 @@ func Database(name ...string) gdb.DB {
|
||||
if v, _ := Config().Get(ctx, configNodeKey); !v.IsEmpty() {
|
||||
configMap = v.Map()
|
||||
}
|
||||
// No configuration found, it formats and panics error.
|
||||
if len(configMap) == 0 && !gdb.IsConfigured() {
|
||||
// File configuration object checks.
|
||||
var (
|
||||
err error
|
||||
configFilePath string
|
||||
)
|
||||
var err error
|
||||
if fileConfig, ok := Config().GetAdapter().(*gcfg.AdapterFile); ok {
|
||||
if configFilePath, _ = fileConfig.GetFilePath(); configFilePath == "" {
|
||||
var (
|
||||
exampleFileName = "config.example.toml"
|
||||
exampleConfigFilePath string
|
||||
)
|
||||
if exampleConfigFilePath, _ = fileConfig.GetFilePath(exampleFileName); exampleConfigFilePath != "" {
|
||||
err = gerror.NewCodef(
|
||||
gcode.CodeMissingConfiguration,
|
||||
`configuration file "%s" not found, but found "%s", did you miss renaming the example configuration file?`,
|
||||
fileConfig.GetFileName(),
|
||||
exampleFileName,
|
||||
)
|
||||
} else {
|
||||
err = gerror.NewCodef(
|
||||
gcode.CodeMissingConfiguration,
|
||||
`configuration file "%s" not found, did you miss the configuration file or the misspell the configuration file name?`,
|
||||
fileConfig.GetFileName(),
|
||||
)
|
||||
}
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if _, err = fileConfig.GetFilePath(); err != nil {
|
||||
panic(gerror.WrapCode(gcode.CodeMissingConfiguration, err,
|
||||
`configuration not found, did you miss the configuration file or the misspell the configuration file name`,
|
||||
))
|
||||
}
|
||||
}
|
||||
// Panic if nothing found in Config object or in gdb configuration.
|
||||
if len(configMap) == 0 && !gdb.IsConfigured() {
|
||||
err = gerror.NewCodef(
|
||||
panic(gerror.NewCodef(
|
||||
gcode.CodeMissingConfiguration,
|
||||
`database initialization failed: "%s" node not found, is configuration file or configuration node missing?`,
|
||||
`database initialization failed: configuration missing for database node "%s"`,
|
||||
consts.ConfigNodeNameDatabase,
|
||||
)
|
||||
panic(err)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
136
internal/deepcopy/deepcopy.go
Normal file
136
internal/deepcopy/deepcopy.go
Normal file
@ -0,0 +1,136 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
// Package deepcopy makes deep copies of things using reflection.
|
||||
//
|
||||
// This package is maintained from: https://github.com/mohae/deepcopy
|
||||
package deepcopy
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Interface for delegating copy process to type
|
||||
type Interface interface {
|
||||
DeepCopy() interface{}
|
||||
}
|
||||
|
||||
// Copy creates a deep copy of whatever is passed to it and returns the copy
|
||||
// in an interface{}. The returned value will need to be asserted to the
|
||||
// correct type.
|
||||
func Copy(src interface{}) interface{} {
|
||||
if src == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Copy by type assertion.
|
||||
switch r := src.(type) {
|
||||
case
|
||||
int, int8, int16, int32, int64,
|
||||
uint, uint8, uint16, uint32, uint64,
|
||||
float32, float64,
|
||||
complex64, complex128,
|
||||
string,
|
||||
bool:
|
||||
return r
|
||||
|
||||
default:
|
||||
if v, ok := src.(Interface); ok {
|
||||
return v.DeepCopy()
|
||||
}
|
||||
var (
|
||||
original = reflect.ValueOf(src) // Make the interface a reflect.Value
|
||||
dst = reflect.New(original.Type()).Elem() // Make a copy of the same type as the original.
|
||||
)
|
||||
// Recursively copy the original.
|
||||
copyRecursive(original, dst)
|
||||
// Return the copy as an interface.
|
||||
return dst.Interface()
|
||||
}
|
||||
}
|
||||
|
||||
// copyRecursive does the actual copying of the interface. It currently has
|
||||
// limited support for what it can handle. Add as needed.
|
||||
func copyRecursive(original, cpy reflect.Value) {
|
||||
// check for implement deepcopy.Interface
|
||||
if original.CanInterface() {
|
||||
if copier, ok := original.Interface().(Interface); ok {
|
||||
cpy.Set(reflect.ValueOf(copier.DeepCopy()))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// handle according to original's Kind
|
||||
switch original.Kind() {
|
||||
case reflect.Ptr:
|
||||
// Get the actual value being pointed to.
|
||||
originalValue := original.Elem()
|
||||
|
||||
// if it isn't valid, return.
|
||||
if !originalValue.IsValid() {
|
||||
return
|
||||
}
|
||||
cpy.Set(reflect.New(originalValue.Type()))
|
||||
copyRecursive(originalValue, cpy.Elem())
|
||||
|
||||
case reflect.Interface:
|
||||
// If this is a nil, don't do anything
|
||||
if original.IsNil() {
|
||||
return
|
||||
}
|
||||
// Get the value for the interface, not the pointer.
|
||||
originalValue := original.Elem()
|
||||
|
||||
// Get the value by calling Elem().
|
||||
copyValue := reflect.New(originalValue.Type()).Elem()
|
||||
copyRecursive(originalValue, copyValue)
|
||||
cpy.Set(copyValue)
|
||||
|
||||
case reflect.Struct:
|
||||
t, ok := original.Interface().(time.Time)
|
||||
if ok {
|
||||
cpy.Set(reflect.ValueOf(t))
|
||||
return
|
||||
}
|
||||
// Go through each field of the struct and copy it.
|
||||
for i := 0; i < original.NumField(); i++ {
|
||||
// The Type's StructField for a given field is checked to see if StructField.PkgPath
|
||||
// is set to determine if the field is exported or not because CanSet() returns false
|
||||
// for settable fields. I'm not sure why. -mohae
|
||||
if original.Type().Field(i).PkgPath != "" {
|
||||
continue
|
||||
}
|
||||
copyRecursive(original.Field(i), cpy.Field(i))
|
||||
}
|
||||
|
||||
case reflect.Slice:
|
||||
if original.IsNil() {
|
||||
return
|
||||
}
|
||||
// Make a new slice and copy each element.
|
||||
cpy.Set(reflect.MakeSlice(original.Type(), original.Len(), original.Cap()))
|
||||
for i := 0; i < original.Len(); i++ {
|
||||
copyRecursive(original.Index(i), cpy.Index(i))
|
||||
}
|
||||
|
||||
case reflect.Map:
|
||||
if original.IsNil() {
|
||||
return
|
||||
}
|
||||
cpy.Set(reflect.MakeMap(original.Type()))
|
||||
for _, key := range original.MapKeys() {
|
||||
originalValue := original.MapIndex(key)
|
||||
copyValue := reflect.New(originalValue.Type()).Elem()
|
||||
copyRecursive(originalValue, copyValue)
|
||||
copyKey := Copy(key.Interface())
|
||||
cpy.SetMapIndex(reflect.ValueOf(copyKey), copyValue)
|
||||
}
|
||||
|
||||
default:
|
||||
cpy.Set(original)
|
||||
}
|
||||
}
|
||||
1110
internal/deepcopy/deepcopy_test.go
Normal file
1110
internal/deepcopy/deepcopy_test.go
Normal file
File diff suppressed because it is too large
Load Diff
@ -22,12 +22,12 @@ const (
|
||||
)
|
||||
|
||||
type discoveryNode struct {
|
||||
service *gsvc.Service
|
||||
service gsvc.Service
|
||||
address string
|
||||
}
|
||||
|
||||
// Service is the client discovery service.
|
||||
func (n *discoveryNode) Service() *gsvc.Service {
|
||||
func (n *discoveryNode) Service() gsvc.Service {
|
||||
return n.service
|
||||
}
|
||||
|
||||
@ -49,11 +49,11 @@ func internalMiddlewareDiscovery(c *Client, r *http.Request) (response *Response
|
||||
if gsvc.GetRegistry() == nil {
|
||||
return c.Next(r)
|
||||
}
|
||||
var service *gsvc.Service
|
||||
service, err = gsvc.GetWithWatch(ctx, r.URL.Host, func(service *gsvc.Service) {
|
||||
intlog.Printf(ctx, `http client watching service "%s" changed`, service.KeyWithoutEndpoints())
|
||||
if v := clientSelectorMap.Get(service.KeyWithoutEndpoints()); v != nil {
|
||||
if err = updateSelectorNodesByService(v.(gsel.Selector), service); err != nil {
|
||||
var service gsvc.Service
|
||||
service, err = gsvc.GetAndWatch(ctx, r.URL.Host, func(service gsvc.Service) {
|
||||
intlog.Printf(ctx, `http client watching service "%s" changed`, service.GetPrefix())
|
||||
if v := clientSelectorMap.Get(service.GetPrefix()); v != nil {
|
||||
if err = updateSelectorNodesByService(ctx, v.(gsel.Selector), service); err != nil {
|
||||
intlog.Errorf(context.Background(), `%+v`, err)
|
||||
}
|
||||
}
|
||||
@ -65,15 +65,22 @@ func internalMiddlewareDiscovery(c *Client, r *http.Request) (response *Response
|
||||
return c.Next(r)
|
||||
}
|
||||
// Balancer.
|
||||
selectorMapKey := service.KeyWithoutEndpoints()
|
||||
selector := clientSelectorMap.GetOrSetFuncLock(selectorMapKey, func() interface{} {
|
||||
intlog.Printf(ctx, `http client create selector for service "%s"`, selectorMapKey)
|
||||
return gsel.GetBuilder().Build()
|
||||
}).(gsel.Selector)
|
||||
// Update selector nodes.
|
||||
if err = updateSelectorNodesByService(selector, service); err != nil {
|
||||
var (
|
||||
selectorMapKey = service.GetPrefix()
|
||||
selectorMapValue = clientSelectorMap.GetOrSetFuncLock(selectorMapKey, func() interface{} {
|
||||
intlog.Printf(ctx, `http client create selector for service "%s"`, selectorMapKey)
|
||||
selector := gsel.GetBuilder().Build()
|
||||
// Update selector nodes.
|
||||
if err = updateSelectorNodesByService(ctx, selector, service); err != nil {
|
||||
return nil
|
||||
}
|
||||
return selector
|
||||
})
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := selectorMapValue.(gsel.Selector)
|
||||
// Pick one node from multiple addresses.
|
||||
node, done, err := selector.Pick(ctx)
|
||||
if err != nil {
|
||||
@ -87,13 +94,13 @@ func internalMiddlewareDiscovery(c *Client, r *http.Request) (response *Response
|
||||
return c.Next(r)
|
||||
}
|
||||
|
||||
func updateSelectorNodesByService(selector gsel.Selector, service *gsvc.Service) error {
|
||||
nodes := make([]gsel.Node, 0)
|
||||
for _, address := range service.Endpoints {
|
||||
func updateSelectorNodesByService(ctx context.Context, selector gsel.Selector, service gsvc.Service) error {
|
||||
nodes := make(gsel.Nodes, 0)
|
||||
for _, endpoint := range service.GetEndpoints() {
|
||||
nodes = append(nodes, &discoveryNode{
|
||||
service: service,
|
||||
address: address,
|
||||
address: endpoint.String(),
|
||||
})
|
||||
}
|
||||
return selector.Update(nodes)
|
||||
return selector.Update(ctx, nodes)
|
||||
}
|
||||
|
||||
@ -118,6 +118,26 @@ func ExampleNew() {
|
||||
// {"id":1,"name":"john"}
|
||||
}
|
||||
|
||||
func ExampleClient_Clone() {
|
||||
var (
|
||||
ctx = gctx.New()
|
||||
client = gclient.New()
|
||||
)
|
||||
|
||||
client.SetCookie("key", "value")
|
||||
cloneClient := client.Clone()
|
||||
|
||||
if r, err := cloneClient.Get(ctx, "http://127.0.0.1:8999/var/json"); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
defer r.Close()
|
||||
fmt.Println(r.ReadAllString())
|
||||
}
|
||||
|
||||
// Output:
|
||||
// {"id":1,"name":"john"}
|
||||
}
|
||||
|
||||
func ExampleNew_MultiConn_Recommend() {
|
||||
var (
|
||||
ctx = gctx.New()
|
||||
|
||||
@ -9,7 +9,9 @@ package gclient_test
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/debug/gdebug"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"testing"
|
||||
@ -532,3 +534,27 @@ func Test_WebSocketClient(t *testing.T) {
|
||||
t.Assert(data, msg)
|
||||
})
|
||||
}
|
||||
|
||||
func TestLoadKeyCrt(t *testing.T) {
|
||||
var (
|
||||
testCrtFile = gfile.Dir(gdebug.CallerFilePath()) + gfile.Separator + "testdata/upload/file1.txt"
|
||||
testKeyFile = gfile.Dir(gdebug.CallerFilePath()) + gfile.Separator + "testdata/upload/file2.txt"
|
||||
crtFile = gfile.Dir(gdebug.CallerFilePath()) + gfile.Separator + "testdata/server.crt"
|
||||
keyFile = gfile.Dir(gdebug.CallerFilePath()) + gfile.Separator + "testdata/server.key"
|
||||
tlsConfig = &tls.Config{}
|
||||
)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
tlsConfig, _ = gclient.LoadKeyCrt("crtFile", "keyFile")
|
||||
t.AssertNil(tlsConfig)
|
||||
|
||||
tlsConfig, _ = gclient.LoadKeyCrt(crtFile, "keyFile")
|
||||
t.AssertNil(tlsConfig)
|
||||
|
||||
tlsConfig, _ = gclient.LoadKeyCrt(testCrtFile, testKeyFile)
|
||||
t.AssertNil(tlsConfig)
|
||||
|
||||
tlsConfig, _ = gclient.LoadKeyCrt(crtFile, keyFile)
|
||||
t.AssertNE(tlsConfig, nil)
|
||||
})
|
||||
}
|
||||
|
||||
20
net/gclient/testdata/server.crt
vendored
Normal file
20
net/gclient/testdata/server.crt
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDVzCCAj+gAwIBAgIJAPRQQvW4UaTJMA0GCSqGSIb3DQEBCwUAMEIxCzAJBgNV
|
||||
BAYTAlhYMRUwEwYDVQQHDAxEZWZhdWx0IENpdHkxHDAaBgNVBAoME0RlZmF1bHQg
|
||||
Q29tcGFueSBMdGQwHhcNMTcxMTA2MDMwNjUzWhcNMjcxMTA0MDMwNjUzWjBCMQsw
|
||||
CQYDVQQGEwJYWDEVMBMGA1UEBwwMRGVmYXVsdCBDaXR5MRwwGgYDVQQKDBNEZWZh
|
||||
dWx0IENvbXBhbnkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA
|
||||
rvm9LVnIIPlimBCiNzhLmKqe8soWN7ZND+cN8myD8mcGVZblp01JZbR4n1btEekU
|
||||
rl3oNr/6aXhLml4ijre150Z73q31XMarlgBtbkbs4Lu22rlLZg/u2hzs9f1aF1VT
|
||||
qXzru+2ifcYR15Ptoyr8t12dYSQ9YXP7LwzghE9oWw52w0LxlNL0cNq2muSMTelQ
|
||||
xBU3OuAOdy7dPhiHvkpCCZ5SmwZuK8IpSX0/pJUgDkmd3zfKaaOE4JdLKJ5lWsGF
|
||||
RgM8leygKfvW4hwguEh7S1UG9CT/6jqPpyiPii3Qc4dxrogmiTPlFpYWY8bFNa9s
|
||||
iuwr8KFPPZIIwxZgDLAvywIDAQABo1AwTjAdBgNVHQ4EFgQUMsBb4Dhl4OZl+xw8
|
||||
Pl2wkRhUVi0wHwYDVR0jBBgwFoAUMsBb4Dhl4OZl+xw8Pl2wkRhUVi0wDAYDVR0T
|
||||
BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAQEaUz59HZHbPt4Etv4zASn3mFJeR
|
||||
QZHmUnKhVjB163xvHoN46GJmc4VnWahOd1a7i7b+qK6AnFzKI5zmZ4z5ZrjwqZiG
|
||||
epvAQ4FVbZy1nzMjBXQIyAkiDgbdjASvOUoE4OlKA3jLH7H204K3jhpaFTKVQNeY
|
||||
BGEALlKdveQUjlp5YTk38NrrZg0yzGDBUQ6X6PCYB+kdEOOpyx6061jxgIVKuBaY
|
||||
37I88vGcC9C3PVhYvDcilMkEcUPnp7DRMiZpXU7DraCWlWbr/b+47NkTPBWiNiLC
|
||||
nlfGdCGuL0ylZ16nEpkvZVUWiAijh3sUYbz1dbBACw+8dTG/+vlKUuz/hA==
|
||||
-----END CERTIFICATE-----
|
||||
27
net/gclient/testdata/server.key
vendored
Normal file
27
net/gclient/testdata/server.key
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEowIBAAKCAQEArvm9LVnIIPlimBCiNzhLmKqe8soWN7ZND+cN8myD8mcGVZbl
|
||||
p01JZbR4n1btEekUrl3oNr/6aXhLml4ijre150Z73q31XMarlgBtbkbs4Lu22rlL
|
||||
Zg/u2hzs9f1aF1VTqXzru+2ifcYR15Ptoyr8t12dYSQ9YXP7LwzghE9oWw52w0Lx
|
||||
lNL0cNq2muSMTelQxBU3OuAOdy7dPhiHvkpCCZ5SmwZuK8IpSX0/pJUgDkmd3zfK
|
||||
aaOE4JdLKJ5lWsGFRgM8leygKfvW4hwguEh7S1UG9CT/6jqPpyiPii3Qc4dxrogm
|
||||
iTPlFpYWY8bFNa9siuwr8KFPPZIIwxZgDLAvywIDAQABAoIBAQCRYfXaWY/cPfm6
|
||||
qY9u3DqLpbCdwGWHctRC01MWSy2y2gE8Wj2ErcW/WJ0kn4Ao8oX5fxMzcn2o5ofC
|
||||
wlZqSKA+gqTnV5jXtkbZQo+qIgotjCqZP34zVie6WHBWz2PsoTv7Rk1D/2WUpV8r
|
||||
xMCdY1lJLeJW1Vqev1REOqnNpYDqrhBsCCNn0vvCOS+/UbTbJ2d4sw3BuqGfd2Uk
|
||||
eIXSlwkODKf2Tk3b4tktC7I0XZfBeO1DEpBJAYP+zPTt/we/Kne6FI/squdephJL
|
||||
JMj30bSZ0jpgP/K6otEiE3pfdzijTFPjw8ayU1yuZZMSRLJtFKbSfSNGUfXVHwZP
|
||||
6ygv91DJAoGBAOIawxKzSVJxz6yvaxh2Zxnib33TmpyWcDVKje/bk88hxEXm7C3Q
|
||||
OPMGbfy37mc6jDoH2erv2GFDFRCezHKS+OEN5heZnL3m/c6E0A4K/V9VUDSnABLi
|
||||
jmDRw45mDZq9edGxkvydHYMdJhH+hbbWrxr8LQtsBLuaDzLEkHa8cscdAoGBAMYc
|
||||
Wd4x3fBCA2/Xd98+ZTpYhtbYDvIYl2gfVLSiLuvf3ZgnWozibCOJg5DVh/0vCS+G
|
||||
ct4Ga3e17qRXZOXuSoZdBIh7nV2mQ0+zc+4ZE7UE0cAU4KYkGBabt1J4HdIxCOUB
|
||||
60smideKfFKurh5OCxSP76tIwOhcSXpduhmb/VYHAoGAfe7V89Zz4j2No+rYRXm9
|
||||
FwetfXGcTdbkjGoIAC5WdymhfiWOKj4tWf6cyANR/6D2dWPmFhqcdB++3dD0omQF
|
||||
xqPNIhvm10aO2rXSg9/PG4gS8iCJw/r3vilXODrTHPqnnQnAin6f72UOzTrsEtgk
|
||||
E22dUR1KzYqTKH2e0ONJMmkCgYBlcFzftd7zR4nk+YoKiDNi9bNNTOISOl9EVE6W
|
||||
Ezk9U6puXzAxVTqT07THM17nV+83I3urjdP3PvPLuGgUh7gnJnfMvqbsLdbnd3aT
|
||||
4slBdg9EcCw7Rd4DrYXnt1Nlre/k+t+U4k3QTLutxn2nTMTFqZHJvX3xPFfvTRCe
|
||||
Tk4gfwKBgDDo8/NvOZQJi+A5qJFooWkm5mFjsq2RTuOE5dZlgfNp3FzbJ1wcC0X5
|
||||
ifOWAMGIyw0m68Q07fL2rsfvfB69iB6oRv6WCuUXH2f5THgUeVxxYHHUfGJQQkcu
|
||||
XJXnZDH/OB1Pg674BzC6dGsHDM19kgWmr0aVQK4jueqxsm5pchEr
|
||||
-----END RSA PRIVATE KEY-----
|
||||
@ -16,10 +16,10 @@ import (
|
||||
|
||||
"github.com/gogf/gf/v2/container/gmap"
|
||||
"github.com/gogf/gf/v2/container/gtype"
|
||||
"github.com/gogf/gf/v2/net/goai"
|
||||
"github.com/gogf/gf/v2/net/gsvc"
|
||||
"github.com/gogf/gf/v2/os/gcache"
|
||||
"github.com/gogf/gf/v2/os/gsession"
|
||||
"github.com/gogf/gf/v2/protocol/goai"
|
||||
)
|
||||
|
||||
type (
|
||||
@ -37,7 +37,7 @@ type (
|
||||
statusHandlerMap map[string][]HandlerFunc // Custom status handler map.
|
||||
sessionManager *gsession.Manager // Session manager.
|
||||
openapi *goai.OpenApiV3 // The OpenApi specification management object.
|
||||
service *gsvc.Service // The service for Registry.
|
||||
service gsvc.Service // The service for Registry.
|
||||
}
|
||||
|
||||
// Router object.
|
||||
|
||||
@ -16,6 +16,7 @@ import (
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/internal/intlog"
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/util/grand"
|
||||
@ -27,6 +28,11 @@ type UploadFile struct {
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface MarshalJSON for json.Marshal.
|
||||
func (f UploadFile) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(f.FileHeader)
|
||||
}
|
||||
|
||||
// UploadFiles is an array type of *UploadFile.
|
||||
type UploadFiles []*UploadFile
|
||||
|
||||
|
||||
@ -25,6 +25,7 @@ import (
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/internal/intlog"
|
||||
"github.com/gogf/gf/v2/net/ghttp/internal/swaggerui"
|
||||
"github.com/gogf/gf/v2/net/goai"
|
||||
"github.com/gogf/gf/v2/os/gcache"
|
||||
"github.com/gogf/gf/v2/os/genv"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
@ -32,7 +33,6 @@ import (
|
||||
"github.com/gogf/gf/v2/os/gproc"
|
||||
"github.com/gogf/gf/v2/os/gsession"
|
||||
"github.com/gogf/gf/v2/os/gtimer"
|
||||
"github.com/gogf/gf/v2/protocol/goai"
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
|
||||
@ -10,7 +10,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/internal/intlog"
|
||||
"github.com/gogf/gf/v2/protocol/goai"
|
||||
"github.com/gogf/gf/v2/net/goai"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
)
|
||||
|
||||
|
||||
@ -25,6 +25,7 @@ func (s *Server) doServiceRegister() {
|
||||
protocol = gsvc.DefaultProtocol
|
||||
insecure = true
|
||||
address = s.config.Address
|
||||
err error
|
||||
)
|
||||
if address == "" {
|
||||
address = s.config.HTTPSAddr
|
||||
@ -45,13 +46,13 @@ func (s *Server) doServiceRegister() {
|
||||
gsvc.MDProtocol: protocol,
|
||||
gsvc.MDInsecure: insecure,
|
||||
}
|
||||
s.service = &gsvc.Service{
|
||||
s.service = &gsvc.LocalService{
|
||||
Name: s.GetName(),
|
||||
Endpoints: []string{fmt.Sprintf(`%s:%s`, ip, port)},
|
||||
Endpoints: gsvc.NewEndpoints(fmt.Sprintf(`%s:%s`, ip, port)),
|
||||
Metadata: metadata,
|
||||
}
|
||||
s.Logger().Debugf(ctx, `service register: %+v`, s.service)
|
||||
if err := gsvc.Register(ctx, s.service); err != nil {
|
||||
if s.service, err = gsvc.Register(ctx, s.service); err != nil {
|
||||
s.Logger().Fatalf(ctx, `%+v`, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ import (
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/internal/utils"
|
||||
"github.com/gogf/gf/v2/protocol/goai"
|
||||
"github.com/gogf/gf/v2/net/goai"
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gmeta"
|
||||
|
||||
@ -32,7 +32,7 @@ const (
|
||||
</head>
|
||||
<body>
|
||||
<redoc spec-url="{SwaggerUIDocUrl}" show-object-schema-examples="true"></redoc>
|
||||
<script src="https://unpkg.com/redoc@latest/bundles/redoc.standalone.js"> </script>
|
||||
<script src="https://unpkg.com/redoc@2.0.0-rc.70/bundles/redoc.standalone.js"> </script>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
|
||||
@ -216,3 +216,28 @@ func Test_Params_Strict_Route_File_Single(t *testing.T) {
|
||||
t.Assert(gfile.GetContents(dstPath), gfile.GetContents(srcPath))
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Params_File_Upload_Required(t *testing.T) {
|
||||
type Req struct {
|
||||
gmeta.Meta `method:"post" mime:"multipart/form-data"`
|
||||
File *ghttp.UploadFile `type:"file" v:"required#upload file is required"`
|
||||
}
|
||||
type Res struct{}
|
||||
|
||||
s := g.Server(guid.S())
|
||||
s.Use(ghttp.MiddlewareHandlerResponse)
|
||||
s.BindHandler("/upload/required", func(ctx context.Context, req *Req) (res *Res, err error) {
|
||||
return
|
||||
})
|
||||
s.SetDumpRouterMap(false)
|
||||
s.Start()
|
||||
defer s.Shutdown()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
// file is empty
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
|
||||
content := client.PostContent(ctx, "/upload/required")
|
||||
t.Assert(content, `{"code":51,"message":"upload file is required","data":null}`)
|
||||
})
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user