google / wire

Compile-time Dependency Injection for Go
Apache License 2.0
13.14k stars 625 forks source link

Wire: not enough arguments in call to xxx #386

Open sav7ng opened 1 year ago

sav7ng commented 1 year ago

Describe the bug

When using wire to generate code, the console prompts an error message

$ wire
wire: E:\product-channel-beauty-order-service\internal\cmd\main.go:69:35: not enough arguments in call to misc.GetConfig
wire: generate failed

Tried to search for a solution but did not find a way, I hope you can help to investigate

To Reproduce

Execute the wire command in the cmd directory to reproduce

$ wire
wire: E:\product-channel-beauty-order-service\internal\cmd\main.go:69:35: not enough arguments in call to misc.GetConfig
wire: generate failed

Expected behavior

Personally think that the problem is caused by the generic type of [T any]go

Version

go version: 1.20 wire version: v0.5.0

Additional context

├─cmd
│      main.go
│      wire.go
...

func main() {
    flag.Parse()
    logger := log.With(log.NewStdLogger(os.Stdout),
        "ts", func(context.Context) interface{} {
            z := time.FixedZone("GMT", 8)
            return time.Now().In(z).Format("2006-01-02 15:04:05")
        },
        "caller", log.DefaultCaller,
        "host", Host,
        "trace.id", tracing.TraceID(),
        "span.id", tracing.SpanID(),
    )
    abs, err := filepath.Abs(flagconf)
    if err != nil {
        panic(err)
    }
    var bc internal.Bootstrap
    if err := misc.GetConfig(abs, &bc); err != nil {
        panic(err)
    }
    app, cleanup, err := wireApp(&bc, logger)
    if err != nil {
        panic(err)
    }
    defer cleanup()

    // start and wait for stop signal
    if err := app.Run(); err != nil {
        panic(err)
    }
}

...
...

func wireApp(*internal.Bootstrap, log.Logger) (*kratos.App, func(), error) {
    panic(wire.Build(data.DataProviderSets, server.ServerProviderSets, depends.DependsProviderSets, service.ServiceProviderSets, newApp))
}

...
package misc

import (
    "github.com/go-kratos/kratos/v2/log"
    "github.com/pkg/errors"
    "gopkg.in/yaml.v3"
    "os"
)

func GetConfig[T any](path string, t *T) error {
    file, err := os.ReadFile(path)
    if err != nil {
        log.Errorf("read config failed:%v", err)
        return err
    }
    err = yaml.Unmarshal(file, t)
    if err == nil {
        return nil
    }
    err = JSON.Unmarshal(file, t)
    if err == nil {
        return nil
    }
    return errors.New("unrecognized file")
}