V
V
veryoriginalnickname2021-10-06 20:25:03
go
veryoriginalnickname, 2021-10-06 20:25:03

How to change the name of a function in the interface?

In the package that creates a connection to the database, I made an interface for the logger. So that when creating a connection, you can skip your logger, and errors in the database would be written to it:

type Logger interface {
  Panic(err error)
}

The problem is that my logger does not have Panic, but PanicErr. Because of this, a logger cannot be pushed into the connection creation function. Is there any way to fix this without renaming the function in my logger?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Mamonov, 2021-10-06
@veryoriginalnickname

It is impossible, because your implementation will not match the interface.
Alternatively, you can create your Panic function, and call your PanicErr in it, then this implementation will correspond to the interface

type Logger interface {
  Panic(err error)
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question