Skip to content
/ gone Public

Gone is a lightweight dependency injection framework for Golang, designed to integrate with a variety of third-party components, enabling rapid development of cloud-native micro services.

License

Notifications You must be signed in to change notification settings

gone-io/gone

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

English  |  δΈ­ζ–‡

license GoDoc Go Report Card codecov Build and Test Release Mentioned in Awesome Go

logo

Gone

Gone is a Golang tag-based dependency injection framework

Gone is a lightweight golang dependency injection framework. Here's a simple example (a structure that embeds gone.Flag, which we call a "Goner"):

package main
import "github.com/gone-io/gone/v2"

type Dep struct {
    gone.Flag
    Name string
}
type Component struct {
    gone.Flag
    dep *Dep        `gone:"*"` //dependency injection
    log gone.Logger `gone:"*"`
}
func (c *Component) Init() {
    c.log.Infof(c.dep.Name) //using dependency
}
func main() {
    gone.
       NewApp().
       // Register and load components
       Load(&Dep{Name: "Component Dep"}).
       Load(&Component{}).
       //run
       Run()
}

Features

  • Supports struct property injection, including private field injection πŸ‘‰πŸ» Dependency Injection Introduction
  • Supports function parameter injection, injecting by function parameter type πŸ‘‰πŸ» Dependency Injection Introduction
  • Provider mechanism, supports injecting external components into Goners: πŸ‘‰πŸ» Gone V2 Provider Mechanism Introduction
  • Supports code generation, automatically completing component registration and loading (via Gonectr)
  • Supports interface-based mock unit testing
  • Supports Goner components for microservice development
  • Supports defining initialization methods Init() and BeforeInit() for Goners
  • Supports writing service-type Goners: implementing Start() error and Stop() error, the framework will automatically call Start() and Stop() methods
  • Supports hooks like BeforeStart, AfterStart, BeforeStop, AfterStop for executing custom operations when services start and stop

Architecture

architecture

Lifecycle

flow

Quick Start

  1. Install gonectr and mockgen
    go install github.com/gone-io/gonectr@latest
    go install go.uber.org/mock/mockgen@latest
  2. Create a project
    gonectr create myproject
  3. Run the project
    cd myproject
    go mod tidy
    gonectr run ./cmd/server

Update History

v2.0.5

  • Added option:"lazy" tag to support lazy field injection, see documentation
  • Note: Fields marked with option:"lazy" cannot be used in the Init, Provide, and Inject methods

v2.0.4

  • Added SetValue function for unified handling of various configuration value types
  • Refactored existing type handling logic, using reflection to improve generality

v2.0.3

v2.0.0

Version 2 has been extensively updated, removing unnecessary concepts. Please refer to: Gone@v2 Instructions before use.

v1.2.1

  • Defined gone.Provider, a factory function for injecting external components (structs, struct pointers, functions, interfaces) that are not Goners into Goner properties requiring injection
  • Fixed gone.NewProviderPriest which couldn't generate Priests for interface-type gone.Provider
  • Wrote test code for goner/gorm, completed other test codes; documentation updated.

v1.2.0

  • Provided a new gone.GonerOption that can inject by type, delegating the task of constructing type instances to a Goner that implements Suck(conf string, v reflect.Value, field reflect.StructField) error
  • Provided a helper function for implementing Goner Provider: func NewProviderPriest[T any, P any](fn func(tagConf string, param P) (T, error)) Priest
  • Provided strategy configuration for cluster mode in goner/xorm
  • Improved goner/gorm code and functional testing, supporting connection to various databases.

v1.1.1

  • goner/xorm supports clusters and multiple databases, latest documentation: https://goner.fun/zh/references/xorm.html
  • Added goner/gorm, encapsulating gorm.io/gorm for database access, currently only supports MySQL, in progress...

Contribution

If you find errors or have feature requests, feel free to submit an issue, and pull requests are welcome.

Contact

If you have any questions, please contact us through:

License

gone is released under the MIT License, please see the LICENSE file for details.

About

Gone is a lightweight dependency injection framework for Golang, designed to integrate with a variety of third-party components, enabling rapid development of cloud-native micro services.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Languages