Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wire: not enough arguments in call to xxx #386

Open
sav7ng opened this issue Jul 17, 2023 · 0 comments
Open

Wire: not enough arguments in call to xxx #386

sav7ng opened this issue Jul 17, 2023 · 0 comments

Comments

@sav7ng
Copy link

sav7ng commented Jul 17, 2023

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
  • main.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)
	}
}

...
  • wire.go
...

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

...
  • extra information GetConfig
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")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant