How to have an optional query in GET request using Gorilla Mux?

后端 未结 2 1512
野趣味
野趣味 2020-12-31 17:22

I would like to have some of my query parameters be optional. As for now, I have

r.HandleFunc(\"/user\", userByValueHandler).
    Queries(
        \"usernam         


        
2条回答
  •  长发绾君心
    2020-12-31 17:48

    Just a comment to the previous answer.

    We can just add two routes there, I feel it is more readable, like below:

    r.HandleFunc("/user", userByValueHandler).
        Queries(
            "username", "{username}",
            "email", "{email}",
        ).
        Methods("GET")
    r.HandleFunc("/user", UserByValueHandler).Methods("GET")
    

提交回复
热议问题