-4

Writing a website connected to a Go backend

I am able to pass data to the html template and thus the front end but can not then use that data for a am missing the code skill in javascript.

How can a Go variable

{{Gopher9}}

be read by javascript code?
GoPher9
  • 39
  • 4
  • 2
    Your question is unclear. Where is the Go running? Where is the JavaScript running? Are you talking about writing a module in JavaScript to be used in a Go program? Are you talking about sending messages over a network? Something else? – Quentin Sep 19 '18 at 08:43
  • The short answer is yes. To give the long answer, this question is too broad and also unclear. Obviously you need some kind of communication (between the Go app and the other app that executes the Javascript, e.g. a browser), whether it is simple HTTP requests or websocket or SSE (or something else) is a matter of detail. – icza Sep 19 '18 at 08:48
  • Re edit: Now a [duplicate](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – Quentin Sep 19 '18 at 08:49
  • Of course there is a way. That's what networks are for. But there are literally an infinite number of ways, many common, some uninvented yet. Your question is far too broad. You might do well to do a little bit of research into AJAX and REST, then come back when you find yourself facing a specific problem. – Jonathan Hall Sep 19 '18 at 08:55
  • Its not a Duplicate thats between php and javascript. – GoPher9 Sep 19 '18 at 08:59
  • No, that question is about client-side vs server-side programming. The languages in use are irrelevant, except as an example. – Jonathan Hall Sep 19 '18 at 09:30
  • I apologies to you all for the lack of clarity in my question. I have done my best to simply my question. Thank you all. – GoPher9 Sep 19 '18 at 10:11

1 Answers1

1

This can probably be done by storing the variables in a file rather than in the scripts local storage.

When You want to read variable then grab the value from the file and when you want to set variable then write to the file.

The value can be stored in a .txt file but if u have a lot of values that are going to be stored and passed between the programs consider making a .json File.

Andreto
  • 88
  • 8
  • "This can probably be done by storing the variables in a file rather than in the scripts local storage." Thank you for your help. I have already successfully used that way. I am specifically asking if it can be done directly between Go and Javascript or if not possible with out the use of things like AJAX and REST and so on. – GoPher9 Sep 19 '18 at 09:02
  • I found the answer. https://www.youtube.com/watch?v=IucPdpcyubg – GoPher9 Sep 19 '18 at 11:03