MCPcopy
hub / github.com/go-gorm/gorm / getOrParse

Function getOrParse

schema/schema.go:393–414  ·  view source on GitHub ↗
(dest interface{}, cacheStore *sync.Map, namer Namer)

Source from the content-addressed store, hash-verified

391}
392
393func getOrParse(dest interface{}, cacheStore *sync.Map, namer Namer) (*Schema, error) {
394 modelType := reflect.ValueOf(dest).Type()
395
396 if modelType.Kind() != reflect.Struct {
397 for modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array || modelType.Kind() == reflect.Ptr {
398 modelType = modelType.Elem()
399 }
400
401 if modelType.Kind() != reflect.Struct {
402 if modelType.PkgPath() == "" {
403 return nil, fmt.Errorf("%w: %+v", ErrUnsupportedDataType, dest)
404 }
405 return nil, fmt.Errorf("%w: %s.%s", ErrUnsupportedDataType, modelType.PkgPath(), modelType.Name())
406 }
407 }
408
409 if v, ok := cacheStore.Load(modelType); ok {
410 return v.(*Schema), nil
411 }
412
413 return Parse(dest, cacheStore, namer)
414}

Callers 2

parseRelationMethod · 0.85
ParseFieldMethod · 0.85

Calls 3

ParseFunction · 0.85
TypeMethod · 0.65
NameMethod · 0.65

Tested by

no test coverage detected