server/pkg/loafer/app/app.go

40 lines
1023 B
Go
Raw Normal View History

2019-11-11 15:00:04 +00:00
package app
import (
"log"
"reflect"
cdr "git.loafle.net/commons/di-go/registry"
2019-11-11 15:13:14 +00:00
appAnnotation "git.loafle.net/totopia/server/pkg/loafer/app/annotation"
webAnnotation "git.loafle.net/totopia/server/pkg/loafer/web/annotation"
2019-11-11 15:00:04 +00:00
)
func Run(t reflect.Type) {
2019-11-11 15:13:14 +00:00
taServer := cdr.GetTypeAnnotation(t, appAnnotation.ServerAnnotationType)
if nil == taServer {
2019-11-11 15:00:04 +00:00
log.Printf("[%s] is not Server, use @app:Server", t.Elem().Name())
return
}
2019-11-11 15:13:14 +00:00
aServer := taServer.(*appAnnotation.ServerAnnotation)
log.Printf("%s %d", t.Elem().Name(), aServer.HTTPPort)
restHandlers, err := cdr.GetInstancesByAnnotationType(webAnnotation.RestHandlerAnnotationType)
if nil != err {
log.Printf("[%v]", err)
return
}
for _, restHandler := range restHandlers {
t := reflect.TypeOf(restHandler)
ta := cdr.GetTypeAnnotation(t, webAnnotation.RestHandlerAnnotationType)
if nil == ta {
log.Printf("Service[%s] is not RESTService, use @RESTService", t.Elem().Name())
continue
}
log.Printf("%s %v", t.Elem().Name(), ta)
}
2019-11-11 15:00:04 +00:00
}