5

Writing testable examples in Go

 1 year ago
source link: https://www.ardanlabs.com/blog/2023/01/writing-testable-examples-in-go.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Writing testable examples in Go

Author image

Cheikh Seck

January 12, 2023

Introduction

Google developed Go to be an alternative to C++ with the internet and scale in mind. Go’s toolchain automates tasks that are easily overlooked, and amongst those tasks is generating documentation. Go has the ability to generate documentation based on comments written in your source code. As the end user, you have the choice to view this documentation in your terminal or, if your code is publicly accessible, on pkg.go.dev. Go also offers special comment syntax to further format and style the generated documentation.

In this video, Miki will generate documentation that displays and correctly formats testable code. In the context of this video, testable code will be code that a user can paste into their scratch file to test out the functionality of a package or API. Miki will start by adding a source code file to his package and define a test function. Within this test function, He will write the comments and syntax required to display testable code on his documentation. Watch to learn how you can generate documentation with code samples your end users can run.

Things you will learn in this video

  • How to add formatting to your Go documentation.
  • Generate testable code within documentation.

Video


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK