Feat: add query params

This commit is contained in:
2025-11-10 11:07:36 +08:00
parent 9a39bcda40
commit dbd2ed6469
16 changed files with 293 additions and 37 deletions

View File

@@ -8,12 +8,13 @@ import (
"time"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.uber.org/zap"
)
func pongHandler(w tcp.ResponseWriter, req *tcp.Request) error {
w.WriteHeader(tcp.StatusOK)
_, err := io.WriteString(w, string(req.Body))
_, err := io.WriteString(w, string(req.Params["msg"]))
return err
}
@@ -29,12 +30,20 @@ func tickHandler(w tcp.ResponseWriter, req *tcp.Request) error {
var serverCmd = &cobra.Command{
Use: "server",
Run: func(cmd *cobra.Command, args []string) {
router := tcp.NewRouter()
router.Use(middlewares.ErrorHandler)
router.Use(middlewares.AccessLog)
router.Register(tcp.MethodSOCKET, "/", tickHandler)
router.Register(tcp.MethodPOST, "/", pongHandler)
router := tcp.NewRouter().
Use(middlewares.ErrorHandler).
Use(middlewares.AccessLog)
router.Listen(":8080")
router.Register(tcp.MethodSOCKET, "/test",
tickHandler)
router.Register(tcp.MethodGET, "/test",
pongHandler)
router.Listen(":" + viper.GetString("port"))
},
}
func init() {
serverCmd.Flags().
String("port", "8080", "")
}