Building a module in Go (Golang)

Learn to build a reusable, well-tested module in Go

  • 0.0 (0 Reviews)
  • 0 Students
  • 58 Lessons
  • Trevor Sawler

Course Overview

Working with web applications in Go is remarkably easy, but it does not take too long to realize that in a lot of cases, we end up writing the same kind of code every time we start a new project. You might need to read JSON, write JSON, upload files, or any of the commonly used features of a given web application. In other words, we often rewrite code that we have already written, many times over.

Rather than simply copying and pasting code from one project to another, it makes sense to take advantage of Go modules -- reusable code that can be included in a project by simply issuing a "go get" command. That way, if new functionality is added to that module, any project that imports it can take advantage of that functionality simply by updating its dependencies, and if a bug is discovered, you can fix it by updating the module; every project that uses that module gets the bug fix with a single "go get -u" command.

Building a robust, secure, well-tested module is not difficult, but it does require careful planning to ensure that it will work across different operating systems.

This course will take you through the steps necessary to produce a module that includes many of the tasks commonly used in web applications, including:

  • reading JSON

  • writing JSON

  • producing well formatted, informative error messages

  • uploading one or more files to a server, and limiting uploads by mime type and file size

  • creating directories on the server

  • generating random strings

  • downloading static files

  • posting JSON to a remote service

  • creating a URL safe slug from a string

We'll build our module using Go 1.18's new workspaces tools, and we'll ensure that the entire module is well-tested.

Our final module will not have any external dependencies, and will only use functionality found in Go's standard library.

By the time you have finished this course, you'll have a Go module that will make starting a new web application much faster, and you won't be depending on someone else's code to do so.

See more

FAQ

FAQ area empty

Course curriculum

10 chương 58 bài học 4 giờ 16 phút 7 bài học thử miễn phí
Chương 1 Introduction
Chương 2 Project Setup
  • Installing Go 1:31
  • Installing an IDE 3:14
  • Setting up our Go Workspace 4:59
Chương 3 Getting Started with the Module
Chương 4 Uploading one or More Files
Chương 5 Creating Directories if they do not exist
  • What we'll cover in this section 0:52
  • Writing the CreateDirIfNotExists method 2:20
  • Trying out our new method 2:21
  • Writing a test for CreateDirIfNotExists 2:12
  • Updating the UploadFiles method to take advantage of our new method 1:32
  • Updating our readme and pushing changes to GitHUB 1:09
Chương 6 Generating Slugs
  • What we'll cover in this section 0:42
  • Writing the Slugify method for our module 3:43
  • Adding an app-slug project to our Go workspace and trying things out 3:32
  • Update our tests 7:57
  • Pushing our changes to GitHub 1:30
Chương 7 Downloading a Static File
  • What we'll cover in this section 0:58
  • Writing the DownloadStaticFile function 3:59
  • Trying things out 7:52
  • Writing a test for DownloadStaticFile 5:49
  • Pushing our changes to GitHub 1:16
Chương 8 Working with JSON
  • What we'll cover in this section 0:56
  • Reading JSON 8:34
  • Improving error messages in ReadJSON 8:09
  • Writing a test for ReadJSON 7:37
  • Adding additional cases to our table test for ReadJSON 6:41
  • Writing JSON 3:53
  • Writing a test for WriteJSON 2:49
  • Creating the ErrorJSON function 2:48
  • Writing a test for ErrorJSON 4:01
  • Pushing JSON to a remote service 6:54
  • Writing a test for PushJSONToRemote 6:17
  • Setting up our simple web app and adding some HTML 4:49
  • Getting started with the web app 5:36
  • Handling a simple JSON Post 4:33
  • Handling pushing to a remote service 5:21
Chương 9 Tagging a release & Semantic Versioning
  • What we'll cover in this section 1:03
  • What is semantic versioning? 2:06
  • Tagging version 1.0.0 of our module 2:10
  • Updating the version to 2.0.0 6:10
Chương 10 Trying our module out
  • What we'll cover in this section 0:39
  • Creating a simple (dummy) API 3:08
  • Importing our toolkit module to the project and trying one endpoint 3:05
  • Trying out the login handler 7:42

Requirment

  • Some experience with the Go programming language is required.

Outcomes

  • How to build a platform agnostic, re-usable Go module

  • How to share your module with other Go developers

  • How to write tests for your module

  • How to manage multiple versions of your module

  • How to use Go 1.18's new go work feature, workspaces

Instructor

...
Trevor Sawler

0.0

  • ... 0 Student
  • ... 9 Courses
  • ... 0 review

View Details

Reviews

Rate this course :

Remove all