DEV Community


Posted on

Convert var string struct key to struct key



I have a map (string) of "tag" to convert "words" into a text
this list of "Tags" must be replaced by values coming from a structure

var users struc {
login String
json:" options "
passwd String
json:" options "
var folders struc {
arch String
json:" folders "
dest String
json:" folders "`

var TAGS = map [string] string {
"{login}": "users.login",
"{passwd}": "users.passwd",
"{archive}": "folders.arch",
"{dest}": "folders.dest",

To do something like this:
var test = "Name = {login} archive = {archive} destination = {dest} / {login}"
var realTest = ReplaceTag (test, & TAGS)

I don't know how to convert the strings from the value to the real value of the structure.
I know how to do it directly but not when it is in the form of a string

thank you in advance

Top comments (0)