How to have an optional query in GET request using Gorilla Mux?
问题 I would like to have some of my query parameters be optional. As for now, I have r.HandleFunc("/user", userByValueHandler). Queries( "username", "{username}", "email", "{email}", ). Methods("GET") But in this case "username" AND "email" needs to be present in the request. I want to have more flexible choice: have 2 of them OR have just one of them (but not zero parameters). Thanks! 回答1: So I found the solution to re-write my logic as: r.HandleFunc("/user", UserByValueHandler).Methods("GET")