Skip to content

netlifeguru/examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NetLife Guru Go Examples

Runnable examples for the open-source Go packages maintained by NetLife Guru.

This repository complements the official documentation with small, focused programs that can be read, modified, and executed locally. Each example demonstrates one feature or usage pattern and is organized by package.

Packages

Package Description Examples Documentation
db Shared database layer for queries, execution, transactions, dialect-specific SQL, and result mapping. ./db Documentation
db-mysql MySQL driver for the NetLife Guru database layer. ./db/mysql Documentation
db-postgres PostgreSQL driver for the NetLife Guru database layer. ./db/postgresql Documentation
db-scylla ScyllaDB driver for the NetLife Guru database layer. ./db/scylla Documentation
form Type-safe form and request validation for Go applications. ./form Documentation
logger Structured logging built on top of Go's log/slog. ./logger Documentation
mapper Lightweight database row mapper for structs, maps, and custom handlers. ./mapper Documentation
router Fast HTTP router focused on low-allocation request handling and clean application structure. ./router Documentation

Requirements

  • Go 1.25 or newer
  • Git
  • A supported database for database examples
  • Docker or locally installed database services for examples that require MySQL, PostgreSQL, or ScyllaDB

Getting Started

Clone the repository:

git clone https://github.com/netlifeguru/examples.git
cd examples

Download the dependencies:

go mod download

Run an example by passing its directory to go run:

go run ./router/getting-started
go run ./logger/structured
go run ./form/getting-started

Each example is an independent package main program. Open its directory to inspect the complete source code and any example-specific setup instructions.

Repository Structure

.
├── db/
│   ├── databases/
│   ├── mysql/
│   ├── postgresql/
│   └── scylla/
├── form/
├── logger/
├── mapper/
├── router/
├── go.mod
└── README.md

The top-level directories correspond to NetLife Guru packages. Nested directories contain focused examples for individual features, APIs, and practical use cases.

Database Examples

Database examples may require a running database and environment-specific connection settings.

Schema files are available in db/databases:

db/databases/
├── db_mysql.sql
├── db_postgresql.sql
└── db_scylla.cql

Review the selected example before running it and configure the required connection values. Never commit real credentials or production connection strings.

Typical commands:

go run ./db/mysql/01_getting_started
go run ./db/postgresql/01_getting_started
go run ./db/scylla/01_getting_started

Explore the Examples

DB

The database examples cover connection setup, configuration, connection pools, typed query helpers, dialect-specific SQL, insert/update/delete operations, transactions, batches, lightweight transactions, and SQL model files.

go run ./db/mysql/05_select_list
go run ./db/postgresql/30_transactions
go run ./db/scylla/30_batch

Form

The form examples cover validation rules, optional values, conditional validation, HTTP request validation, custom responses, schema composition, and practical application workflows.

go run ./form/getting-started
go run ./form/practical/registration
go run ./form/httpform/httpform-response

Logger

The logger examples demonstrate initialization, structured fields, chained loggers, context-aware logging, file output, terminal output, source information, and integration with HTTP servers.

go run ./logger/getting-started
go run ./logger/structured
go run ./logger/context_logging

Mapper

The mapper examples demonstrate scanning database rows into structs and maps, nullable values, joins, field tags, naming conversion, custom row converters, caching, partial results, and error handling.

go run ./mapper/usage/01_getting_started
go run ./mapper/usage/03_join
go run ./mapper/edge_cases/01_null_values

Router

The router examples cover route registration, handlers, middleware, groups, mounting, static files, health checks, logging, recovery, rate limiting, profiling, multiple servers, and custom error handling.

go run ./router/default
go run ./router/middleware
go run ./router/custom_error_handler

Most HTTP examples listen on a local port such as :8080. The exact address is visible in the example source.

Build and Verify

Build every example in the repository:

go build ./...

Run all tests:

go test ./...

Run static analysis:

go vet ./...

Clean and verify module dependencies:

go mod tidy
git diff --exit-code -- go.mod go.sum

Documentation

The package documentation explains the APIs and recommended usage patterns. This repository provides complete runnable programs that accompany those guides.

Contributing

Contributions, corrections, and new examples are welcome.

When adding an example:

  1. Place it under the directory of the package it demonstrates.
  2. Keep the example focused on one feature or use case.
  3. Use a standalone package main program whenever possible.
  4. Include comments only where they clarify an important decision.
  5. Do not include secrets, production credentials, or private endpoints.
  6. Make sure go build ./..., go test ./..., and go vet ./... succeed.

Before opening a pull request, format the code and tidy the module:

gofmt -w .
go mod tidy
go test ./...
go vet ./...

Support

For documentation and project information, visit netlife.guru.

For questions and feedback, contact [email protected].

License

This repository is licensed under the MIT License. See LICENSE for details.

About

Example projects for NetLife Guru Go packages.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages