Go: Get path parameters from http.Request

后端 未结 1 1573
没有蜡笔的小新
没有蜡笔的小新 2020-12-30 00:43

I\'m developing a REST API with Go, but I don\'t know how can I do the path mappings and retrieve the path parameters from them.

I want something like this:

相关标签:
1条回答
  • If you don't want to use any of the multitude of the available routing packages, then you need to parse the path yourself:

    Route the /provisions path to your handler

    http.HandleFunc("/provisions/", Provisions)
    

    Then split up the path as needed in the handler

    id := strings.TrimPrefix(req.URL.Path, "/provisions/")
    // or use strings.Split, or use regexp, etc.
    
    0 讨论(0)
提交回复
热议问题