Essential Go gob  Edit on GitHub      File Issue

How to read data from file and decode with go?

package main

import (
    "encoding/gob"
    "fmt"
    "os"
)

type User struct {
    Username string
    Password string
}

func main() {

    user := User{}
    file, _ := os.Open("user.gob")
    defer file.Close()

    decoder := gob.NewDecoder(file)
    decoder.Decode(&user)
    fmt.Println(user)
}
  ↑ ↓ to navigate     ↵ to select     Esc to close