server/pkg/loafer/app/app.go
2019-11-12 00:13:14 +09:00

40 lines
1023 B
Go

package app
import (
"log"
"reflect"
cdr "git.loafle.net/commons/di-go/registry"
appAnnotation "git.loafle.net/totopia/server/pkg/loafer/app/annotation"
webAnnotation "git.loafle.net/totopia/server/pkg/loafer/web/annotation"
)
func Run(t reflect.Type) {
taServer := cdr.GetTypeAnnotation(t, appAnnotation.ServerAnnotationType)
if nil == taServer {
log.Printf("[%s] is not Server, use @app:Server", t.Elem().Name())
return
}
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)
}
}