在golang中,您如何访问采用指针接收器并且也位于其他程序包中的方法?

package tests

import (
    "testing"
    "strconv"
    "dir/model"
)

type TestStruct struct {
    ID int
    a  string
    b  string
    c  string
    d  string
    ac bool
    ad bool
}

func TestUpdate(t *testing.T) {

        t.Log("Updating")
        cur := TestStruct{i,a,b,c,d,true,true}
        err := cur.model.Update(a,b,c,d,true,true)
}

In the code block above, I am trying to call a method that takes a receiver pointer and that is located in package "model".

The compiler error for this is:

reference to undefined field or method ‘model’ err := cur.model.Update(a,b,c,d,e,true,true)

In the code block below,the method "Udpate" in package "model" takes a receiver point to a struct and other input parameters.

package model

type Struct struct {
    ID int
    a  string
    b  string
    c  string
    d  string
    ac bool
    ad bool
}

func (update *Struct) Update(a, b, c, d,
e string, f, g bool) error {

    /* code */

}

I know for functions in other packages I can call them in my current package by saying:

packageName.method(parameters) 

How could I call method "Update" from package "model" in package "tests" while inputting a receiver pointer when I call it?

func (update *Struct) Update(a, b, c, d, e string, f, g bool)

is a method that is defined on type model.Struct. You cannot call it on a different type, such as TestStruct defined in your tests package.

What you probably want to do is:

    cur := model.Struct{i,a,b,c,d,true,true}
    err := cur.Update(a,b,c,d,true,true)

For example,

package tests

import (
    "dir/model"
    "testing"
)

func TestUpdate(t *testing.T) {
    t.Log("Updating")
    cur := model.Struct{i, a, b, c, d, true, true}
    err := cur.Update(a, b, c, d, true, true)
}