example_quickstart_example

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2025 License: MIT Imports: 14 Imported by: 0

README

ServiceLib Examples

This directory contains complete example applications that demonstrate how to use ServiceLib in real-world scenarios.

Available Examples

Value Object Examples

The following examples demonstrate how to use various value objects from the valueobject package:

  • coordinate_example.go - Demonstrates how to use the Coordinate value object, including creating coordinates, accessing latitude and longitude, calculating distances, and checking hemisphere information.
  • email_example.go - Demonstrates how to use the Email value object, including validation, accessing address and domain components, and domain checking.
  • filesize_example.go - Demonstrates how to use the FileSize value object, including creating file sizes, converting between units, formatting, and performing calculations.
  • id_example.go - Demonstrates how to use the ID value object, including generating random IDs, creating IDs from strings, and comparing IDs.
  • ipaddress_example.go - Demonstrates how to use the IPAddress value object, including creating IPv4 and IPv6 addresses, checking address types, and comparing addresses.
  • money_example.go - Demonstrates how to use the Money value object, including creating Money objects, performing arithmetic operations, comparing values, and handling currency.
  • url_example.go - Demonstrates how to use the URL value object, including creating URLs, accessing components, and comparing URLs.
  • username_example.go - Demonstrates how to use the Username value object, including validation, case conversion, and substring checking.

To run any of these examples:

go run valueobject/example_name.go

For example:

go run valueobject/money_example.go
Auth Examples

The following examples demonstrate how to use various features of the auth package:

To run any of these examples:

go run auth/example_name.go

For example:

go run auth/quickstart_example.go
GraphQL Examples

The following examples demonstrate how to use various features of the graphql package:

To run any of these examples:

go run graphql/example_name.go

For example:

go run graphql/resolver_authorization_example.go
Package-Specific Examples

Examples for individual packages can be found in their respective README.md files:

Contributing Examples

If you'd like to contribute an example application, please follow these guidelines:

  1. Create a new directory with a descriptive name for your example
  2. Include a README.md that explains what the example demonstrates
  3. Keep the example focused on demonstrating a specific use case
  4. Include comments in the code to explain key concepts
  5. Ensure the example follows best practices for Go code
  6. Make sure the example can be run with minimal setup

Running Examples

Each example should include instructions for running it in its README.md file.

Documentation

Overview

This example demonstrates how to use the error handling system in servicelib.

Example of a basic ServiceLib application

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunErrorHandlingExample

func RunErrorHandlingExample()

RunErrorHandlingExample demonstrates how to use the error handling system

Types

type User

type User struct {
	ID    string
	Name  string
	Email string
}

User represents a user in the system

type UserHandler

type UserHandler struct {
	// contains filtered or unexported fields
}

UserHandler is a simple HTTP handler that demonstrates error handling

func NewUserHandler

func NewUserHandler(service *UserService) *UserHandler

NewUserHandler creates a new UserHandler

func (*UserHandler) GetUser

func (h *UserHandler) GetUser(w http.ResponseWriter, r *http.Request)

GetUser handles GET requests for users

type UserService

type UserService struct {
	// contains filtered or unexported fields
}

UserService is a simple service that demonstrates error handling

func NewUserService

func NewUserService(logger *logging.ContextLogger, meter metric.Meter) *UserService

NewUserService creates a new UserService

func (*UserService) GetUserByID

func (s *UserService) GetUserByID(ctx context.Context, id string) (*User, error)

GetUserByID retrieves a user by ID

func (*UserService) ValidateUser

func (s *UserService) ValidateUser(ctx context.Context, user *User) error

ValidateUser validates a user

Directories

Path Synopsis
Example usage of creating an Auth instance
Example usage of creating an Auth instance
Example demonstrating basic usage of the cache package
Example demonstrating basic usage of the cache package
Example demonstrating basic usage of the circuit package
Example demonstrating basic usage of the circuit package
Example of basic usage of the context package
Example of basic usage of the context package
Example of basic usage of the date package
Example of basic usage of the date package
Example of connecting to different database types
Example of connecting to different database types
Example of basic usage of the dependency injection package
Example of basic usage of the dependency injection package
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.
Example demonstrating how to configure the auth service for GraphQL
Example demonstrating how to configure the auth service for GraphQL
Example of basic usage of the health package
Example of basic usage of the health package
Example of basic usage of the logging package
Example of basic usage of the logging package
Example of basic usage of the middleware package
Example of basic usage of the middleware package
Example demonstrating basic usage of the rate package
Example demonstrating basic usage of the rate package
Example of basic repository implementation
Example of basic repository implementation
Example demonstrating basic usage of the retry package
Example demonstrating basic usage of the retry package
Example of basic graceful shutdown
Example of basic graceful shutdown
Example of basic signal handling
Example of basic signal handling
Example of using HTTP instrumentation in the telemetry package
Example of using HTTP instrumentation in the telemetry package
Example of basic saga transaction
Example of basic saga transaction
Example of basic validation using the validation package
Example of basic validation using the validation package
valueobject
appearance
Example usage of the Color value object
Example usage of the Color value object
base
Example usage of the base value object types
Example usage of the base value object types
contact
Example usage of the Email value object
Example usage of the Email value object
identification
Example usage of the ID value object
Example usage of the ID value object
location
Example usage of the Coordinate value object
Example usage of the Coordinate value object
measurement
Example usage of the FileSize value object
Example usage of the FileSize value object
network
Example usage of the IPAddress value object
Example usage of the IPAddress value object
temporal
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