logo
  • 教程列表
  • SO官方文檔
  • 凝塊
    • 如何編碼資料並使用 gob 寫入檔案
    • 如何從檔案中讀取資料並使用 go 解碼
    • 如何使用 gob 對介面進行編碼
    • 如何使用 gob 解碼介面
  1. StackOverflow 文件
  2. Go 教程
  3. 凝塊
  4. 如何編碼資料並使用 gob 寫入檔案

如何編碼資料並使用 gob 寫入檔案

Created: November-22, 2018

package main

import (
    "encoding/gob"
    "os"
)

type User struct {
    Username string
    Password string
}

func main() {

    user := User{
        "zola",
        "supersecretpassword",
    }

    file, _ := os.Create("user.gob")

    defer file.Close()

    encoder := gob.NewEncoder(file)

    encoder.Encode(user)

}
  • 如何從檔案中讀取資料並使用 go 解碼
  • 凝塊

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 關於本站
  • 免責聲明