OSDN Git Service

add code keystore_use
authoripqhjjybj <250657661@qq.com>
Tue, 22 Sep 2020 09:58:42 +0000 (17:58 +0800)
committeripqhjjybj <250657661@qq.com>
Tue, 22 Sep 2020 09:58:42 +0000 (17:58 +0800)
cmd/keystore/main.go

index 70a7fe5..0a17faf 100644 (file)
@@ -1,7 +1,42 @@
 package main
 
-import "fmt"
+import (
+       "fmt"
+       "os"
+       "encoding/json"
+)
+
+type PersonInfo struct {
+       Name    string
+       age     int32
+       Sex     bool
+       Hobbies []string
+}
+
+func readFile() {
+
+       filePtr, err := os.Open("person_info.json")
+       if err != nil {
+               fmt.Println("Open file failed [Err:%s]", err.Error())
+               return
+       }
+       defer filePtr.Close()
+
+       var person []PersonInfo
+
+       // 创建json解码器
+       decoder := json.NewDecoder(filePtr)
+       err = decoder.Decode(&person)
+       if err != nil {
+               fmt.Println("Decoder failed", err.Error())
+
+       } else {
+               fmt.Println("Decoder success")
+               fmt.Println(person)
+       }
+}
 
 func main() {
        fmt.Println("Hello world!")
+       readFile()
 }