First web app - advice welcomed

Hi,

I’m working my way through the web development with Go Udemy course by Todd McLeod and really enjoying and benefitting from it. So much so that I have been able to build my first html reports using Go templates. I really enjoyed building that as it bound together a large number of techniques into a something ‘real’.

I’m moving on now to a project which I suspect is going to be a challenge.

I want to build a dashboard style webpage which will pull data (metrics) from a handful of different sources (using SQL/Rest) and render them as a composite view of a particular environment. I know html/css/javascript/jquery reasonably well and I wish to hook these metrics up to instrumentation widgets to produce a professional looking application.

I will need the dashboard to refresh every 30s or so, which I don’t think should be too tricky as it only takes Go about 8s to complete all the GET’s and Query’s needed to populate the map which I am injecting into the template.

Where I would appreciate opinions/advice:

  • Thus far I have been using the simple webserver boilerplate code from Todd’s training section 6. lecture 46 ‘creating a static file server with Go’. Its great for serving up the dashboard… that should work fine for the initial render of the page/template - but I can’t see how to handle the 30s refresh needed. Should I serve the page as one Go channel/routine and then run the creation of the page in another? They should work okay together to produce the desired effect, right? Or is there a better way to handle it?

  • For the application I have described, would I be better using Node.js for the webserver side and Go for the creation of the content being served up?

  • My progress with Go so far seems to be based on a lot of blood and tears, just about getting what I want/need, then someone comes along and says… “Oh, you could have used xxxx”, then when I look at xxxx they are right and I go back and redo it. This time I’d really like to research and choose in advance which packages will work well for me.

  • Anyone know of any starter or demo projects that do this kind of thing to give me something to study?

Would appreciate any thoughts/guidance.

Many thanks!

There are always many approaches to such problems, but here are a few suggestions based on my understanding of what you’ve done so far and where you wish to go.

If you’re happy with your dashboard approach as it is, and all you need to do is have it auto-refresh every 30 seconds, add a <meta> tag under the <head> section of your HTML, or use a little JavaScript to do just that. Here is such an answer from StackOverflow.

You can also break things up into two Go services – a web server to serve pages, and a separate service that provides data via a RESTful API usable by many services.

If choosing the two-tier approach mentioned above, I wouldn’t bother with Node for a web server. Instead, check out Caddy. It is an excellent, free and open source, web server written in Go.

The two tier approach is more flexible and scalable, but also more complicated because now your web pages need to be designed including JavaScript to make the HTTP/Restful API calls to your Go based data service.

2 Likes

Thank you @kpowick

In thinking about the approach this afternoon I realised that there was no need for one Go app to do it all and that I could abstract away the getting of the data and the injection of the data into the page template from the business of actually serving the page itself.

After realising this I actually visited the Caddy website. It looks really accomplished and accessible, so will definitely be giving that a try.

Thank you for the reminder about techniques for the auto refresh - appreciated.

I’m feeling pretty confident now that my head is clear about breaking the application up.
Thanks again.

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