di/annotation/inject.go

34 lines
484 B
Go
Raw Normal View History

2017-12-03 13:54:09 +00:00
package annotation
2017-12-05 13:28:42 +00:00
// @Inject(name? string)
import (
2017-12-06 06:07:44 +00:00
"fmt"
"reflect"
2017-12-05 13:28:42 +00:00
)
const (
InjectTag = "@Inject"
)
2017-12-06 06:07:44 +00:00
func init() {
registerAnnotation(InjectTag, reflect.TypeOf((*Inject)(nil)))
}
2017-12-03 13:54:09 +00:00
type Inject struct {
2017-12-05 13:28:42 +00:00
Annotation
2017-12-05 10:02:41 +00:00
Name string
2017-12-03 13:54:09 +00:00
}
2017-12-05 13:28:42 +00:00
2017-12-06 06:07:44 +00:00
func (a *Inject) parseAttribute(attributes map[string]string) error {
for k, v := range attributes {
2017-12-05 13:28:42 +00:00
switch k {
case "name":
2017-12-06 06:07:44 +00:00
a.Name = v
default:
return fmt.Errorf("Syntax error: not supported attribute[%s]", k)
2017-12-05 13:28:42 +00:00
}
}
2017-12-06 06:07:44 +00:00
return nil
2017-12-05 13:28:42 +00:00
}