Beispiel #1
0
func writeValuesTofile(protocolData *protocol.MetaRequest, stmt *sql.Stmt) {
	fmt.Println("adding one record...")
	if reqType := protocolData.GetType(); reqType == protocol.MetaRequest_REGISTER {
		userInfo := protocolData.GetRegisterInfo()

		UserName := userInfo.GetUsername()
		PassWord := userInfo.GetPassword()
		Email := userInfo.GetEmail()

		fmt.Println(UserName, PassWord)

		if result, err := stmt.Exec(UserName, PassWord, Email); err == nil {
			fmt.Println("one record added to db", result)
		} else {
			fmt.Println("one record failed to add to db..")
		}
	}
}
Beispiel #2
0
func handleProtoClient(conn net.Conn, c chan *protocol.MetaRequest) {
	fmt.Println("Connection established")
	defer conn.Close()
	data := make([]byte, 4096)

	n, err := conn.Read(data)
	checkError(err)
	fmt.Println("Decoding Protobuf message")
	protodata := new(protocol.MetaRequest)
	if err = proto.Unmarshal(data[0:n], protodata); err != nil {
		fmt.Println("Error protocol data!")
		return
	}
	checkError(err)
	reqType := protodata.GetType()
	if reqType == protocol.MetaRequest_REGISTER {
		fmt.Println("Register")
		c <- protodata
	}
}