Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Vladimir Barsukov
zGo
Commits
d34b26e7
Commit
d34b26e7
authored
Nov 18, 2023
by
Vladimir Barsukov
Browse files
fix
parent
92afcbbd
Changes
5
Show whitespace changes
Inline
Side-by-side
zdb/any.go
View file @
d34b26e7
...
...
@@ -55,7 +55,7 @@ func (d *Pool) qAny(q *Conn, dst any, sql string, args ...any) error {
}
else
if
f
.
DataTypeOID
==
pgtype
.
NumericOID
{
ff
,
_
:=
v
[
i
]
.
(
pgtype
.
Numeric
)
.
Float64Value
()
r
[
f
.
Name
]
=
ff
.
Float64
}
else
if
f
.
DataTypeOID
==
pgtype
.
TimestampOID
&&
d
.
UseGoTime
==
false
{
}
else
if
f
.
DataTypeOID
==
pgtype
.
TimestampOID
&&
!
d
.
UseGoTime
{
r
[
f
.
Name
]
=
v
[
i
]
.
(
time
.
Time
)
.
Format
(
d
.
PgTsFormat
)
}
else
if
f
.
DataTypeOID
==
pgtype
.
UUIDOID
{
bb
:=
v
[
i
]
.
([
16
]
byte
)
...
...
zdb/pool.go
View file @
d34b26e7
...
...
@@ -354,14 +354,14 @@ func (d *Pool) IsAlive() bool {
func
(
d
*
Pool
)
prepare
(
sql
string
,
param
map
[
string
]
any
)
string
{
for
n
,
t
:=
range
param
{
switch
t
.
(
type
)
{
switch
tv
:=
t
.
(
type
)
{
case
time
.
Time
:
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
fmt
.
Sprintf
(
"'%s'"
,
t
.
(
time
.
Time
)
.
UTC
()
.
Format
(
time
.
DateTime
)))
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
fmt
.
Sprintf
(
"'%s'"
,
t
v
.
UTC
()
.
Format
(
time
.
DateTime
)))
case
*
time
.
Time
:
if
t
.
(
*
time
.
Time
)
==
nil
{
if
t
v
==
nil
{
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
"NULL"
)
}
else
{
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
fmt
.
Sprintf
(
"'%s'"
,
t
.
(
*
time
.
Time
)
.
UTC
()
.
Format
(
time
.
DateTime
)))
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
fmt
.
Sprintf
(
"'%s'"
,
t
v
.
UTC
()
.
Format
(
time
.
DateTime
)))
}
case
nil
:
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
"NULL"
)
...
...
@@ -381,35 +381,35 @@ func (d *Pool) prepare(sql string, param map[string]any) string {
if
t
.
(
string
)
==
"NULL"
{
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
"NULL"
)
}
else
{
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
fmt
.
Sprintf
(
"'%v'"
,
strings
.
ReplaceAll
(
t
.
(
string
)
,
"'"
,
"''"
)))
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
fmt
.
Sprintf
(
"'%v'"
,
strings
.
ReplaceAll
(
t
v
,
"'"
,
"''"
)))
}
case
*
int
:
if
t
.
(
*
int
)
==
nil
{
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
"NULL"
)
}
else
{
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
fmt
.
Sprintf
(
"%v"
,
*
t
.
(
*
int
)
))
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
fmt
.
Sprintf
(
"%v"
,
*
t
v
))
}
case
*
bool
:
if
t
.
(
*
bool
)
==
nil
{
if
t
v
==
nil
{
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
"NULL"
)
}
else
{
if
*
t
.
(
*
bool
)
{
if
*
t
v
{
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
"TRUE"
)
}
else
{
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
"FALSE"
)
}
}
case
*
int64
:
if
t
.
(
*
int64
)
==
nil
{
if
t
v
==
nil
{
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
"NULL"
)
}
else
{
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
fmt
.
Sprintf
(
"%v"
,
*
t
.
(
*
int64
)
))
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
fmt
.
Sprintf
(
"%v"
,
*
t
v
))
}
case
*
float64
:
if
t
.
(
*
float64
)
==
nil
{
if
t
v
==
nil
{
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
"NULL"
)
}
else
{
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
fmt
.
Sprintf
(
"%v"
,
*
t
.
(
*
float64
)
))
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
fmt
.
Sprintf
(
"%v"
,
*
t
v
))
}
case
int
,
int64
:
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
fmt
.
Sprintf
(
"%v"
,
t
))
...
...
zq/zq.go
View file @
d34b26e7
package
zq
import
(
"fmt"
"git.barsukov.pro/barsukov/zgo/zatomic"
"git.barsukov.pro/barsukov/zgo/z
wg
"
"git.barsukov.pro/barsukov/zgo/z
quit
"
"runtime"
)
type
ZQ
struct
{
WorkerCounter
*
zatomic
.
Int
WorkerFn
func
(
any
)
JobsWg
*
z
wg
.
Zwg
ZQuit
*
z
quit
.
ZQuit
complete
chan
bool
jobs
chan
any
...
...
@@ -19,7 +20,7 @@ func New(qtyWorkers int, buff int, fn func(any)) *ZQ {
q
:=
&
ZQ
{
WorkerCounter
:
zatomic
.
New
(),
WorkerFn
:
fn
,
JobsWg
:
zwg
.
New
(),
ZQuit
:
zquit
.
Default
(),
jobs
:
make
(
chan
any
,
buff
),
complete
:
make
(
chan
bool
),
}
...
...
@@ -68,6 +69,11 @@ func Default64(fn func(any)) *ZQ {
return
DefaultN
(
64
,
fn
)
}
func
(
q
*
ZQ
)
WithZQuit
(
quit
*
zquit
.
ZQuit
)
*
ZQ
{
q
.
ZQuit
=
quit
return
q
}
func
(
q
*
ZQ
)
AddWorker
(
delta
int
)
{
if
delta
<
1
{
for
i
:=
0
;
i
<
delta
*-
1
;
i
++
{
...
...
@@ -89,7 +95,7 @@ func (q *ZQ) AddWorker(delta int) {
return
case
j
:=
<-
q
.
jobs
:
q
.
WorkerFn
(
j
)
q
.
JobsWg
.
Done
()
q
.
ZQuit
.
Done
()
}
}
}()
...
...
@@ -100,15 +106,19 @@ func (q *ZQ) RemoveWorker() {
q
.
AddWorker
(
-
1
)
}
func
(
q
*
ZQ
)
AddJob
(
a
any
)
*
ZQ
{
q
.
JobsWg
.
Inc
()
func
(
q
*
ZQ
)
AddJob
(
a
any
)
error
{
if
q
.
ZQuit
.
IsQuit
()
{
return
fmt
.
Errorf
(
"quit"
)
}
q
.
ZQuit
.
Inc
()
q
.
jobs
<-
a
return
q
return
nil
}
func
(
q
*
ZQ
)
Wait
()
{
q
.
JobsWg
.
Wait
()
q
.
ZQuit
.
Wait
()
}
func
(
q
*
ZQ
)
Quit
()
{
...
...
zquit/pool.go
View file @
d34b26e7
package
zquit
import
(
"log"
"os"
"os/signal"
"syscall"
...
...
@@ -28,13 +29,25 @@ func (p *Pool) Add(z *ZQuit) {
p
.
items
=
append
(
p
.
items
,
z
)
}
func
(
p
*
Pool
)
PrintStat
()
{
func
(
p
*
Pool
)
PrintStat
(
sec
int
)
{
go
func
()
{
for
{
<-
time
.
After
(
time
.
Second
*
time
.
Duration
(
sec
))
s
:=
""
for
_
,
i
:=
range
p
.
items
{
i
.
PrintStat
()
s
+=
i
.
GetStat
()
+
"; "
}
log
.
Printf
(
"Z_QUIT: %s"
,
s
)
}
}()
}
func
(
p
*
Pool
)
Wait
()
{
for
_
,
i
:=
range
p
.
items
{
i
.
Shutdown
()
}
for
_
,
i
:=
range
p
.
items
{
i
.
Wait
()
}
...
...
zquit/zquit.go
View file @
d34b26e7
package
zquit
import
(
"fmt"
"git.barsukov.pro/barsukov/zgo/zwg"
"github.com/gin-gonic/gin"
"log"
...
...
@@ -95,11 +96,14 @@ func (q *ZQuit) Middleware(c *gin.Context) {
c
.
Next
()
}
func
(
q
*
ZQuit
)
PrintStat
()
{
func
(
q
*
ZQuit
)
GetStat
()
string
{
return
fmt
.
Sprintf
(
"%s: %v"
,
q
.
Name
,
q
.
Val
())
}
func
(
q
*
ZQuit
)
PrintStat
(
sec
int
)
{
go
func
()
{
for
{
<-
time
.
After
(
time
.
Second
)
log
.
Printf
(
"Z_QUIT:
LOCKS[%s]: %v"
,
q
.
Name
,
q
.
Val
())
<-
time
.
After
(
time
.
Second
*
time
.
Duration
(
sec
)
)
log
.
Printf
(
"Z_QUIT:
%s"
,
q
.
GetStat
())
}
}()
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment