Extract Id from a string

Hi all,

I work for a company who are very risk averse to developers using any packages that are not invented from the ground up in-house. As a result it’s virtually impossible to have access to and to be able to use any of the many really useful community developed packages i.e. gorilla, gin etc

I’m currently exploring the possibilities and pitfalls of developing HTTP restful services solely using the standard library and one of the first things that I’ve come up against is lack of standard library out of the box ability to extract an Id from a request URL.Path for a PUT, the Id which effectively represents the item being updated in the PUT request.

This is pretty basic stuff which would be trivial with gorilla but since I’m unable to use that I’ve come up my own struct + method that intends to be reusable in whatever package it gets declared in / whatever other struct it eventually ends up being attached to in this example:

https://play.golang.org/p/_GSVa0mS2La

I’m seeking feedback from you useful people here to tell me if this looks ok, looks awful or is just an altogether terrible idea etc.

Many thanks,
Joe

Not sure if this is better or worse, but I’m accustomed to seeing REST APIs that are like http://hostname.com/api/toplevel/12/nextlevel/34/leaf/56. If I had to parse multiple IDs out of something like that, I’d do something like this: https://play.golang.org/p/E2NuVGvFxxa

Thank you for the alternative insight. I instinctively leant towards regexp being the most efficient way to achieve this but having benchmarked various options it looks like it’s the worst option so far as performance goes. It does indeed appear that a simple string split will perform best.