golang auto wire code generator

Go-AutoWire

helps you to generate wire files with easy annotate

中文文档

this project is base on wire

but it did simplify the wire usage and make wire much more stronger

Installation

Install Wire by running:

go get github.com/google/wire/cmd/wire

then

Install Gutowire by running:

go get github.com/Just-maple/go-autowire/cmd/gutowire

and ensuring that $GOPATH/bin is added to your $PATH.

Usage example

If you want to build a zoo,you may need some dependencies like animals

package example

type Zoo struct{ 
    Cat         Cat
    Dog         Dog
    FlyAnimal FlyAnimal
}

type Cat struct{
}

type FlyAnimal interface{
    Fly()
}

type Bird struct{
}

func (b Bird)Fly(){
}

type Dog struct{
}

in traditional wire,you need to write some files to explain the wire relation to google/wire

package example_zoo

import (
	"github.com/google/wire"
)

var zooSet = wire.NewSet(
	wire.Struct(new(Zoo), "*"),
)

var animalsSet = wire.NewSet(
	wire.Struct(new(Cat), "*"),
	wire.Struct(new(Dog), "*"),

	wire.Struct(new(Bird), "*"),
	wire.Bind(new(FlyAnimal), new(Bird)),
)

var sets = wire.NewSet(zooSet, animalsSet)

func InitZoo() Zoo {
	panic(wire.Build(sets))
}

you need to rewrite your wire.go and comes much more harder to manager all the dependencies

as your zoo goes bigger and bigger

but now

you can use gutowire

write annotate as below

package example

// @autowire.init(set=zoo)
// it will be collect into zooSet (this comment is not necessary)
type Zoo struct{ 
    Cat         Cat
    Dog         Dog
    FlyAnimal FlyAnimal
}

// it will be collect into animalsSet (this comment is not necessary)
// @autowire(set=animals)
type Cat struct{
}


type FlyAnimal interface{
    Fly()
}

// it will be collect into animalsSet and wire as interface FlyAnimal (this comment is not necessary)
// @autowire(set=animals,FlyAnimal)
type Bird struct{
}

func (b Bird)Fly(){
}

// it will be collect into animalsSet (this comment is not necessary)
// @autowire(set=animals)
type Dog struct{
}

.init in @autowire.init(set=zoo) will auto write InitializeZoo func in wire.gen.go like below:

// Code generated by go-autowire. DO NOT EDIT.

// +build wireinject
//
package example_zoo

import "github.com/google/wire"

func InitializeZoo() (*Zoo, func(), error) {
	panic(wire.Build(Sets))
}

and run

gutowire -s ./example_zoo ./example_zoo

-s means scope to look up build dependencies

all the wire files you need will generate

look at file generated in example_zoo

Similar Resources

Clean-Swift source and test code auto-generator. It can save you time typing 500-600 lines of code.

Clean-Swift source and test code auto-generator. It can save you time typing 500-600 lines of code.

Clean-Swift source & test code auto generator Overview Run Output Basic Usage make config.yaml target_project_name: Miro // target project name copyri

Apr 13, 2022

Git-auto-push - Auto commit and push to github repositories

Auto commit and push to github repositories. How to use git clone https://github

Dec 19, 2022

RabbitMQ wire tap and swiss army knife

RabbitMQ wire tap and swiss army knife

rabtap - RabbitMQ wire tap Swiss army knife for RabbitMQ. Tap/Pub/Sub messages, create/delete/bind queues and exchanges, inspect broker. Contents Feat

Dec 28, 2022

RBAC scaffolding based on Gin + Gorm+ Casbin + Wire

RBAC scaffolding based on Gin + Gorm+ Casbin + Wire

Gin Admin 基于 GIN + GORM + CASBIN + WIRE 实现的RBAC权限管理脚手架,目的是提供一套轻量的中后台开发框架,方便、快速的完成业务需求的开发。 特性 遵循 RESTful API 设计规范 & 基于接口的编程规范 基于 GIN 框架,提供了丰富的中间件支持(JWT

Dec 28, 2022

wire protocol for multiplexing connections or streams into a single connection, based on a subset of the SSH Connection Protocol

qmux qmux is a wire protocol for multiplexing connections or streams into a single connection. It is based on the SSH Connection Protocol, which is th

Dec 26, 2022

Jacket of spf13/viper: Simplified go configuration for wire-jacket.

Viper-Jacket: viper config for Wire-Jacket Jacket of spf13/viper: config for wire-jacket. Simplified env-based go configuration package using viper. b

Nov 18, 2021

Wire: Automated Initialization in Go

Wire: Automated Initialization in Go Wire is a code generation tool that automates connecting components using dependency injection. Dependencies betw

Dec 10, 2021

Experimental wire-format protobuf canonicalizer

wirepb This repository implements an experimental wire-format canonical string format for protocol buffer messages. Specifically, the wirepb.Canonical

Oct 25, 2022

Toy-redis-mock - Experimentation with parsing the redis wire protocol from scratch

Overview Simple app for practicing implementing server-side Redis wire protocol

Jan 9, 2022

An experimental toolkit for injecting alternate authentication strategies into a PostgreSQL-compatible wire format.

PG Auth Proxy This is an experimental toolkit for injecting alternate authentication strategies into a PostgreSQL-compatible wire format. This is a pr

Jan 20, 2022

gonewire: one wire library that uses the w1 kernel module

gonewire one wire library that uses the w1 kernel module. current support: DS18(S)20

Jan 25, 2022

Grafana-threema-forwarder - Alert forwarder from Grafana webhooks to Threema wire messages

Grafana to Threema alert forwarder Although Grafana has built in support for pus

Nov 11, 2022

Mgosniff: MongoDB Wire Protocol Analysis Tools

mgosniff - MongoDB Wire Protocol Analysis Tools Reference: MongoDB Wire Protocol

Feb 18, 2022

Auto-evaluate your Golang code.

Auto-evaluate your Golang code.

Ginker Ginker is a GUI application for auto-evaluating your Golang code. It allows you to write and run Golang code on the fly and it will help you to

Jun 24, 2021

Auto-gen fuzzing wrappers from normal code. Automatically find buggy call sequences, including data races & deadlocks. Supports rich signature types.

fzgen fzgen auto-generates fuzzing wrappers for Go 1.18, optionally finds problematic API call sequences, can automatically wire outputs to inputs acr

Dec 23, 2022

VS Code code snippet generator

VS Code code snippets generator.

Sep 2, 2022

Code generator that generates boilerplate code for a go http server

http-bootstrapper This is a code generator that uses go templates to generate a bootstrap code for a go http server. Usage Generate go http server cod

Nov 20, 2021

AI-powered code snippet generator using ChatGPT. Generate code in various languages based on natural language descriptions!

SnipForge - AI-Powered Code Snippet Generator SnipForge is a powerful command-line interface (CLI) tool that utilizes OpenAI's GPT technology to gener

May 5, 2023

Test your code without writing mocks with ephemeral Docker containers 📦 Setup popular services with just a couple lines of code ⏱️ No bash, no yaml, only code 💻

Gnomock – tests without mocks 🏗️ Spin up entire dependency stack 🎁 Setup initial dependency state – easily! 🏭 Test against actual, close to product

Dec 29, 2022
Comments
  • 当接口定义interface和实现类struct不在同一个包中会报错

    当接口定义interface和实现类struct不在同一个包中会报错

    我的项目结构 image

    项目这么设计是想做依赖倒置,但是引入autowire运行生成代码会报错如下

    [gutowire] [gen failed] wire: /Users/user/code/quants/autowire/autowire_repository.go:13:22: ITradeRepo not declared by package mysql

Wire: Automated Initialization in Go

Wire: Automated Initialization in Go Wire is a code generation tool that automates connecting components using dependency injection. Dependencies betw

Dec 10, 2021
Experimental wire-format protobuf canonicalizer

wirepb This repository implements an experimental wire-format canonical string format for protocol buffer messages. Specifically, the wirepb.Canonical

Oct 25, 2022
Mgosniff: MongoDB Wire Protocol Analysis Tools

mgosniff - MongoDB Wire Protocol Analysis Tools Reference: MongoDB Wire Protocol

Feb 18, 2022
An additive dependency injection container for Golang.

Alice Alice is an additive dependency injection container for Golang. Philosophy Design philosophy behind Alice: The application components should not

Oct 16, 2022
Strict Runtime Dependency Injection for Golang

wire Wire is runtime depedency injection/wiring for golang. It's designed to be strict to avoid your go application running without proper dependency

Sep 27, 2022
Generated dependency injection containers in go (golang)
Generated dependency injection containers in go (golang)

Generation of dependency injection containers for go programs (golang). Dingo is a code generator. It generates dependency injection containers based

Dec 22, 2022
Golang PE injection on windows

GoPEInjection Golang PE injection on windows See: https://malwareunicorn.org/workshops/peinjection.html Based on Cryptowall's PE injection technique.

Jan 6, 2023
two scripts written in golang that will help you recognize dependency confusion.
two scripts written in golang that will help you recognize dependency confusion.

two scripts written in golang that will help you recognize dependency confusion.

Mar 3, 2022
golang-runtime-di is a framework for runtime dependency injection in go

golang-runtime-di description golang-runtime-di is a framework for runtime dependency injection in go. usage quickstart add it to your go.mod: go get

Aug 1, 2022
Jacket of google/wire: advanced DI approach wrapping google/wire for cloud.
Jacket of google/wire: advanced DI approach wrapping google/wire for cloud.

Wire-Jacket: IoC Container of google/wire for cloud-native Jacket of google/wire: advanced DI approach wrapping google/wire for cloud. google/wire : h

Nov 21, 2022