Skip to content

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"funcinit() {
factory.Singleton[MyRepo]() // registry MyRepo as a singleton service
}
// MyRepo to control model with dbtypeMyRepostruct {
//...
}
func (mr*MyRepo) SaveData() {
//...
}

service struct looks like

package service
import"github.com/peace0phmind/bud/factory"import"repo"funcinit() {
factory.Singleton[MyService]() // registry MyRepo as a singleton service
}
typeMyServicestruct {
myRepo*repo.MyRepo`wire:"auto"`
}
func (ms*MyService) DoSomething() {
// ...ms.myRepo.SaveDate()
// ...
}

main.go

package main
import"github.com/peace0phmind/bud/factory"import"service"funcmain() {
serv:=factory.Get[servcie.MyService]()
serv.DoSomething()
}

About

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

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages