Unnest common schema initialization
This makes the common code path less deeply nested and the flow control easier to follow.
This commit is contained in:
parent
30461cc297
commit
444c38806d
@ -223,7 +223,12 @@ func Parse(dest interface{}, cacheStore *sync.Map, namer Namer) (*Schema, error)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if s, loaded := cacheStore.LoadOrStore(modelType, schema); !loaded {
|
if v, loaded := cacheStore.LoadOrStore(modelType, schema); loaded {
|
||||||
|
s := v.(*Schema)
|
||||||
|
<-s.initialized
|
||||||
|
return s, s.err
|
||||||
|
}
|
||||||
|
|
||||||
defer close(schema.initialized)
|
defer close(schema.initialized)
|
||||||
if _, embedded := schema.cacheStore.Load(embeddedCacheKey); !embedded {
|
if _, embedded := schema.cacheStore.Load(embeddedCacheKey); !embedded {
|
||||||
for _, field := range schema.Fields {
|
for _, field := range schema.Fields {
|
||||||
@ -251,10 +256,6 @@ func Parse(dest interface{}, cacheStore *sync.Map, namer Namer) (*Schema, error)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
schema = s.(*Schema)
|
|
||||||
<-schema.initialized
|
|
||||||
}
|
|
||||||
|
|
||||||
return schema, schema.err
|
return schema, schema.err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user