incomingdata

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: MIT Imports: 3 Imported by: 0

README

The package provides a simple object to validate incoming data

See ./types.go to support types.

Example:

import(
  "api"
  
  inc "github.com/iostrovok/incomingdata.go"
)
  ...
  
func (g *grpcserver) GetByIds(in *api.Parameters) (*api.result, error) {
	err := inc.New().
		Add("list of ids", in.GetIds(), inc.ListInt32P).
		Add("time of request", in.GetTime(), inc.Int64P).
		First()
		
	if err != nil {
        return nil, err
	}
	
	...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Incoming

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

func New

func New() *Incoming

New creates a new instance of the Incoming struct. Just a simple constructor.

func (*Incoming) Add

func (i *Incoming) Add(key string, value any, typ Type) *Incoming

Add adds a new check case to the Incoming object. It takes in a key(string), value(any type), and typ(Type). It returns the Incoming struct itself.

func (*Incoming) All

func (i *Incoming) All() []Result

All returns the list of results in the Incoming struct.

func (*Incoming) First

func (i *Incoming) First() error

First returns the first error as all errors or nil if no error is found.

func (*Incoming) Print

func (i *Incoming) Print() *Incoming

Print is a debug function. It iterates over the list of results in the Incoming struct and prints each result's Key and Error. It returns the Incoming struct itself.

type Result

type Result struct {
	Key   string
	Error error
}

type Type

type Type int
const (
	None  Type = iota // unknown for a checking type
	Inter             // any / interface{}
	Any               // any / interface{}

	Int32  // simple integer 32
	Int32N // simple non-negative integer 32
	Int32P // simple positive integer 32

	ListInt32N // list of simple non-negative integer 32
	ListInt32P // list of simple positive integer 32

	Int64  // simple integer 64
	Int64N // simple non-negative integer 64
	Int64P // simple positive integer 64

	Float32  // simple float 32
	Float32N // simple non-negative float 32
	Float32P // simple positive float 32

	Float64  // simple float 64
	Float64N // simple non-negative float 64
	Float64P // simple positive float 64

	String  // simple string
	StringP // non-empty string

	// ListString - list has length > 0
	ListString // non-empty list of any values
	// ListStringP - list has at least one non-empty value
	ListStringP // non-empty list containing at least one non-empty value
	// ListStringS - all values in list are not empty
	ListStringS // non-empty list with all non-empty values
)

Jump to

Keyboard shortcuts

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