when I do a long connection service for the first time, I encounter a small problem, which used to be http. Use url to determine the service
for example, let"s be clear.
for example, there are two services, one login and one chat, and the corresponding json passed by the client is
Login:
{"type": "login", "username": "abc", "password": "123456"}
chat:
{"type": "chat", "from": "Zhang San", "to": "Li Si", "content": "Li Si Hello"}
the type field of json indicates which service to request
for golang, we usually parse these two json into corresponding structures
type Login struct{
Type string
Username string
Password string
}
type Chat struct{
Type string
From string
To string
Content string
}
how can I be sure to parse the json to the corresponding structure when I have just received the json string and don"t know what type is? I should json.Unmarshal (json,?)
or was my design idea wrong in the first place?