Skip to content

Commit 1a97134

Browse files
committed
added generic router
1 parent 672e82b commit 1a97134

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ func (s *Service) NewComponentSession(aComponent *repository.Component, opts ...
179179
}
180180
aSession := session.New(aComponent.View, session.WithLocatorOptions(options...),
181181
session.WithAuth(s.repository.Auth()),
182+
session.WithComponent(aComponent),
182183
session.WithStateResource(sessionOpt.resource), session.WithOperate(s.operator.Operate))
183184
return aSession
184185
}

service/session/stater.go

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"reflect"
88
"runtime/debug"
99

10+
"embed"
11+
1012
"github.com/viant/datly/utils/types"
1113
"github.com/viant/datly/view/state"
1214
"github.com/viant/datly/view/state/kind/locator"
@@ -55,12 +57,33 @@ func (s *Session) Bind(ctx context.Context, dest interface{}, opts ...hstate.Opt
5557
destType := reflect.TypeOf(dest)
5658
sType := types.EnsureStruct(destType)
5759
stateType, ok := s.Types.Lookup(sType)
58-
if !ok {
59-
if stateType, err = state.NewType(
60-
state.WithSchema(state.NewSchema(destType)),
61-
state.WithResource(s.resource),
62-
); err != nil {
63-
return err
60+
61+
var embedFs *embed.FS
62+
if embedder, ok := dest.(state.Embedder); ok {
63+
embedFs = embedder.EmbedFS()
64+
}
65+
66+
if !ok && s.component != nil {
67+
68+
if s.component.Input.Type.Type() != nil {
69+
if destType == s.component.Input.Type.Type().Type() {
70+
stateType = &s.component.Input.Type
71+
}
72+
}
73+
if s.component.Output.Type.Type() != nil {
74+
if destType == s.component.Output.Type.Type().Type() {
75+
stateType = &s.component.Output.Type
76+
}
77+
}
78+
79+
if stateType == nil {
80+
if stateType, err = state.NewType(
81+
state.WithSchema(state.NewSchema(destType)),
82+
state.WithResource(s.resource),
83+
state.WithFS(embedFs),
84+
); err != nil {
85+
return err
86+
}
6487
}
6588
s.Types.Put(stateType)
6689
}

0 commit comments

Comments
 (0)