klesh commented on code in PR #6146: URL: https://github.com/apache/incubator-devlake/pull/6146#discussion_r1338292974
########## backend/helpers/srvhelper/model_service_helper.go: ########## @@ -0,0 +1,215 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package srvhelper + +import ( + "fmt" + "time" + + "github.com/apache/incubator-devlake/core/context" + "github.com/apache/incubator-devlake/core/dal" + "github.com/apache/incubator-devlake/core/errors" + "github.com/apache/incubator-devlake/core/log" + "github.com/apache/incubator-devlake/core/models" + "github.com/apache/incubator-devlake/helpers/dbhelper" + "github.com/go-playground/validator/v10" +) + +type CustomValidator interface { + CustomValidate(entitiy interface{}, validate *validator.Validate) errors.Error Review Comment: 2. No, it is not. For example, the `CustomValidate` may be implemented in a **nested struct** of the `model` and sometimes we need to check the whole `model` instead of the **nested struct** only. https://github.com/apache/incubator-devlake/blob/90cb26bd62d226f5c4ed54c17689dab9bcf30de0/backend/helpers/pluginhelper/api/connection_auths.go#L147 3. Passing the `*validate` can be beneficial in terms of performance because the cached metadata in Validator can be reused. 4. the function is meant for plugins to take over the Validation when needed, if plugins implement this interface, the helper would skip its own implementation and let the plugin do what it wants. I think `CustomValidate` is more specify and reflects its purpose better. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
