Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

miko.gs/struct-validator

Package Overview
Dependencies
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

miko.gs/struct-validator

Go Modules
Version
v0.9.0
Version published
Created
Source

struct-validator

Verify the values of struct fields using tags

Example code

Use the package with the following URL:

import "miko.gs/struct-validator"

And see the below code snippet:

type Test1 struct {
	FirstName     string `validation:"req len:5,25"`
	LastName      string `validation:"req len:2,50"`
	Age           int    `validation:"req val:18,150"`
	Price         int    `validation:"req val:0,9999"`
	PostCode      string `validation:"req" validation_regexp:"^[0-9][0-9]-[0-9][0-9][0-9]$"`
	Email         string `validation:"req email"`
	BelowZero     int    `validation:"val:-6,-2"`
	DiscountPrice int    `validation:"val:0,8000"`
	Country       string `validation_regexp:"^[A-Z][A-Z]$"`
	County        string `validation:"len:,40"`
}

s := &Test1{
	FirstName: "Name that is way too long and certainly not valid",
	...
}

o := validator.&ValidationOptions{
	RestrictFields: map[string]bool{
		"FirstName": true,
		"LastName":  true,
		...
	},
	...
}

isValid, fieldViolations, err := validator.Validate(s, &o)

FAQs

Package last updated on 12 Feb 2026

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