core

module
v0.0.0-...-89aa834 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: MIT

README ยถ

๐Ÿš€ gopherd/core

Go Reference Go Report Card codecov Build Status License

gopherd/core is a Go library that provides a component-based development framework for building backend services, leveraging the power of Go's generics. It's a modern, type-safe approach to creating scalable applications! ๐ŸŒŸ

๐ŸŒŸ Overview

This library offers a state-of-the-art mechanism for component-based development, enabling Go developers to create highly modular and maintainable backend services. By harnessing the power of gopherd/core and Go's generics, developers can:

  • ๐Ÿงฉ Easily create and manage type-safe components for various functionalities (e.g., database connections, caching, authentication)
  • ๐Ÿ”Œ Implement a plugin-like architecture for extensible services with compile-time type checking
  • ๐Ÿ› ๏ธ Utilize a set of fundamental helper functions to streamline common tasks, all with the benefits of generics

The component-based approach, combined with Go's generics, allows for better organization, reusability, and scalability of your Go backend services. It's like LEGO for your code, but with perfect fit guaranteed by the type system! ๐Ÿงฑโœจ

๐Ÿ”ฅ Key Features

  • Modern, generic-based architecture: Leverage Go's generics for type-safe component creation and management
  • Flexible configuration: Load configurations from files, URLs, or standard input with type safety
  • Template processing: Use Go templates in your component configurations for dynamic setups
  • Multiple format support: Handle JSON, TOML, YAML, and other arbitrary configuration formats through encoders and decoders
  • Automatic dependency injection: Simplify component integration with built-in dependency resolution and injection

๐Ÿ“ฆ Installation

To use gopherd/core in your Go project, install it using go get:

go get github.com/gopherd/core

โšก Quick Start

Here's a simple example showcasing the power of generics in our library:

// demo/main.go
package main

import (
	"context"
	"fmt"

	"github.com/gopherd/core/component"
	"github.com/gopherd/core/service"
)

// helloComponent demonstrates the use of generics for type-safe options.
type helloComponent struct {
	component.BaseComponent[struct {
		Message string
	}]
}

func (c *helloComponent) Init(ctx context.Context) error {
	fmt.Println("Hello, " + c.Options().Message + "!")
	return nil
}

func init() {
	component.Register("hello", func() component.Component { return &helloComponent{} })
}

func main() {
	service.Run()
}

Yes, it's that simple and type-safe! ๐Ÿ˜ฎ With just these few lines of code, you can leverage the power of our generic-based, component-driven architecture. The simplicity of this example demonstrates how our library abstracts away the complexities of component management while maintaining type safety, allowing you to focus on building your application logic. Modern magic, right? โœจ๐Ÿ”ฎ

Basic Usage

Run your application with a configuration file:

./demo app.json

Here's an example app.json

{
	"Components": [
		{
			"Name": "hello",
			"Options": {
				"Message": "world"
			}
		}
	]
}
Load Configuration from Different Sources
  • From a file: ./demo app.json ๐Ÿ“„
  • From a URL: ./demo http://example.com/config/app.json ๐ŸŒ
  • From stdin: echo '{"Components":[...]}' | ./demo - โŒจ๏ธ
Command-line Options
  • -p: Print the configuration ๐Ÿ–จ๏ธ
  • -t: Test the configuration for validity โœ…
  • -T: Enable template processing for component configurations ๐Ÿงฉ

๐ŸŽ“ Example Project

For a more comprehensive example of how to use gopherd/core in a real-world scenario, check out our example project:

https://github.com/gopherd/example

This project demonstrates how to build a modular backend service using gopherd/core, including:

  • Setting up multiple components
  • Configuring dependencies between components
  • Using the event system
  • Implementing authentication and user management

It's a great resource for understanding how all the pieces fit together in a larger application! ๐Ÿงฉ

๐Ÿ“š Documentation

For detailed documentation of each package and component, please refer to the GoDoc:

https://pkg.go.dev/github.com/gopherd/core

๐Ÿ‘ฅ Contributing

Contributions are welcome! Please feel free to submit a Pull Request. Let's make this library even more awesome together! ๐Ÿค

๐Ÿ“œ License

This project is licensed under the MIT License.

๐Ÿ†˜ Support

If you encounter any problems or have any questions, please open an issue in this repository. We're here to help! ๐Ÿ’ช


We hope you find gopherd/core valuable for your modern Go backend projects! Whether you're building a small microservice or a complex distributed system, gopherd/core provides the foundation for creating modular, maintainable, and efficient backend services with the power of generics. Welcome to the future of Go development! ๐Ÿš€๐ŸŽ‰

Directories ยถ

Path Synopsis
Package builder provides utilities for managing and displaying build information.
Package builder provides utilities for managing and displaying build information.
Package component provides a flexible and extensible component system for building modular applications.
Package component provides a flexible and extensible component system for building modular applications.
Package constraints provides type constraints for generic programming in Go.
Package constraints provides type constraints for generic programming in Go.
container
heap
Package heap provides a generic heap implementation.
Package heap provides a generic heap implementation.
history
Package history provides data structures with undo functionality.
Package history provides data structures with undo functionality.
iters
Package iters provides utility functions for working with iterators and sequences.
Package iters provides utility functions for working with iterators and sequences.
pair
Package pair provides a generic Pair type for holding two values of any types.
Package pair provides a generic Pair type for holding two values of any types.
tree
Package tree provides functionality for working with tree-like data structures.
Package tree provides functionality for working with tree-like data structures.
trie
Package trie implements a prefix tree (trie) data structure.
Package trie implements a prefix tree (trie) data structure.
Package encoding provides interfaces, utilities, and common functions for encoding and decoding data in various formats.
Package encoding provides interfaces, utilities, and common functions for encoding and decoding data in various formats.
Package enum provides a way to register enum descriptors and lookup them by name.
Package enum provides a way to register enum descriptors and lookup them by name.
Package errkit provides a flexible error code mechanism for Go applications.
Package errkit provides a flexible error code mechanism for Go applications.
Package event provides a generic event handling system.
Package event provides a generic event handling system.
Package flags provides custom flag types and utilities.
Package flags provides custom flag types and utilities.
Package lifecycle provides interfaces and types for managing the lifecycle of components.
Package lifecycle provides interfaces and types for managing the lifecycle of components.
math
mathutil
Package mathutil provides various mathematical utility functions.
Package mathutil provides various mathematical utility functions.
Package op provides a set of generic functions that extend and complement Go's built-in operators and basic operations.
Package op provides a set of generic functions that extend and complement Go's built-in operators and basic operations.
Package service provides a framework for creating and managing service processes with support for configuration loading, lifecycle management, and component handling.
Package service provides a framework for creating and managing service processes with support for configuration loading, lifecycle management, and component handling.
Package term provides terminal-related utilities.
Package term provides terminal-related utilities.
document
Package document provides efficient document indexing and updating capabilities for text editors and language servers.
Package document provides efficient document indexing and updating capabilities for text editors and language servers.
templates
Package templates provides utility functions for working with Go templates.
Package templates provides utility functions for working with Go templates.
Package typing provides utilities for handling raw data objects and wraps basic Go types with additional functionality.
Package typing provides utilities for handling raw data objects and wraps basic Go types with additional functionality.

Jump to

Keyboard shortcuts

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