valfile

command module
v0.0.0-...-91aacda Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2023 License: MIT Imports: 21 Imported by: 0

README

valfile

A CLI tool to statically validate YAML, TOML, JSON, Jsonnet, HCL, dotenv files and environment variables against a Go struct type.

Usage

The following command will return errors, if file input-file.toml can't be unmarshaled into type YourStructType defined in package path/to/yourpackage or doesn't match it's validate field tags of github.com/go-playground/validator:

valfile -p path/to/yourpackage -t YourStructType -f input-file.toml

If input-file.toml passes the marshaling and validation then the above command is a no-op.

Struct tag check

By default, valfile will return errors if any of the fields of the selected type don't have a tag corresponding to the input type, for example:

struct S struct {
    Foo string `json:"foo"`
    Bar string
}

The above type in combination with a JSON input file will produce:

Config.Bar: missing tag "json"

option -no-tag-check disables this check.

Environment variables

To match environment variables against a Go type, use the -env flag. Beware that this flag is mutually exclusive with -f.

FOO=bar BAZZ=fuzz valfile -p path/to/yourpackage -t YourStructType -env

Requirements

valfile requires the Go compiler toolchain to be installed on the system.

How it works

valfile parses the given package, finds the type definition, renders a format-specific program template to a temporary directory, runs it using the Go toolchain go run . and forwards error messages if any.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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