1
0
Fork 0
mirror of https://gitlab.alpinelinux.org/alpine/aports.git synced 2025-07-15 20:25:17 +03:00
aports/testing/heplify-server/fix-go-vet-errors.patch
2021-06-07 18:30:14 +00:00

77 lines
2.5 KiB
Diff

From e58baf45920806a959405e4b87223f1dd246a374 Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Mon, 7 Jun 2021 18:50:27 +0200
Subject: [PATCH] Fix go vet errors (#473)
Fixes go vet errors:
# github.com/sipcapture/heplify-server/rotator
rotator/rotator.go:222:2: unreachable code
# github.com/sipcapture/heplify-server/decoder
decoder/decoder.go:299:35: possible misuse of reflect.SliceHeader
see https://github.com/golang/go/issues/40701
---
decoder/decoder.go | 13 +++++++------
rotator/rotator.go | 9 +++++----
2 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/decoder/decoder.go b/decoder/decoder.go
index 309e31d..e563953 100644
--- a/decoder/decoder.go
+++ b/decoder/decoder.go
@@ -291,12 +291,13 @@ func WriteJSONString(w io.Writer, s string) (int, error) {
func stb(s string) []byte {
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
- bh := reflect.SliceHeader{
- Data: sh.Data,
- Len: sh.Len,
- Cap: sh.Len,
- }
- return *(*[]byte)(unsafe.Pointer(&bh))
+ var res []byte
+
+ bh := (*reflect.SliceHeader)((unsafe.Pointer(&res)))
+ bh.Data = sh.Data
+ bh.Len = sh.Len
+ bh.Cap = sh.Len
+ return res
}
func toUTF8(s, replacement string) string {
diff --git a/rotator/rotator.go b/rotator/rotator.go
index d23fa6c..4f795da 100644
--- a/rotator/rotator.go
+++ b/rotator/rotator.go
@@ -194,6 +194,8 @@ func (r *Rotator) getSizeInBtyes() (float64, error) {
func (r *Rotator) GetDatabaseSize(db *sql.DB, schema string) (float64, error) {
var databaseSize string
+ var size float64
+ var err error
switch schema {
case "maxusage":
rows, err := db.Query("select pg_database_size('homer_data');")
@@ -205,7 +207,7 @@ func (r *Rotator) GetDatabaseSize(db *sql.DB, schema string) (float64, error) {
return 0, err
}
}
- return strconv.ParseFloat(databaseSize, 64)
+ size, err = strconv.ParseFloat(databaseSize, 64)
default:
rows, err := db.Query("select * from sys_df();")
checkDBErr(err)
@@ -216,10 +218,9 @@ func (r *Rotator) GetDatabaseSize(db *sql.DB, schema string) (float64, error) {
return 0, err
}
}
- percentageUsage, _ := strconv.ParseFloat(strings.TrimSuffix(strings.Split(databaseSize[1:len(databaseSize)-1], ",")[4], "%"), 64)
- return percentageUsage, nil
+ size, err = strconv.ParseFloat(strings.TrimSuffix(strings.Split(databaseSize[1:len(databaseSize)-1], ",")[4], "%"), 64)
}
- return 0, nil
+ return size, err
}
func (r *Rotator) UsageProtection(scheme string) error {