šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

github.com/forkyid/go-utils/validation

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/forkyid/go-utils/validation

v0.0.0-20201202070637-5708e0743088
Source
Go
Version published
Created
Source

Makes use of four field tags: validate, id, process, json

json is used to get the field name when processing error details. If this tag is empty, or "-", the name defaults to the lowercased struct field name. Returns 400 on error.

validate tags is passed to go-validator. Errors from go-validator is parsed into validation.ErrorDetails.

"id" tags has three possible values: "required", "valid", "allow-zero", and "dive". "required" validates that the field is not empty, and is valid, sets the status code to 400 when empty and 422 when invalid. "valid" behaves similarly to "required" but returns 200 when empty. "allow-zero" allows zero value in id. When used on a slice, the tags will be applied to each element. Using the "dive" tag instructs the validator to recursively dive into slices, maps, and structs. The validator then checks for other tags within the slice/map/struct.

"process" behaves in the same way as validate but returns 422 on error.

validation.ErrorDetails is a map[string]string with an additional method Add(key, value string). Appends detail with "|" as separator. This type can be directly passed to rest.ResponseError as details.

FAQs

Package last updated on 02 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts