Simple Web App Example

I’m trying to learn about creating web apps with Go and very much enjoying making progress here and there. So far I’ve been able to implement a couple of template based projects with static data but now I need to step things up a little.

I would like to set up a simple site which can accept some text in an input box and when a submit button is clicked I would like to be execute some processing on the text which was entered. Are there any good SIMPLE examples of doing this anywhere that are not overly complicated?

I am a-ok with html, css, javascript and jquery - basically the web part itself. I am fine with writing the code which I will need to execute to process the input. Specifically the part I a fuzzy on is how to ‘wire’ the input box/button click action to a go function.

Would greatly appreciate any examples or tutorials on how to accomplish this.


If you want very simple, I believe the Go website itself has an article covering something very similar to this -

You create a simple web app that allows you to create, edit, and view text files using input forms.

Thanks @joncalhoun
I guess I maybe should have said very very very simple as I had tried that tutorial and had problems getting it to work at all.

Are you aware of any examples where the button click is hooked up to an ajax handler to execute the Go code then write the result back to the page?

Sorry to be so dim… :frowning:

All you have to do is create a web server with the net/http package that registers some routes to a mux, those routes are established by connecting them to a HandleFunc, which is a function that matches the interface defined in the http package. You will parse your data from the form post request on the rendered page.

Check out this vid:

Thanks @joncalhoun and @CurtGreen

After a couple of hours of messing around and head banging I’ve cobbled these together. I suppose its not impossible that they might be of some use to others at some time in the future as crazy simple examples of how to:

  • Run a simple web server
  • Collect some input into a textbox
  • Allow the user to click a submit box and have the textbox data sent back to a Go function.
  • Perform some processing on the data sent and send it back for display on the page

Works great and I’m delighted with it. This could be the bare bones of something much more sophisticated!

Go app:

html (bootstrap enabled) template:

Thanks again.

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