diff --git a/golang_learn/data_func/go_to_json/gjson/main.go b/golang_learn/data_func/go_to_json/gjson/main.go new file mode 100644 index 0000000..4231ffd --- /dev/null +++ b/golang_learn/data_func/go_to_json/gjson/main.go @@ -0,0 +1,56 @@ +package main + +import ( + "github.com/tidwall/gjson" + "log" +) + +func main() { + log.Print("查询内容:", gjson.Get(jsonStr, "code")) + log.Print("查询内容:", gjson.Get(jsonStr, "data.ext")) + log.Print("查询内容:", gjson.Get(jsonStr, "data.items.0")) + log.Print("查询内容:", gjson.Get(jsonStr, "data.items.2.resourceId")) +} + +var jsonStr = `{ + "code": 200, + "data": { + "ext": { + "utm_medium": "AAAA" + }, + "size": 6, + "items": [ + { + "ext": null, + "resourceId": "1", + "mediaAssetInfo": null, + }, + { + "ext": null, + "resourceId": "2", + "mediaAssetInfo": null, + }, + { + "ext": null, + "resourceId": "3", + "mediaAssetInfo": null, + }, + { + "ext": null, + "resourceId": "4", + "mediaAssetInfo": null, + }, + { + "ext": null, + "resourceId": "5", + "mediaAssetInfo": null, + }, + { + "ext": null, + "resourceId": "6", + "mediaAssetInfo": null, + } + ] + }, + "message": "success" +}` diff --git a/golang_learn/data_func/go_to_json/sjson/main.go b/golang_learn/data_func/go_to_json/sjson/main.go new file mode 100644 index 0000000..4ea0c40 --- /dev/null +++ b/golang_learn/data_func/go_to_json/sjson/main.go @@ -0,0 +1,58 @@ +package main + +import ( + "github.com/tidwall/sjson" + "log" +) + +func main() { + res, err := sjson.Set(jsonStr, "code", "111") + if err != nil { + log.Fatal("发生异常:", err) + return + } + log.Print("查询内容:", res, jsonStr) +} + +var jsonStr = `{ + "code": 200, + "data": { + "ext": { + "utm_medium": "AAAA" + }, + "size": 6, + "items": [ + { + "ext": null, + "resourceId": "", + "mediaAssetInfo": null, + }, + { + "ext": null, + "resourceId": "", + "mediaAssetInfo": null, + }, + { + "ext": null, + "resourceId": "", + "mediaAssetInfo": null, + }, + { + "ext": null, + "resourceId": "", + "mediaAssetInfo": null, + }, + { + "ext": null, + "resourceId": "", + "mediaAssetInfo": null, + }, + { + "ext": null, + "resourceId": "", + "mediaAssetInfo": null, + } + ] + }, + "message": "success" +}` diff --git a/golang_learn/go.mod b/golang_learn/go.mod index f1df889..fed65bc 100644 --- a/golang_learn/go.mod +++ b/golang_learn/go.mod @@ -28,6 +28,8 @@ require ( github.com/russross/blackfriday v1.6.0 github.com/shirou/gopsutil v2.20.4+incompatible github.com/spf13/viper v1.8.1 + github.com/tidwall/gjson v1.13.0 + github.com/tidwall/sjson v1.2.4 github.com/yeka/zip v0.0.0-20180914125537-d046722c6feb golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect golang.org/x/exp/errors v0.0.0-20210715201039-d37aa40e8013 diff --git a/golang_learn/go.sum b/golang_learn/go.sum index c96b8e7..1ecc7be 100644 --- a/golang_learn/go.sum +++ b/golang_learn/go.sum @@ -308,6 +308,15 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= +github.com/tidwall/gjson v1.12.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/gjson v1.13.0 h1:3TFY9yxOQShrvmjdM76K+jc66zJeT6D3/VFFYCGQf7M= +github.com/tidwall/gjson v1.13.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= +github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/tidwall/sjson v1.2.4 h1:cuiLzLnaMeBhRmEv00Lpk3tkYrcxpmbU81tAY4Dw0tc= +github.com/tidwall/sjson v1.2.4/go.mod h1:098SZ494YoMWPmMO6ct4dcFnqxwj9r/gF0Etp19pSNM= github.com/yeka/zip v0.0.0-20180914125537-d046722c6feb h1:OJYP70YMddlmGq//EPLj8Vw2uJXmrA+cGSPhXTDpn2E= github.com/yeka/zip v0.0.0-20180914125537-d046722c6feb/go.mod h1:9BnoKCcgJ/+SLhfAXj15352hTOuVmG5Gzo8xNRINfqI= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/gui_gio_learn/haptic/example.go b/gui_gio_learn/haptic/example.go index e2cb407..af242a7 100644 --- a/gui_gio_learn/haptic/example.go +++ b/gui_gio_learn/haptic/example.go @@ -46,7 +46,7 @@ func loop(w *app.Window) error { buzzer.Buzz() } gtx := layout.NewContext(&ops, e) - layout.Center.Layout(gtx, material.Button(th, &btn, "buzz").Layout) + layout.Center.Layout(gtx, material.Button(th, &btn, "测试").Layout) e.Frame(gtx.Ops) default: ProcessPlatformEvent(e)