zenrpc icon indicating copy to clipboard operation
zenrpc copied to clipboard

Generates code from imported types

Open smyrman opened this issue 4 years ago • 2 comments

When running zenrpc in a package that both defines and imports a zenrpc.Service type, then it will generate (incorrect) code for the imported services.

I.e. if having:

cmd/mycmd
    main_zenrpc.go -- generated
    service.go -- defines FooService
    server.go -- register FooService and pkg/bar.Service
pkg/bar
   bar_zenrpc.go -- generated
   service.go -- defines Service

When generating the code in cmd/mycmd then it will generate code for Service (which does not exist in the package) as well as FooService, which does exist. It will also, for some reason, import encoding/json twise. Either way, the result is invalid code.

Maybe related with #35?

smyrman avatar Feb 12 '21 14:02 smyrman

Should be working now, please confirm

dizzyfool avatar Mar 23 '21 18:03 dizzyfool

Sorry for the late update. It seams that we no longer get the additional Service generation. However, we still get a duplicated import:

Import:

import (
	"context"
	"encoding/json"

	"github.com/semrush/zenrpc/v2"
	"github.com/semrush/zenrpc/v2/smd"

	"encoding/json"
)

smyrman avatar Apr 26 '21 07:04 smyrman