Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grave in the Go Language

Tags:

rest

syntax

go

After looking around for a while I was able to understand how the json: tags are used in the Go language. However two tags I have come across I'm still lost on, and can't seem to find documentation on it.

Both pertain to a REST api service and the full code can be found here-> code.google.com

What is the root: tag used for

gorest.RestService    `root:"/orders-service/" consumes:"application/json" produces:"application/json"`

as well how does the method: tag work?

userDetails gorest.EndPoint `method:"GET" path:"/users/{Id:int}" output:"User"`

I didn't know if anyone had any links to a site or document that might explain this more, from the examples I can learn enough to use it. However, I would really like to fully understand it.

Thanks for your time!

like image 786
ngille Avatar asked Nov 21 '25 10:11

ngille


1 Answers

Tags are nothing but strings, they don't have any meaning per-se.

Libraries can use reflection to introspect struct fields and interpret their tags. See reflect.StructTag.

In your case, gorest parses the following tags on Services:

  • root
  • consumes
  • produces

and these on Endpoints:

  • realm
  • method
  • path
  • output
  • input
  • role
  • postdata

Their meaning is described in gorest's documentation.

like image 133
thwd Avatar answered Nov 22 '25 23:11

thwd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!