Skip to content

Commit

Permalink
Remove all prints
Browse files Browse the repository at this point in the history
  • Loading branch information
etabak committed Apr 27, 2020
1 parent 771a325 commit 51df4df
Showing 1 changed file with 1 addition and 29 deletions.
30 changes: 1 addition & 29 deletions injector.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,8 @@ package injector

import (
"fmt"
"os"
"reflect"
"strings"
"time"

"github.com/sirupsen/logrus"
)

const (
// Default log format will output [INFO]: 2006-01-02T15:04:05Z07:00 - Log message
defaultLogFormat = "[%lvl%]: %time% - %msg%"
defaultTimestampFormat = time.RFC3339
)

type Injector interface {
Expand All @@ -32,19 +22,6 @@ func NewEngine() *Engine {
}
}

var log *logrus.Logger

func init() {
setupLogger()
}

func setupLogger() {
logrus.SetFormatter(&logrus.TextFormatter{})
logrus.SetOutput(os.Stdout)
logrus.SetLevel(logrus.InfoLevel)
log = logrus.StandardLogger()
}

func (inj *Engine) Register(beans ...interface{}) error {
for _, bean := range beans {
inj.beans = append(inj.beans, bean)
Expand All @@ -54,7 +31,6 @@ func (inj *Engine) Register(beans ...interface{}) error {
}
structType := val.Type()
typeFullName := inj.getTypeFullName(structType)
log.Debugf("type full name: %s\n", typeFullName)
inj.typeToBean[typeFullName] = bean
}
return nil
Expand Down Expand Up @@ -82,25 +58,21 @@ func (inj *Engine) injectBean(bean interface{}) error {
for _, field := range fields {
fieldName := field.Name
fieldType := field.Type
log.Debugf("Name: %s, Type: %s\n", fieldName, fieldType)
if fieldType == structType {
log.Infof("not supporting self injection")
// not supporting self injection
continue
}
childName := inj.getContainingTypeFullName(field)
log.Debugf("chile name: %s\n", childName)
child := inj.typeToBean[childName]
if child == nil {
if childName, ok := field.Tag.Lookup("inject"); ok {
log.Debugf("chile name: %s\n", childName)
child = inj.typeToBean[childName]
}
}
if child != nil {
f := val.FieldByName(fieldName)
if f.CanAddr() && f.IsValid() {
f.Set(reflect.ValueOf(child))
log.Debugf("Injected %s", child)
}
}
}
Expand Down

0 comments on commit 51df4df

Please sign in to comment.