K
K
kpa6uu2017-07-14 12:54:14
go
kpa6uu, 2017-07-14 12:54:14

How to add a custom property to an existing Go structure?

Greetings!
I get a TCP connection with the following code:

ln, err := net.Listen("tcp", Server.GetHost()+Server.getPortForNet())

for {
    connection, err := ln.Accept()
}

connection - net.Conn interface .
I need to add some custom properties and methods to this structure.
For example:
?{
name string
lastname string
}

func (Connection *?) GetName() string {
    return ?.name
}

func (Connection *?) GetLastName() string {
    return ?.lastname
}

Those. I will have to be able to write something like this:
connection.getName()
How to do it right? Thanks for the help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pavlyuk, 2017-07-14
@kpa6uu

Why don't you just want to create a structure like this?

struct User {
    Name string
    LastName string
    Connection net.Conn
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question