-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdi_errors.go
39 lines (33 loc) · 930 Bytes
/
di_errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package di_injector
import (
"errors"
"fmt"
"log"
"os"
)
var (
ErrAddDependency = "cannot add the dependency %v because %v"
ErrInjectInner = "coudnt inject inner dependency -- %v"
ErrFoundImplementation = "None implementation was found for dependency: %v"
ErrAtInjection = "fatal error at injection"
ErrInjectInterface = "cannot inject into interface{}"
)
func DiError(errFormat string, values ...interface{}) error {
var message string
if values == nil {
message =errFormat
}else {
message = fmt.Sprintf(errFormat,values)
}
errLog.Print(message)
return errors.New(message)
}
func DiFatal(errFormat string, values ...interface{}) {
errLog.Fatal(fmt.Sprintf(errFormat,values))
}
var errLog = Logger(log.New(os.Stderr, "[di-injector] ", log.Ldate|log.Ltime|log.Lshortfile))
// Logger is used to log critical error messages.
type Logger interface {
Print(v ...interface{})
Fatal(v ...interface{})
}