Thank you for your answer. Very helpful. 

On Thursday, September 2, 2021 at 8:01:54 PM UTC+3 seank...@gmail.com wrote:

> gorilla/mux tests routes in the order they're added.
> You can register your shared_data route before the {id} one if you must 
> keep the ambiguous path,
> though the better option is to not have ambiguous paths in the first place.
>
> On Thursday, September 2, 2021 at 6:18:36 PM UTC+2 bse...@computer.org 
> wrote:
>
>> Your paths are ambiguous.  "/nfdm-fdm/v2/shared-data" matches  
>> "/nfdm-fdm/v2/{id}" where id=shared_data. You can use a regex for the path 
>> with {id} to exclude the "shared_data" match.
>>
>> On Thu, Sep 2, 2021 at 10:13 AM Van Fury <fury...@gmail.com> wrote:
>>
>>> Hi All,
>>>
>>> I have the following to handler functions, DataSetsGet and 
>>> RetrieveSharedData.
>>> When make request with the URL 
>>> https://127.0.0.1:20000/nfdm-fdm/v2/shared-data, I get response from 
>>> DataSetsGet handler instead of RetrieveSharedData handler function. When I 
>>> take the bracket from {id} to id, I get the right response from 
>>> RetrieveSharedData handler. Any help to solve this issue, my code below 
>>> with omitted codes.
>>>
>>> ```
>>> func DataSetsGet(response http.ResponseWriter, request *http.Request) {
>>>
>>> // Data set response codes
>>> }
>>>
>>> func RetrieveSharedData(response http.ResponseWriter, request 
>>> *http.Request) {
>>> // Retrieve shared data response codes
>>> }
>>>
>>>
>>>
>>> type Route struct {
>>>     Name        string
>>>     Method      string
>>>     Pattern     string
>>>     HandlerFunc http.HandlerFunc
>>> }
>>>
>>> var Router = NewRouter()
>>>
>>> type Routes []Route
>>>
>>> func NewRouter() *mux.Router {
>>>     router := mux.NewRouter().StrictSlash(true)
>>>     for _, route := range routes {
>>>         var handler http.Handler
>>>         handler = route.HandlerFunc
>>>
>>>         router.
>>>             Methods(route.Method).
>>>             Path(route.Pattern).
>>>             Name(route.Name).
>>>             Handler(handler)
>>>     }
>>>
>>>     return router
>>> }
>>>
>>>
>>> var routes = Routes{
>>>     Route{
>>>         "DataSetsGet",
>>>         strings.ToUpper("Get"),
>>>         "/nfdm-fdm/v2/{id}",
>>>         DataSetsGet,
>>>     },
>>>
>>>     Route{
>>>         "RetrieveSharedData",
>>>         strings.ToUpper("Get"),
>>>         "/nfdm-fdm/v2/shared-data",
>>>         RetrieveSharedData,
>>>     },
>>>
>>> }
>>>
>>>
>>> func main{
>>>
>>> addr := "127.0.0.1:6060"
>>>
>>> server := NewServer(addr)
>>>
>>> go func() {
>>>         err := server.ListenAndServe() 
>>>         if err != nil && err != http.ErrServerClosed {
>>>             logger.Log.Errorf("Could not listen on %s: %v\n", addr, err)
>>>         }
>>>     }()
>>> }
>>>
>>>
>>>
>>> // Create a new server
>>> func NewServer(ListAddr string) *http.Server {
>>>
>>>     return &http.Server{
>>>         Addr:         ListAddr,
>>>         Handler:      Router,
>>>         ReadTimeout:  5 * time.Second,
>>>         WriteTimeout: 10 * time.Second,
>>>         IdleTimeout:  15 * time.Second,
>>>     }
>>> }
>>> ```
>>>
>>> BR
>>> Fury
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "golang-nuts" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to golang-nuts...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/golang-nuts/faf2c214-3638-4b3e-b460-1a789e351defn%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/golang-nuts/faf2c214-3638-4b3e-b460-1a789e351defn%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/5fb6fbe9-3414-4c10-9318-f300ac71873cn%40googlegroups.com.

Reply via email to