vburenin / ifacemaker

Generate interfaces from structure methods.
Apache License 2.0
320 stars 43 forks source link

Missing import package in generated interface file #44

Closed wych42 closed 3 years ago

wych42 commented 3 years ago

Using example in README:

package main

import (
    "fmt"
    "github.com/volatiletech/null/v8"
)

type Human struct {
    name string
    age  int
}

// Returns the name of our Human.
func (h *Human) GetName() string {
    return h.name
}

// Our Human just had a birthday! Increase its age.
func (h *Human) Birthday() {
    h.age += 1
    fmt.Printf("I am now %d years old!\n", h.age)
}

// Make the Human say hello.
func (h *Human) SayHello() {
    fmt.Printf("Hello, my name is %s, and I am %d years old.\n", h.name, h.age)
}

func (h *Human) SetName(name null.String) {
    if name.Valid {
        h.name = name.String
    }
}

func main() {
    human := &Human{name: "Bob", age: 30}
    human.GetName()
    human.SayHello()
    human.Birthday()
}

Command: ifacemaker -f human.go -s Human -i HumanIface -p humantest will output

package humantest

type HumanIface interface {
    // Returns the name of our Human.
    GetName() string
    // Our Human just had a birthday! Increase its age.
    Birthday()
    // Make the Human say hello.
    SayHello()
    SetName(name null.String)
}

which does not contains package github.com/volatiletech/null/v8.

Peter-Maguire commented 3 years ago

I had this problem, the workaround is to use

import null "github.com/volatiletech/null/v8"

Then it will detect the import correctly

wych42 commented 3 years ago
import null "github.com/volatiletech/null/v8"

CI would complain: "Redundant alias" and won't pass.

wych42 commented 3 years ago

This issue already fix in older commit.

I did run go get -u to upgrade local binary package, but seems the binary files wasn't upgraded at all.