a label attached to someone or something for the purpose of identification or to give other information
The go docs only have a short paragraph covering struct tags which follows:
A field declaration may be followed by an optional string literal tag, which becomes an attribute for all the fields in the corresponding field declaration. The tags are made visible through a reflection interface and take part in type identity for structs but are otherwise ignored.
Basically struct tags allow you to attach metadata to struct fields in the form of arbitrary string values.
The format of the metadata is: `key:val` or `key:val1,val2` in the case of multiple values. By convention the key corresponds to the name of the package consuming it.
This metadata can be intended for another package or you can make use of it yourself. It can be consumed via reflection using the types reflect.Type, reflect.StructField and reflect.StructTag as can be seen in this example.
A common use case is for serialisation/ deserialisation, the 'json' tag which is used by the encoding/json package is an example of this.
It also allows you to incorporate your initialisation code in the struct definition. An example of this is the github.com/caarlos0/env package which uses struct tags to define config structures with associated environment variables and perform boiler-plate free parsing. The package also allows you to set defaults via struct tags which again reduces initialisation code, however this is not compile-time safe.
If you are interested there is a good talk available here: video pdf
Informative article. Im very happy to visit this page. keep it up and Good job.
ReplyDeletejavascript training in chennai
javascript training
javascript training courses
javascript training classes
core java training in chennai
C C++ Training in Chennai
Appium Training in Chennai
JMeter Training in Chennai
Such a wonderful blog, I got new information from this article.
ReplyDeleteios mobile application development
ios apps development
hadoop technologies
importance of cloud computing
what is cloud in cloud computing
node js advanced interview questions
film izle - sex hikayeleri - sex hikayesi - erotik hikaye -
ReplyDeleteankara escort - bornova escort - alsancak escort - çeşme escort - izmir escort - smm panel - instagram takipçi satın al - instagram takipçi satın al - instagram takipçi satın al - instagram takipçi satın al - haber - instagram takipçi hilesi - instagram takipçi satın al - izmir evden eve nakliyat - seocu - instagram takipçi hilesi - instagram takipçi satın al - izmir escort - takipçi satın al - instagram takipçi satın al - tiktok takipçi satın al - instagram takipçi satın al - instagram takipçi satın al - instagram takipçi satın al - instagram takibi bırakanlar - buca escort -
karşıyaka escort - instagram takipçi hilesi
perde modelleri
ReplyDeletenumara onay
mobil ödeme bozdurma
nft nasıl alınır
ANKARA EVDEN EVE NAKLİYAT
trafik sigortasi
dedektor
Web sitesi kurma
Aşk kitapları
beykoz alarko carrier klima servisi
ReplyDeletetuzla lg klima servisi
tuzla alarko carrier klima servisi
tuzla daikin klima servisi
çekmeköy toshiba klima servisi
çekmeköy beko klima servisi
ataşehir beko klima servisi
maltepe lg klima servisi
üsküdar alarko carrier klima servisi