I am creating a server in the Golang intended for a mobile application. I need to be able to support multiple versions of the API for cases where users do not update the application. The main problem with the version is to return the data in the correct format for the version of the mobile application.
I saw that there are three main ways to do this.
A. One way is to have one route handler on "/" and then allow this function to parse the version control URL.
Example:
func main() { http.HandleFunc("/", routes.ParseFullURI) }
C. Use a library such as gorilla / mux to process patterns inside the router, but I have seen some warnings that this might be too slow .
Example:
func main() { mux.HandleFunc("{version:}/", routes.ParseVersionForHome) mux.HandleFunc("{version:}/getData", routes.ParseVersionForGetDAta) mux.HandleFunc("{version:}/otherCall", routes.ParseVersionForOtherCall) }
C. Have separate URLs that do not change, but are split into different versions based on the header. Example:
func main() { http.HandleFunc("/", routes.ParseHeaderForVersionForHome) http.HandleFunc("/getData", routes.ParseHeaderForVersionForGetData) http.HandleFunc("/otherCall", routes.ParseHeaderForVersionForOtherCall) }
I am concerned that option 1 will be too dirty code. I am worried that option 2 will be too slow, and I am worried that for the third client it will be difficult to complete task 3 or it will be confusing as the version is not clearly marked.
Which method is the most idiomatic for Golang and will lead to maximum performance for the mobile application that will be frequently polled?
source share