package main

import (
	"bytes"
	"encoding/gob"
	"fmt"
	"net"
)

type User struct {
	Name, Pass string
}
type User2 struct {
	qwe string
	xsa string
}
func main() {
	var xxs =new(User2)
	Load(xxs)
	fmt.Println(xxs)
}

func Load(object interface{}) (){
	Conn, _ := net.Dial("tcp", "127.0.0.1:1234")
	tmp:=make([]byte,1024)
	len1,_:=Conn.Read(tmp)
	tmp=tmp[:len1]
	a:=bytes.NewBuffer(tmp)
	decoder := gob.NewDecoder(a)
	decoder.Decode(object)

	Conn.Close()
}

因为user2的成员没有大写,导致结果不正常

type User2 struct {
	qwe string
	xsa string
}

改成这样就行啦

说点什么
支持Markdown语法
好耶,沙发还空着ヾ(≧▽≦*)o
Loading...