CRUD examples in Go for SaaS Web App

The example code for the web app service in the SaaS Startup Kit exposes business value to authenticated users. The responsive web application renders HTML using the html/template package from the standard library to enable direct interaction with customers of your SaaS and their users. The web app relies on the Golang business logic packages developed to provide an API for internal requests. These examples show how the SaaS Starter Kit provides Go boilerplate code to perform CRUD operations on an object.

One example business logic package is the one to create and manage Projects. In the SaaS Startup Kit, projects represent the highest level of business value. Users can perform CRUD on project records. You can easily modify the projects package to support your own requirements. If you were providing a software-as-a-service similar to Github, Projects could be changed to be 'repositories'. If you were providing software-as-a-service similar to Slack, Projects could be modified to be 'channels', etc.

Go Templates for Web App pages

The pages in the web app uses this base layout:
saas-starter-kit/blob/master/cmd/web-app/templates/layouts/base.gohtml

Since users are authenticated to use the business value provided by the SaaS, the base layout wraps the content pages for the Go web app with this additional partial layout:
saas-starter-kit/blob/master/cmd/web-app/templates/partials/app-wrapper.tmpl

Example List Objects template code in Go Web App

Go code example of List Objects for Index page in SaaS Web App

The projects functionality in the Go web app provides example functionality on how CRUD can be performed and exposed. The web app includes this index page that lists all records. This index page then allows users to view, update and delete an object.

example.saasstartupkit.com/projects

saas-starter-kit/blob/master/cmd/web-app/templates/content/projects-index.gohtml

Example Create Object template code in Go Web App

Go code example to Create Object in SaaS Web App

From the projects index page, users can click the button to create a new record. This create page demonstrates how a new record can be created for projects and also demonstrates inline validation.

example.saasstartupkit.com/create

saas-starter-kit/blob/master/cmd/web-app/templates/content/projects-create.gohtml

Go code example creating Object in SaaS Web App

Once the new object is saved, the user is redirected to view the object. Flash messages are displayed for the results of the CRUD operations.

Example Read Object template code in Go Web App

Go code example to Read and View Object in SaaS Web App

The view page for an object displays the fields for the object as read-only. The page then includes links to edit or archive the object. The archive functionality demonstrates how a soft-delete can be performed. While the web app does not expose functionality to delete a record, the internal API does support the delete operation.

example.saasstartupkit.com/projects/4ed08432-d585-46d4-9e82-82eafffef214

saas-starter-kit/blob/master/cmd/web-app/templates/content/projects-view.gohtml

Example Update Object template code in Go Web App

Go code example to Update Object in SaaS Web App

This update page demonstrates how a record can be edited. The various fields that you want to allow users to change can be exposed. The changes can then be saved to update the record.

example.saasstartupkit.com/projects/4ed08432-d585-46d4-9e82-82eafffef214/update

saas-starter-kit/blob/master/cmd/web-app/templates/content/projects-update.gohtml

Go code example updating Object in SaaS Web App

Once the object is updated, the user is redirected back to the view page for the object. Flash messages are displayed for the results of the CRUD operations.

Example Datatable implementation in Go Web App

Go code example of Datatables in SaaS Web App

The Go web app for SaaS uses Datatables to provide interactivity when listing objects. Datatables provides a free and easy way to add advanced interaction controls to your HTML tables. These Datatables in the Go web app are rendered server-side. The Golang code to render a data table has been abstracted into it a partial template.

saas-starter-kit/blob/master/cmd/web-app/templates/partials/datatable.tmpl

Code example of searching Datatables using Golang in SaaS Web App

This shows how users can interact with a Datatable in your Go web app by searching the records listed.

Code example of filtering Datatables using Golang in SaaS Web App

This shows how users can filter all the records in the Datatable. Filtering displayed in the footer of the table can be a dropdown for enum values or input for string values.

Example Inline Validation code for validating CRUD in Go Web App

Code example of inline validation server-side using Golang in SaaS Web App

The manage projects functionality in the Go Web App implements server-side validation. A flash message is rendered to display the error message. Errors for specific fields are removed from the flash message and instead included with the specific field inline.

example.saasstartupkit.com/examples/flash-messages

saas-starter-kit/blob/master/cmd/web-app/templates/content/examples-flash-messages.gohtml

Provide Feedback via our Google Slides

If you would like to provide us feedback on any of these screen captures and associated functionality, you are welcome to publicly comment on our Google Slides:

Open in Google Slides