
Golang Jet is a Go library that provides a simple and efficient way to handle HTTP requests and responses. It's built on top of the net/http package and offers a more concise and expressive API.
Golang Jet is designed to make it easy to write web applications in Go, with features like automatic request parsing and response rendering. This makes it a great choice for developers who want to build web apps quickly and efficiently.
One of the key benefits of Golang Jet is its ability to handle multiple requests concurrently, making it well-suited for high-traffic web applications. This is achieved through the use of goroutines and channels, which allow Golang Jet to scale horizontally and handle a large number of requests.
Golang Jet also provides a range of built-in middleware functions that make it easy to add features like authentication and rate limiting to your web application. These middleware functions can be easily composed together to create a robust and secure web app.
Installation
To install the Jet package, you need to install Go and set your Go workspace first. This is a crucial step, as it will allow you to use the Jet generator to create jet files from the command line.
The minimum Go version required is 1.8. If you're using an older version, you'll need to upgrade before proceeding.
You can install Jet using one of two methods: via `go install` or by building manually from source and installing the jet generator to a specific folder.
Here's a brief overview of the two options:
- Option 1: Install via `go install`
- Option 2: Build manually from source and install jet generator to specific folder
If you choose to install manually, make sure the target directory is included in your system's PATH environment variable to allow global access to the jet command.
Features and Benefits
golang jet provides a significant boost in speed, improving performance in three major areas. Writing SQL queries is faster and easier with SQL code completion and type safety directly from Go.
Automatic scan to arbitrary structure removes a lot of headache and boilerplate code needed to structure database query results. This reduces complexity and development time.
With golang jet, you can write complex queries and return results in a single database call, eliminating latency issues between the server and database. This is especially beneficial when dealing with multiple round-trips to the database, which can lead to significant performance penalties.
Here are some key benefits of using golang jet:
golang jet also allows you to join the whole database and store the whole structured result in one database call, which can be done in less than 0.7 seconds. This is a significant improvement over traditional ORM libraries that can introduce performance penalties due to multiple round-trips to the database.
Features
Jet provides an auto-generated type-safe SQL Builder, which is available for PostgreSQL, MySQL, and MariaDB. This feature allows developers to write SQL queries faster and easier.

With Jet, you can automatically generate data model types - Go types mapped to database types, used to store the result of database queries. These types can be combined to create the desired query result destination.
Jet supports query execution with result mapping to arbitrary destination structures, making it easier to retrieve and process data from your database.
The auto-generated data model types and SQL Builder help catch bugs earlier in the development process, reducing the likelihood of expensive bugs being discovered in production.
Jet's auto-generated type-safe SQL Builder and data model types can be used to create complex queries and retrieve results in a single database call, reducing latency and improving performance.
With Cache
The With Cache feature is a game-changer for developers. It allows you to set the cache to use for template parsing results, making your development process more efficient.
By default, Jet uses a concurrency-safe in-memory cache that holds templates forever. This means you don't have to worry about template caching, it's taken care of for you.
You can use InDevelopmentMode() to disable caching of parsed templates if needed. This gives you more control over your development environment.
Explore further: Golang Cache
Configuration and Usage

To use golang jet effectively, you need to have an already defined database schema, including tables and enums.
Jet requires a predefined database schema to generate SQL Builder and Model files, which is a crucial step in the process. This ensures that the generated files are accurate and efficient.
You can generate these files quickly and add them as a pre-build step, making it a seamless process.
Set InMemLoader
Setting up an InMemLoader is a straightforward process. You can add a template to the loader using the Set method.
The Set method is a key part of the InMemLoader's functionality. It allows you to add a template to the loader.
To use the Set method, you'll need to call it on an instance of the InMemLoader. This method is available on the InMemLoader type.
In Development Mode
When working on a project, it's essential to consider your development mode. InDevelopmentMode returns an option function that toggles development mode on, meaning the cache will always be bypassed and every template lookup will go to the loader.
This allows for a more accurate representation of how your project will behave in a live environment, without the interference of a cached version.
For another approach, see: Golang Mode
Go Template Engine
Go Template Engine is a powerful tool for generating dynamic content in Golang. It's easy to use and has a simple, familiar syntax.
Jet, a popular Go template engine, supports template inheritance and composition. This means you can create complex templates by extending and including other templates.
Jet also provides descriptive error messages with filename and line number, making it easier to debug your templates. This is a big plus when working with complex template systems.
Here are some key features of Jet's template engine:
Go Template Engine
Jet is a template engine developed to be easy to use, powerful, dynamic, yet secure and very fast.
One of the key benefits of Jet is its simple and familiar syntax, making it easy to use even for developers who are new to template engines.
The engine supports template inheritance (extends) and composition (block/yield, import, include), giving developers a lot of flexibility when building complex templates.
Jet also provides descriptive error messages with filename and line number, making it easier to debug and identify issues.
Here are some of the key features of Jet:
- simple and familiar syntax
- supports template inheritance (extends) and composition (block/yield, import, include)
- descriptive error messages with filename and line number
- auto-escaping
- simple C-like expressions
- very fast execution
- very light in terms of allocations and memory footprint
The WithTemplateNameExtensions function returns an option function that sets the extensions to try when looking up template names in the cache or loader.
The default extensions are "". (no extension), ".jet", ".html.jet", and ".jet.html".
Type RendererFunc
The Type RendererFunc is a crucial part of the Go Template Engine, allowing you to render data in a custom way.
A RendererFunc is a function that takes a value and a type, and returns a string representation of that value.
In Go, a RendererFunc is defined as a function with a specific signature, (string, string) string, which means it takes two string arguments and returns a string value.
This function is then used by the template engine to render data in a specific format.
You can use a RendererFunc to render data in a custom way, such as formatting dates or numbers.
Suggestion: Golang Types
For example, you can use a RendererFunc to format a date as a string, like this: func (t *TemplateData) formatDate(d string) string { return d }.
This function takes a string date and returns a formatted string representation of that date.
You can then use this function in your template to render the date in the desired format.
By using a custom RendererFunc, you can take control of how your data is rendered in the template.
This allows you to create more complex and customized templates that meet your specific needs.
Func Runtime Let
The Go Template Engine is a powerful tool, and understanding its Func Runtime Let feature is crucial for creating dynamic templates.
The Func Runtime Let feature allows you to initialise a variable in the current template scope, potentially shadowing an existing variable of the same name in a parent scope.
In other words, it creates a new variable with the given name and value, which can be used throughout the template.
The Let function is especially useful when you need to create a variable that will be used multiple times in a template, but you don't want to clutter the template with repeated variable declarations.
For example, if you have a template that needs to display the name of a person, and you also need to display the person's age, you can use the Let function to create a variable for the person's name and then use it throughout the template.
SQL and Querying
Jet makes SQL easy for Go developers, supporting PostgreSQL, MySQL, and MariaDB, with plans to add more database support in future releases.
With Jet, you can write type-safe SQL queries in Go using the generated SQL Builder and Data Model types. These types are customizable, allowing you to catch bugs at compile time.
For example, if someone changes a column length in a table, the next Go build will fail at that line, and the bug will be caught at compile time. Similarly, if someone removes a column from a table, the Film field will be omitted from the SQL Builder and Model types, and the next time Jet generator is run, the build will fail.
Discover more: Golang Build Command
Here's a brief rundown of the generated files folder structure:
Jet's column mapper is very powerful, allowing you to map columns to any value you provide, including structs, slices, and maps.
Generate SQL Types
You can generate SQL Builder and Model types from a running PostgreSQL database using the Jet generator. The process involves connecting to the database, retrieving metadata for all tables, views, and enums within a specific schema, and then generating the necessary types.
To start, connect to your PostgreSQL database and retrieve metadata for all tables, views, and enums within the dvds schema. You'll need to have the necessary permissions to read information schema tables.
Delete all contents in the target schema folder before generating the SQL Builder and Data Model types. This is usually located at ./.gen/jetdb/dvds.
The Jet generator will then generate SQL Builder and Data Model types for each table, view, and enum found in the schema. These types will be stored in the .gen/jetdb/dvds folder.
The generated files will have the following structure:
- Types from the table, view, and enum packages are used to write type-safe SQL queries in Go.
- Types from the model types are combined to store results of the SQL queries.
You can customize the default Jet generator behavior to suit your needs. All aspects of generated SQL Builder and model types are customizable, as described in the wiki.
SQL for Go Developers
As a Go developer, you're in luck - Jet makes SQL a breeze to work with.
Jet currently supports PostgreSQL, MySQL, and MariaDB, so you can get started with your favorite database right away.
Jet's column mapper is incredibly powerful, mapping columns to any value you provide, whether it's a struct, a pointer to a struct, or even a simple value like an integer.
Dependencies and Requirements
To execute Jet SQL statements, you can use any SQL driver that implements Go's standard database/sql interface.
The default SQL driver used by the Jet generator can be replaced if needed by customizing the generator.
The Jet generator executable uses the following SQL drivers to read database schema information by default:
To run the tests, you'll also need to install additional dependencies, including github.com/pkg/profile, github.com/stretchr/testify, and github.com/google/go-cmp.
Prerequisites
To install the Jet package, you need to have certain prerequisites in place.
First and foremost, you'll need to install Go, a programming language that's a requirement for many development projects.
You'll also need to set up your Go workspace, which is a crucial step in getting started with Go.
Specifically, you'll need Go version 1.22 or higher to move forward with the Jet package installation.
Dependencies
To execute Jet SQL statements, you can use ANY SQL driver that implements Go's standard database/sql interface. This flexibility makes it easy to work with different databases.
The default SQL driver used by the Jet generator can be replaced if needed, by customizing the generator. This allows you to switch to a different driver if the default one doesn't meet your needs.
The Jet generator uses the following SQL drivers by default:
- github.com/lib/pq (for PostgreSQL)
- github.com/go-sql-driver/mysql (for MySQL and MariaDB)
These drivers are used to read database schema information, which is essential for Jet to function correctly.
Featured Images: pexels.com


