This question already has an answer here:
My go test
can not be passed. What's wrong? What's the meaning of (Handle method has pointer receiver)
package ipc
import (
"testing"
)
// import (
// "encoding/json"
// "fmt"
// )
type Request struct {
Method string `json/"method"`
Params string `json/"params"`
}
type Response struct {
Code string `json/"code"`
Body string `json/"body"`
}
type Server interface {
Name() string
Handle(method, params string) *Response
}
type IpcServer struct {
Server
}
func NewIpcServer(server Server) *IpcServer {
return &IpcServer{server}
}
type EchoServer struct {
}
func (server *EchoServer) Name() string {
return "EchoServer"
}
func (server *EchoServer) Handle(method, params string) *Response {
return &Response{"OK", "Echo " + method + " " + params}
}
func TestIpc(t *testing.T) {
server := EchoServer{}
ipcServer := NewIpcServer(server)
}
When I run go test ipc_test.go
/ipc_test.go:49: cannot use server (type EchoServer) as type Server in argument to NewIpcServer:
EchoServer does not implement Server (Handle method has pointer receiver)
FAIL command-line-arguments [build failed]
</div>