govalid

command module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

README

govalid

govalid is a code generator that implements a Validate method on a given type. The method returns an error when it is called; if the current value is not one of those constants declared in a given file in code generation.

Example

Input (you provide):

type Planet string

const (
  Earth = Planet("earth")
  Mars  = Planet("mars")
)

Command:

govalid -in filename.go -type Planet

Output:

func (p Planet) Validate() error {
  switch p {
  case Earth:
    return nil
  case Mars:
    return nil
  }
  return fmt.Errorf("invalid value")
}

Install

go install github.com/ufukty/govalid@latest

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