Reputation: 218
Lets say we have a client server scenario, in this situation both the server and the client speak to each other using a common message structure. So, one use struct
to define that message structure, something like this
type Message struct {
SenderId int
Content string
AuthCode string
}
Now to avoid repeating yourself and having a Message
structure in both the client package and server package, what is the GoWay to address this problem ?
Thanks!
Upvotes: 1
Views: 2756
Reputation: 1379
There are three different approaches:
http
package.message
, common
, types
, ...) and adding your shared structures there, as does etcd
server
package and importing that in the client
package. For example, the x/net/websocket
package imports net/http
.It's really a matter of personal taste.
Upvotes: 10