reflect.Tag.Lookup() Function in Golang with Examples
Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.Tag.Lookup() Function in Golang is used to find the value associated with key in the tag string, an empty string is returned if there is no such key in the tag and to determine whether a tag is explicitly set to the empty string. To access this function, one needs to imports the reflect package in the program.
Syntax:func (tag StructTag) Lookup(key string) (value string, ok bool)
Parameters: This function takes two parameters of string type (value) and bool type(ok).
Return Value: This function returns the value associated with key in the tag string and the value was explicitly set.
Below examples illustrate the use of the above method in Golang:
123456 (Empty) (Non specific)
Get method: 1 Lookup method: - false