Skip to content

Simplify and Graceful Golang Code. Features include: auto-wiring

License

Notifications You must be signed in to change notification settings

peace0phmind/bud

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bud: Simplify and Graceful Golang Code

Simplify and Graceful Golang Code. Features include: auto-wiring, stream api, ... more TODO

Feature List

  • wire: Runtime Dynamic Auto-Wiring Using Dependency Injection
  • stream: stream api like java to deal with slice
  • enum: TODO
  • trace-log: TODO
  • config: TODO
  • plugin: TODO
  • util: TODO
  • remote: TODO:
  • sys info: TODO: github.com/shirou/gopsutil

wire

Runtime Dynamic Auto-Wiring Using Dependency Injection

Wire is a tool for automating the wiring of components at runtime using dependency injection. The dependencies between components can be defined by the tag marked on the field of the struct, or by the parameters of the Init method.

easy start

repository struct looks like

package repo

import "github.com/peace0phmind/bud/factory"

func init() {
	factory.Singleton[MyRepo]() // registry MyRepo as a singleton service
}

// MyRepo to control model with db
type MyRepo struct {
	//...
}

func (mr *MyRepo) SaveData() {
	//...
}

service struct looks like

package service

import "github.com/peace0phmind/bud/factory"
import "repo"

func init() {
	factory.Singleton[MyService]() // registry MyRepo as a singleton service
}

type MyService struct {
	myRepo *repo.MyRepo `wire:"auto"`
}

func (ms *MyService) DoSomething() {
	// ...
	ms.myRepo.SaveDate()
	// ...
}

main.go

package main

import "github.com/peace0phmind/bud/factory"
import "service"

func main() {
	serv := factory.Get[servcie.MyService]()

	serv.DoSomething()
}

About

Simplify and Graceful Golang Code. Features include: auto-wiring

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages