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 <furyva...@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+unsubscr...@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/CAMV2RqqU3bTZ3midOUr1Dn8Aax0wdgSABmrPrOOfSv%2B252YqRg%40mail.gmail.com.

Reply via email to