update packages

This commit is contained in:
kevin
2020-07-28 18:26:55 +08:00
parent 6ba8cc02c1
commit b1975d29a7
9 changed files with 6 additions and 233 deletions

View File

@@ -1,65 +0,0 @@
package main
import (
"log"
"time"
"zero/core/stores/clickhouse"
"zero/core/stores/sqlx"
)
func main() {
conn := clickhouse.New("tcp://127.0.0.1:9000")
_, err := conn.Exec(`
CREATE TABLE IF NOT EXISTS example (
country_code FixedString(2),
os_id UInt8,
browser_id UInt8,
categories Array(Int16),
action_day Date,
action_time DateTime
) engine=Memory
`)
if err != nil {
log.Fatal(err)
}
conn.Transact(func(session sqlx.Session) error {
stmt, err := session.Prepare("INSERT INTO example (country_code, os_id, browser_id, categories, action_day, action_time) VALUES (?, ?, ?, ?, ?, ?)")
if err != nil {
log.Fatal(err)
}
defer stmt.Close()
for i := 0; i < 10; i++ {
_, err := stmt.Exec("RU", 10+i, 100+i, []int16{1, 2, 3}, time.Now(), time.Now())
if err != nil {
log.Fatal(err)
}
}
return nil
})
var items []struct {
CountryCode string `db:"country_code"`
OsID uint8 `db:"os_id"`
BrowserID uint8 `db:"browser_id"`
Categories []int16 `db:"categories"`
ActionTime time.Time `db:"action_time"`
}
err = conn.QueryRows(&items, "SELECT country_code, os_id, browser_id, categories, action_time FROM example")
if err != nil {
log.Fatal(err)
}
for _, item := range items {
log.Printf("country: %s, os: %d, browser: %d, categories: %v, action_time: %s",
item.CountryCode, item.OsID, item.BrowserID, item.Categories, item.ActionTime)
}
if _, err := conn.Exec("DROP TABLE example"); err != nil {
log.Fatal(err)
}
}

View File

@@ -1,41 +0,0 @@
package main
import (
"encoding/json"
"fmt"
"log"
jsonx "github.com/segmentio/encoding/json"
)
type A struct {
AA string `json:"aa,omitempty"`
}
type B struct {
*A
BB string `json:"bb,omitempty"`
}
func main() {
var b B
b.BB = "b"
b.A = new(A)
b.A.AA = ""
fmt.Println("github.com/segmentio/encoding/json")
data, err := jsonx.Marshal(b)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(data))
fmt.Println()
fmt.Println("encoding/json")
data, err = json.Marshal(b)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(data))
}

View File

@@ -1,74 +0,0 @@
package testjson
import (
"encoding/json"
"testing"
jsoniter "github.com/json-iterator/go"
segment "github.com/segmentio/encoding/json"
)
const input = `{"@timestamp":"2020-02-12T14:02:10.849Z","@metadata":{"beat":"filebeat","type":"doc","version":"6.1.1","topic":"k8slog"},"index":"k8slog","offset":908739,"stream":"stdout","topic":"k8slog","k8s_container_name":"shield-rpc","k8s_pod_namespace":"xx-xiaoheiban","stage":"gray","prospector":{"type":"log"},"k8s_node_name":"cn-hangzhou.i-bp15w8irul9hmm3l9mxz","beat":{"name":"log-pilot-7s6qf","hostname":"log-pilot-7s6qf","version":"6.1.1"},"source":"/host/var/lib/docker/containers/4e6dca76f3e38fb8b39631e9bb3a19f9150cc82b1dab84f71d4622a08db20bfb/4e6dca76f3e38fb8b39631e9bb3a19f9150cc82b1dab84f71d4622a08db20bfb-json.log","level":"info","duration":"39.425µs","content":"172.25.5.167:49976 - /remoteshield.Filter/Filter - {\"sentence\":\"王XX2月12日作业\"}","k8s_pod":"shield-rpc-57c9dc6797-55skf","docker_container":"k8s_shield-rpc_shield-rpc-57c9dc6797-55skf_xx-xiaoheiban_a8341ba0-30ee-11ea-8ac4-00163e0fb3ef_0"}`
func BenchmarkStdJsonMarshal(b *testing.B) {
m := make(map[string]interface{})
if err := json.Unmarshal([]byte(input), &m); err != nil {
b.FailNow()
}
for i := 0; i < b.N; i++ {
if _, err := json.Marshal(m); err != nil {
b.FailNow()
}
}
}
func BenchmarkJsonIteratorMarshal(b *testing.B) {
m := make(map[string]interface{})
if err := jsoniter.Unmarshal([]byte(input), &m); err != nil {
b.FailNow()
}
for i := 0; i < b.N; i++ {
if _, err := jsoniter.Marshal(m); err != nil {
b.FailNow()
}
}
}
func BenchmarkSegmentioMarshal(b *testing.B) {
m := make(map[string]interface{})
if err := segment.Unmarshal([]byte(input), &m); err != nil {
b.FailNow()
}
for i := 0; i < b.N; i++ {
if _, err := jsoniter.Marshal(m); err != nil {
b.FailNow()
}
}
}
func BenchmarkStdJsonUnmarshal(b *testing.B) {
for i := 0; i < b.N; i++ {
m := make(map[string]interface{})
if err := json.Unmarshal([]byte(input), &m); err != nil {
b.FailNow()
}
}
}
func BenchmarkJsonIteratorUnmarshal(b *testing.B) {
for i := 0; i < b.N; i++ {
m := make(map[string]interface{})
if err := jsoniter.Unmarshal([]byte(input), &m); err != nil {
b.FailNow()
}
}
}
func BenchmarkSegmentioUnmarshal(b *testing.B) {
for i := 0; i < b.N; i++ {
m := make(map[string]interface{})
if err := segment.Unmarshal([]byte(input), &m); err != nil {
b.FailNow()
}
}
}

View File

@@ -1,31 +0,0 @@
package testjson
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
)
func TestMarshal(t *testing.T) {
type A struct {
A string `json:"a"`
AA string `json:"aa"`
}
type B struct {
A // can't be A A, or A `json...`
B string `json:"b"`
}
type C struct {
A `json:"a"`
C string `json:"c"`
}
a := A{A: "a", AA: "aa"}
b := B{A: a, B: "b"}
c := C{A: a, C: "c"}
bstr, _ := json.Marshal(b)
cstr, _ := json.Marshal(c)
assert.Equal(t, `{"a":"a","aa":"aa","b":"b"}`, string(bstr))
assert.Equal(t, `{"a":{"a":"a","aa":"aa"},"c":"c"}`, string(cstr))
}