mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-07-18 13:42:29 +03:00
Fixes and improvements
This commit is contained in:
29
common/sql/json.go
Normal file
29
common/sql/json.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package sql
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type SliceJSON[T any] []T
|
||||
|
||||
func (s *SliceJSON[T]) Scan(src interface{}) error {
|
||||
if src == nil {
|
||||
*s = nil
|
||||
return nil
|
||||
}
|
||||
var data []byte
|
||||
switch v := src.(type) {
|
||||
case []byte:
|
||||
data = v
|
||||
case string:
|
||||
data = []byte(v)
|
||||
default:
|
||||
return fmt.Errorf("sliceJSON.Scan: unsupported type %T", src)
|
||||
}
|
||||
if len(data) == 0 {
|
||||
*s = nil
|
||||
return nil
|
||||
}
|
||||
return json.Unmarshal(data, (*[]T)(s))
|
||||
}
|
||||
Reference in New Issue
Block a user