EXAMPLES/

directory
v1.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2025 License: MIT

README

ServiceLib Examples

Overview

This directory contains a collection of examples demonstrating how to use the various components of the ServiceLib library. Each example is a complete, runnable application that showcases specific features and usage patterns.

Example Categories

Authentication & Authorization
Caching
Circuit Breaking
Configuration
Context
Date & Time
Database
Dependency Injection
Environment
Error Handling
GraphQL
Health Checks
Logging
Middleware
Model
Rate Limiting
Recovery
Repository
Retry
Shutdown
Signal
String Utilities
Telemetry
Transaction
Validation
Value Objects

Running the Examples

Each example can be run from its directory using:

go run main.go

Contributing

If you'd like to contribute additional examples, please see the Contributing Guide for more information.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Directories

Path Synopsis
auth
auth_instance command
Example usage of creating an Auth instance
Example usage of creating an Auth instance
authorization command
Example demonstrating authorization concepts
Example demonstrating authorization concepts
configuration command
Example usage of the Auth module configuration
Example usage of the Auth module configuration
context_utilities command
Example demonstrating context utilities for authentication
Example demonstrating context utilities for authentication
error_handling command
Example demonstrating error handling in the auth module
Example demonstrating error handling in the auth module
middleware command
Example usage of the Auth middleware
Example usage of the Auth middleware
quickstart command
Example usage of the Auth module for a quick start
Example usage of the Auth module for a quick start
token_handling command
Example demonstrating the concept of token handling in authentication
Example demonstrating the concept of token handling in authentication
user_info command
Example demonstrating how to get user information from the context
Example demonstrating how to get user information from the context
cache
basic_usage command
Example demonstrating basic usage of the cache package
Example demonstrating basic usage of the cache package
custom_configuration command
Example demonstrating custom configuration of the cache package
Example demonstrating custom configuration of the cache package
circuit
basic_usage command
Example demonstrating basic usage of the circuit package
Example demonstrating basic usage of the circuit package
custom_configuration command
Example demonstrating custom configuration of the circuit package
Example demonstrating custom configuration of the circuit package
config
app_config command
Example of implementing and using the AppConfig interface
Example of implementing and using the AppConfig interface
basic_usage command
Example of basic usage of the config package
Example of basic usage of the config package
custom_adapter command
Example of creating a custom adapter for the config package
Example of creating a custom adapter for the config package
database_config command
Example of implementing and using the DatabaseConfig interface
Example of implementing and using the DatabaseConfig interface
Example of error handling with the context package
Example of error handling with the context package
basic_usage command
Example of basic usage of the context package
Example of basic usage of the context package
timeout command
Example of using timeouts with the context package
Example of using timeouts with the context package
value_propagation command
Example of value propagation with the context package
Example of value propagation with the context package
date
basic_usage command
Example of basic usage of the date package
Example of basic usage of the date package
error_handling command
Example of error handling with the date package
Example of error handling with the date package
optional_date command
Example of working with optional dates using the date package
Example of working with optional dates using the date package
time_zone command
Example of working with time zones using the date package
Example of working with time zones using the date package
db
connection command
Example of connecting to different database types
Example of connecting to different database types
health_check command
Example of checking database health
Example of checking database health
query command
Example of executing queries with different database types
Example of executing queries with different database types
repository command
Example of implementing the repository pattern with the db package
Example of implementing the repository pattern with the db package
retry command
Example of executing queries with retries
Example of executing queries with retries
transaction command
Example of using transactions with different database types
Example of using transactions with different database types
di
basic_usage command
Example of basic usage of the dependency injection package
Example of basic usage of the dependency injection package
generic_container command
Example of using the generic container from the dependency injection package
Example of using the generic container from the dependency injection package
service_container command
Example of using the service container from the dependency injection package
Example of using the service container from the dependency injection package
errors
basic_error_creation command
This example demonstrates how to create different types of errors using the errors package.
This example demonstrates how to create different types of errors using the errors package.
error_categorization command
This example demonstrates how to categorize and handle different types of errors.
This example demonstrates how to categorize and handle different types of errors.
error_context command
This example demonstrates how to add and retrieve context information from errors.
This example demonstrates how to add and retrieve context information from errors.
error_wrapping command
This example demonstrates how to wrap errors to add context as they propagate up the call stack.
This example demonstrates how to wrap errors to add context as they propagate up the call stack.
stack_traces command
This example demonstrates how to include and retrieve caller information from errors.
This example demonstrates how to include and retrieve caller information from errors.
graphql
auth_middleware command
authorization command
Example demonstrating how to check authorization in GraphQL operations
Example demonstrating how to check authorization in GraphQL operations
directive_registration command
Example demonstrating how to register the @isAuthorized directive in a GraphQL server
Example demonstrating how to register the @isAuthorized directive in a GraphQL server
jwt_token_generation command
Example demonstrating how to generate JWT tokens for testing GraphQL RBAC
Example demonstrating how to generate JWT tokens for testing GraphQL RBAC
resolver_authorization command
Example demonstrating how to check authorization in a GraphQL resolver
Example demonstrating how to check authorization in a GraphQL resolver
health
basic_usage command
Example of basic usage of the health package
Example of basic usage of the health package
custom_health_status command
Example of creating a custom health status response
Example of creating a custom health status response
logging
basic_usage command
Example of basic usage of the logging package
Example of basic usage of the logging package
context_aware_logging command
Example of context-aware logging
Example of context-aware logging
trace_id command
Example of adding trace IDs to logs
Example of adding trace IDs to logs
middleware
basic_usage command
Example of basic usage of the middleware package
Example of basic usage of the middleware package
cors command
Example of using the CORS middleware
Example of using the CORS middleware
error_handling command
Example of using the error handling middleware
Example of using the error handling middleware
logging command
Example of using the logging middleware
Example of using the logging middleware
recovery command
Example of using the recovery middleware
Example of using the recovery middleware
timeout command
Example of using the timeout middleware
Example of using the timeout middleware
rate
basic_usage command
Example demonstrating basic usage of the rate package
Example demonstrating basic usage of the rate package
custom_configuration command
Example demonstrating custom configuration of the rate package
Example demonstrating custom configuration of the rate package
recovery
circuit_breaker command
repository
basic_repository_example command
Example of basic repository implementation
Example of basic repository implementation
dependency_injection_example command
Example of integration with dependency injection
Example of integration with dependency injection
repository_factory_example command
Example of using repository factory
Example of using repository factory
retry
basic_usage command
Example demonstrating basic usage of the retry package
Example demonstrating basic usage of the retry package
custom_configuration command
Example demonstrating custom configuration of the retry package
Example demonstrating custom configuration of the retry package
error_detection command
Example demonstrating custom error detection with the retry package
Example demonstrating custom error detection with the retry package
logging_tracing command
Example demonstrating logging and tracing with the retry package
Example demonstrating logging and tracing with the retry package
shutdown
basic_usage_example command
Example of basic graceful shutdown
Example of basic graceful shutdown
multiple_resource_example command
Example of shutting down multiple resources
Example of shutting down multiple resources
programmatic_shutdown_example command
Example of programmatic shutdown initiation
Example of programmatic shutdown initiation
signal
basic_signal_handling_example command
Example of basic signal handling
Example of basic signal handling
manual_cancellation_example command
Example of manual cancellation with HandleShutdown
Example of manual cancellation with HandleShutdown
shutdown_callbacks_example command
Example of using shutdown callbacks
Example of using shutdown callbacks
telemetry
http_instrumentation_example command
Example of using HTTP instrumentation in the telemetry package
Example of using HTTP instrumentation in the telemetry package
initialization_example command
Example of initializing the telemetry package
Example of initializing the telemetry package
metrics_example command
Example of using metrics functionality in the telemetry package
Example of using metrics functionality in the telemetry package
prometheus_integration_example command
Example of integrating with Prometheus in the telemetry package
Example of integrating with Prometheus in the telemetry package
tracing_example command
Example of using tracing functionality in the telemetry package
Example of using tracing functionality in the telemetry package
transaction
basic_saga_example command
Example of basic saga transaction
Example of basic saga transaction
basic_usage_example command
Example of basic usage of the transaction package with WithTransaction function
Example of basic usage of the transaction package with WithTransaction function
context_timeout_example command
Example of using context with timeout in transactions
Example of using context with timeout in transactions
custom_transaction_example command
Example of custom transaction execution
Example of custom transaction execution
error_handling_example command
Example of error handling with checked rollbacks
Example of error handling with checked rollbacks
idempotent_operations_example command
Example of idempotent operations in transactions
Example of idempotent operations in transactions
validation
basic_validation_example command
Example of basic validation using the validation package
Example of basic validation using the validation package
collection_validation_example command
Example of collection validation using the validation package
Example of collection validation using the validation package
custom_validation_example command
Example of custom validation using the validation package
Example of custom validation using the validation package
date_validation_example command
Example of date validation using the validation package
Example of date validation using the validation package
valueobject
appearance/color_example command
Example usage of the Color value object
Example usage of the Color value object
base/base_example command
Example usage of the base value object types
Example usage of the base value object types
contact/email_example command
Example usage of the Email value object
Example usage of the Email value object
identification/id_example command
Example usage of the ID value object
Example usage of the ID value object
identification/username_example command
Example usage of the Username value object
Example usage of the Username value object
location/coordinate_example command
Example usage of the Coordinate value object
Example usage of the Coordinate value object
measurement/filesize_example command
Example usage of the FileSize value object
Example usage of the FileSize value object
measurement/money_example command
Example usage of the Money value object
Example usage of the Money value object
network/ipaddress_example command
Example usage of the IPAddress value object
Example usage of the IPAddress value object
network/url_example command
Example usage of the URL value object
Example usage of the URL value object
temporal/time_example command
Example usage of the Time value object
Example usage of the Time value object

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL