How do you send data to your views in Go?

This is more of a “theory” question, than a pure technical question. How are you sending your data to the view? I’m hobbyist developer and am new to MVC. Friends have recommended that I use a Javascript framework, but that’s more of a learning curve than I want at the moment.

As I was reading through the book: The Go Programming Language

it spoke about Marsheling data, and creating structs in the form of your JSON (or the other way).

If you want to generate an application that is more API driven, would you send back a JSON file from your controller, in your view you would still use Go’s templates to read in the JSON from the URL and use the results of that JSON file in your view layer?

I apologize if this request seems nebulous, learning a bit of theory as I go.

Kind regards

Do one step after the other.

1.) Implement a site that only replies to actual requests. Meaning the user clicks a link which leads to a new URL. Use forms and POST-requests where necessary.
2.) Use JS on the client side which polls some API endpoints on your site or listen on onClick events on your page to dynamically load data and replace parts of the currently displayed page.
3.) Use websockets to push data to your connected clients.

Do one of these steps seperately. Make sure huge parts of your page are working in phase 1 before moving to phase 2. Also when moving from 1 to 2, make sure that everything still works without having JS enabled on the client.

1 Like

Thanks for the advice. It seems like it would be wise to actually map out URLs needed for the entire project before even starting. Is something a developer would do?

Thanks!

You don’t necessarily have to map out for the whole project at once, but for the entire piece of functionality you are presently implementing at the very least. Building it piece-meal of course, but you’re on the right track as it won’t hurt you at all to map them all out before hand. It might just be a bit easier to manage if you chunk it by functionality and implement each. Then you can go back and clean things up/extend it as need be.

Is something a developer would do?

It depends on your team. Some teams or corporations do have API designers some don’t have them.

When you don’t have an API designer your devs need to do it on your own. Simple, eh?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.