Hello Ajinkya, First of all welcome to Go(land) 🙂.
I’ll break the line down:
The chi router has a method called walk. The method recieves:
- A router
- A callback.
The callback is called for each route which was defined on the router, and recieves 4 parameters:
- The method defined for the route
- The actual route string
- The handler(function) which processes the request for the given route
- The list of middlewares defined for the given route (Middlewares are simply functions which get called before the handler is called, so they are used for preprocessing requests, authentication, etc)
In case the `middlewares …func(http.Handlers) http.Handlers` is what wasn’t clear to you:
The … is called a spread operator, and is used for two main purposes:
- To expand a slice. eg:
nums := []int{1, 2, 3, 4}
fmt.Println(nums…)
Will print each item in nums as if they were added individually to println like
fmt.Println(1, 2, 3, 4)
2. To create variadic function. Variadic functions are functions which can allow an unlimited number of arguments. Meaning in the case of `middlewares …func(http.Handlers) http.Handlers`, the function expects an unlimited amount of functions with the given function signature which is:
func(http.Handlers) http.Handlers //ie recieves a http.Handler and returns a http.Handler
Please let me know if I was able to explain it better. And don’t fail to reach out if you ever have any golang related questions in the future. I’ll be happy to help. Great work on the youtube channel, by the way.