Unmarshal a string to a map struct using a base template (reverse process of template parse) Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Map of structs vs array of structs in GoCalling a template with several pipeline parametersIterating through map in templateUnmarshalling JSON to interface variable while matching the underlying type in GoGo template to structis there a way to list used variables?Golang - map data from one complex struct to anotherReflection: Struct by stringUnmarshal map[string]DynamoDBAttributeValue into a structParse and validate “key1:value1; key2:value2” string to Go struct efficiently?

Drawing spherical mirrors

Putting class ranking in CV, but against dept guidelines

Misunderstanding of Sylow theory

If Windows 7 doesn't support WSL, then what is "Subsystem for UNIX-based Applications"?

Dyck paths with extra diagonals from valleys (Laser construction)

What is an "asse" in Elizabethan English?

Central Vacuuming: Is it worth it, and how does it compare to normal vacuuming?

Trademark violation for app?

Did Mueller's report provide an evidentiary basis for the claim of Russian govt election interference via social media?

How were pictures turned from film to a big picture in a picture frame before digital scanning?

How does the math work when buying airline miles?

Is there hard evidence that the grant peer review system performs significantly better than random?

Why is it faster to reheat something than it is to cook it?

Can a Beast Master ranger change beast companions?

A letter with no particular backstory

How to identify unknown coordinate type and convert to lat/lon?

How long can equipment go unused before powering up runs the risk of damage?

What does it mean that physics no longer uses mechanical models to describe phenomena?

How do living politicians protect their readily obtainable signatures from misuse?

How does Belgium enforce obligatory attendance in elections?

How many morphisms from 1 to 1+1 can there be?

What are the discoveries that have been possible with the rejection of positivism?

Should a wizard buy fine inks every time he want to copy spells into his spellbook?

How often does castling occur in grandmaster games?



Unmarshal a string to a map struct using a base template (reverse process of template parse)



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Map of structs vs array of structs in GoCalling a template with several pipeline parametersIterating through map in templateUnmarshalling JSON to interface variable while matching the underlying type in GoGo template to structis there a way to list used variables?Golang - map data from one complex struct to anotherReflection: Struct by stringUnmarshal map[string]DynamoDBAttributeValue into a structParse and validate “key1:value1; key2:value2” string to Go struct efficiently?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I'm curious to see if there is a way to marshal a map or struct from a string and a Go Template (the reverse of template.Execute)



For example, let's say we have the following template for a filename pattern



const NameTemplate = ` .Os.Type / .Os.Variant ! .Os.Version ! .Name ! .Version `


And let's say we have the following map (using a structure in my solution, but I'll use a map here for simplicity)



data := map[string]interface
"Name": "some-name",
"Version": "1.0",
"Os": map[string]interface
"Type": "linux",
"Variant": "debian",
"Version": "9.0",
,



Doing a tmpl.Execute(NameTemplate, data) will result in linux/debian!9.0!some-name!1.0



Now what if we had that string linux/debian!9.0!some-name!1.0 and the template defined above NameTemplate. Is there a simple way to do obtain a map (or struct) like the one defined in data?










share|improve this question



















  • 2





    No, this is not possible. fmt.Scanf may do something similar for simple enough cases, though.

    – Flimzy
    Mar 8 at 22:40

















1















I'm curious to see if there is a way to marshal a map or struct from a string and a Go Template (the reverse of template.Execute)



For example, let's say we have the following template for a filename pattern



const NameTemplate = ` .Os.Type / .Os.Variant ! .Os.Version ! .Name ! .Version `


And let's say we have the following map (using a structure in my solution, but I'll use a map here for simplicity)



data := map[string]interface
"Name": "some-name",
"Version": "1.0",
"Os": map[string]interface
"Type": "linux",
"Variant": "debian",
"Version": "9.0",
,



Doing a tmpl.Execute(NameTemplate, data) will result in linux/debian!9.0!some-name!1.0



Now what if we had that string linux/debian!9.0!some-name!1.0 and the template defined above NameTemplate. Is there a simple way to do obtain a map (or struct) like the one defined in data?










share|improve this question



















  • 2





    No, this is not possible. fmt.Scanf may do something similar for simple enough cases, though.

    – Flimzy
    Mar 8 at 22:40













1












1








1








I'm curious to see if there is a way to marshal a map or struct from a string and a Go Template (the reverse of template.Execute)



For example, let's say we have the following template for a filename pattern



const NameTemplate = ` .Os.Type / .Os.Variant ! .Os.Version ! .Name ! .Version `


And let's say we have the following map (using a structure in my solution, but I'll use a map here for simplicity)



data := map[string]interface
"Name": "some-name",
"Version": "1.0",
"Os": map[string]interface
"Type": "linux",
"Variant": "debian",
"Version": "9.0",
,



Doing a tmpl.Execute(NameTemplate, data) will result in linux/debian!9.0!some-name!1.0



Now what if we had that string linux/debian!9.0!some-name!1.0 and the template defined above NameTemplate. Is there a simple way to do obtain a map (or struct) like the one defined in data?










share|improve this question
















I'm curious to see if there is a way to marshal a map or struct from a string and a Go Template (the reverse of template.Execute)



For example, let's say we have the following template for a filename pattern



const NameTemplate = ` .Os.Type / .Os.Variant ! .Os.Version ! .Name ! .Version `


And let's say we have the following map (using a structure in my solution, but I'll use a map here for simplicity)



data := map[string]interface
"Name": "some-name",
"Version": "1.0",
"Os": map[string]interface
"Type": "linux",
"Variant": "debian",
"Version": "9.0",
,



Doing a tmpl.Execute(NameTemplate, data) will result in linux/debian!9.0!some-name!1.0



Now what if we had that string linux/debian!9.0!some-name!1.0 and the template defined above NameTemplate. Is there a simple way to do obtain a map (or struct) like the one defined in data?







go go-templates






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 9 at 23:09







jucardi

















asked Mar 8 at 21:49









jucardijucardi

1,43511110




1,43511110







  • 2





    No, this is not possible. fmt.Scanf may do something similar for simple enough cases, though.

    – Flimzy
    Mar 8 at 22:40












  • 2





    No, this is not possible. fmt.Scanf may do something similar for simple enough cases, though.

    – Flimzy
    Mar 8 at 22:40







2




2





No, this is not possible. fmt.Scanf may do something similar for simple enough cases, though.

– Flimzy
Mar 8 at 22:40





No, this is not possible. fmt.Scanf may do something similar for simple enough cases, though.

– Flimzy
Mar 8 at 22:40












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55071484%2funmarshal-a-string-to-a-map-struct-using-a-base-template-reverse-process-of-tem%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55071484%2funmarshal-a-string-to-a-map-struct-using-a-base-template-reverse-process-of-tem%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

Алба-Юлія

Захаров Федір Захарович