接口缺少方法的实现

时间:2019-07-16 05:59:14

标签: go interface

参加有关在Go中组织数据库访问的教程:https://www.alexedwards.net/blog/organising-database-access

我正在遵循“使用接口”方法,但是遇到一个错误,基本上是说我在拥有接口的同时还没有为接口实现任何方法。

在users.go中:

package fs

import (
...
)

func (client *Client) Example_Write() error {
    ...
    return nil
}

func (client *Client) Example_Query() error {
    ...
    return nil
}

在db.go中:

type Datastore interface {
    Example_Write() error
    Example_Query() error
}

type Client struct {
    *firestore.Client
}

func SetupClient() (*Client, error){
    return &Client{client}, nil
}
...

在app.go中:

import ( "fs" )
type Env struct {
    client fs.Datastore
}

client, _ := fs.SetupClient()
env := &Env{client: client}

错误看起来像这样: 188:14:无法在字段值中将客户端(* fs.Client类型)用作fs.Datastore类型:     * fs.Client未实现fs.Datastore(缺少Example_Query方法)

任何想法都将不胜感激:) Go的新手,请耐心等待!

0 个答案:

没有答案
相关问题