Skip to content

Commit

Permalink
Merge branch 'meshery:master' into CountEntities
Browse files Browse the repository at this point in the history
  • Loading branch information
Jougan-0 authored Mar 14, 2024
2 parents 5a78b49 + 75d94b9 commit 2474a98
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ newIssueWelcomeComment: >
newPRWelcomeComment: >
Yay, your first pull request! :thumbsup: A contributor will be by to give feedback soon. In the meantime, please review the [Layer5 Community Welcome Guide](https://docs.google.com/document/d/17OPtDE_rdnPQxmk2Kauhm3GwXF1R5dZ3Cj8qZLKdo5E/edit?usp=sharing) and sure to join the [community Slack](http://slack.layer5.io/).
Be sure to double-check that you have signed your commits. Here are instructions for [making signing an implicit activity while peforming a commit](../CONTRIBUTING.md#signing-off-on-commits-developer-certificate-of-origin).
Be sure to double-check that you have signed your commits. Here are instructions for [making signing an implicit activity while peforming a commit](https://github.com/meshery/meshkit/blob/master/CONTRIBUTING.md#general-contribution-flow).
#-------------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions models/meshmodel/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ func (rm *RegistryManager) GetModels(db *database.Handler, f types.Filter) ([]v1
} else {
finder = finder.Order(mf.OrderOn)
}
} else {
finder = finder.Order("display_name")
}

finder.Count(&count)
Expand Down
4 changes: 2 additions & 2 deletions utils/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ func ErrGettingLatestReleaseTag(err error) error {
)
}

func ErrTypeCast(valType string) error {
return errors.New(ErrTypeCastCode, errors.Alert, []string{"invaid type assertion requested"}, []string{fmt.Sprintf("The underlying type of the interface is %s", valType)}, []string{"The interface type is not compatible with the request type cast"}, []string{"use correct data type for type casting"})
func ErrTypeCast(err error) error {
return errors.New(ErrTypeCastCode, errors.Alert, []string{"invaid type assertion requested"}, []string{err.Error()}, []string{"The interface type is not compatible with the request type cast"}, []string{"use correct data type for type casting"})
}

// ErrDecodeYaml is the error when the yaml unmarshal fails
Expand Down
21 changes: 19 additions & 2 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,14 @@ func Contains[G []K, K comparable](slice G, ele K) bool {
}

func Cast[K any](val interface{}) (K, error) {
assertedValue, ok := val.(K)
var assertedValue K
if IsInterfaceNil(val) {
return assertedValue, ErrTypeCast(fmt.Errorf("nil interface cannot be type casted"))
}
var ok bool
assertedValue, ok = val.(K)
if !ok {
return assertedValue, ErrTypeCast(reflect.TypeOf(val).Name())
return assertedValue, ErrTypeCast(fmt.Errorf("the underlying type of the interface is %s", reflect.TypeOf(val).Name()))
}
return assertedValue, nil
}
Expand Down Expand Up @@ -380,3 +385,15 @@ func ExtractDomainFromURL(location string) string {
}
return regexp.MustCompile(`(([a-zA-Z0-9]+\.)([a-zA-Z0-9]+))$`).FindString(parsedURL.Hostname())
}

func IsInterfaceNil(val interface{}) bool {
if val == nil {
return true
}
switch reflect.TypeOf(val).Kind() {
case reflect.Ptr, reflect.Map, reflect.Array, reflect.Chan, reflect.Slice:
return reflect.ValueOf(val).IsNil()
}
return false

}

0 comments on commit 2474a98

Please sign in to comment.