fwhezfwhez / tcpx

a cross-language tcp framwork in golang
MIT License
235 stars 45 forks source link

[Promotion] Provide url style routing way, help tcpx practice better! #39

Open fwhezfwhez opened 4 years ago

fwhezfwhez commented 4 years ago

Hello! Tcpx now provide a better practice routing style for developer. In the past, routers are like:

srv.AddHandler(1, login)
srv.AddHandler(3, auth)

This kind of routing is based on messageID. It seems easy but require developers to manage all messageID themselves, it's really a tiring job.

But now ,tcpx provides better routing style, it will gradually replace the old messageID routing.(But will not abandon usage of messageID and still keep compatible of old stf). It works like:

srv.Any("/login/", login)
srv.Any("/auth/", auth)

Also, when server side wants to reply:

func login(c *tcpx.Context) {
    c.JSONURLPattern(map[string]interface{}{
        "message": "login success, welcome!"
    })
}

More usages of url-pattern routing, you may refer to