di/annotation/inject.go

34 lines
484 B
Go
Raw Normal View History

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