commonsvalidation

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

README

Commons Validation

Go Reference

This module is part of FINACORE software and has as objective to facilitate and standardise the validation process throughout the software execution time line.

As all other products and modules of FINACORE project, this package has a strong code documentations that generates the fullfil tutorial disponible at go.dev reference page, that is enough for their usage.

Read the full documentation at: https://pkg.go.dev/github.com/finacore/commons-validation

Software Quality

Quality Gate Status Maintainability Rating Security Rating Coverage Vulnerabilities

This lib use Sonarcloud combined with Horusec to understand the code quality and security, blocking the pull request in any vulnerability incidence.

As well as security, performance is a fundamental factor of all FINACORE software, package or modules. This way this package use the benchmark regression to ensure that no performance gaps ocours.

The result of benchmark regression is disponible at: Performance Regeression

License

Copyright 2022 finacore.net

Licensed 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.

Documentation

Overview

commonserrors package was created with intent to standardizing a way to execute the data structure validation processo that returns the validation erros every in the same way and in the same language.

by convention, the english language was choosen as a default and unique language. Case your code want to use a diferente language the better for you is do not use this library and and choose to use the standard form of the go-playground/validator library

The first step to use this package is to get it through the command below, then you will be able to import it in your code.

go get github.com/finacore/commons-validation

To avoid the conflicts between packages during the imnport phase, is strongly recommended select other name for this package in the moment of import like shown below:

import (
	commonsvalidation "github.com/finacore/commons-validation"
)

Once imported you can use the package as you prefer. So read the function and methods documentation to know how to use this packagage.

commonserrors package was created with intent to standardizing a way to execute the data structure validation processo that returns the validation erros every in the same way and in the same language.

by convention, the english language was choosen as a default and unique language. Case your code want to use a diferente language the better for you is do not use this library and and choose to use the standard form of the go-playground/validator library

The first step to use this package is to get it through the command below, then you will be able to import it in your code.

go get github.com/finacore/commons-validation

To avoid the conflicts between packages during the imnport phase, is strongly recommended select other name for this package in the moment of import like shown below:

import (
	commonsvalidation "github.com/finacore/commons-validation"
)

Once imported you can use the package as you prefer. So read the function and methods documentation to know how to use this packagage.

commonserrors package was created with intent to standardizing a way to execute the data structure validation processo that returns the validation erros every in the same way and in the same language.

by convention, the english language was choosen as a default and unique language. Case your code want to use a diferente language the better for you is do not use this library and and choose to use the standard form of the go-playground/validator library

The first step to use this package is to get it through the command below, then you will be able to import it in your code.

go get github.com/finacore/commons-validation

To avoid the conflicts between packages during the imnport phase, is strongly recommended select other name for this package in the moment of import like shown below:

import (
	commonsvalidation "github.com/finacore/commons-validation"
)

Once imported you can use the package as you prefer. So read the function and methods documentation to know how to use this packagage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CustomValidator added in v1.1.0

type CustomValidator struct {
	// contains filtered or unexported fields
}

CustomValidator data structure that store the validator.Validate and ut.Translator objects, as well the list o of commonserrors.validationErros populated after execution of Model method.

This data structure is not public to avoid the programers create it directly, this way to create a instance of this struct is necessary call the New function.

func New

func New() *CustomValidator

New has the responsibility to create and instantiate the data structure that able to create a pre convfigured validator that translate the errors to human english language.

Usage:

cv := commonsvalidation.New()

func (*CustomValidator) Model added in v1.1.0

func (cv *CustomValidator) Model(model interface{}) ValidatorResult

Model validator execute the validation of model passed by parameter. Once this method is called, the result is stored internaly in the data structure

Usage:

cv := commonsvalidation.New()
vr := cv.Model(yourModel)

type ValidatorResult added in v1.2.0

type ValidatorResult []commonsErrors.ValidationError

ValidatorResult is da data structure that has a responsibility to store the response of the validation process. This data structure implements some methods to help get access to the data

func (ValidatorResult) Count added in v1.2.0

func (vr ValidatorResult) Count() int

Count returns how many validation errors was produced by the validation process execution

Usage:

cv := commonsvalidation.New()
vr := cv.Model(yourModel)
numErrors := vr.Count()

func (ValidatorResult) Errors added in v1.2.0

Errors return the commonserrors.ValidationError array containing all errors returned by the execution of validation process

Usage:

cv := commonsvalidation.New()
vr := cv.Model(yourModel)
errs := vr.Errors()

func (ValidatorResult) HasError added in v1.2.0

func (vr ValidatorResult) HasError() bool

HasError provivide a simple way to check if the validatorResponse produce or not errors

Usage:

cv := commonsvalidation.New()
vr := cv.Model(yourModel)
hasError := vr.HasError()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL