params

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PathOrReaderType = "$pathOrReader"
	PathOrWriterType = "$pathOrWriter"
)

Variables

This section is empty.

Functions

func BytesFrom

func BytesFrom(s string) ([]byte, error)

Types

type Bytes

type Bytes []byte

Bytes is a string meant to hold a slice of bytes. - as a string: `{ "bucket": "name", "object": "/path/to/file" }` - as a reference to a file: "@dir/file" - from piped input: "-"

type FilePath

type FilePath string

FilePath represents a file path and provides with helper to open / create either regular files or pipe stdin / stdout whenever the path is '-'.

func (FilePath) Create

func (f FilePath) Create() (Writer, error)

func (FilePath) IsPipe

func (f FilePath) IsPipe() bool

func (FilePath) Open

func (f FilePath) Open() (Reader, error)

func (FilePath) OpenPipe

func (f FilePath) OpenPipe() (Reader, error)

func (*FilePath) Set

func (f *FilePath) Set(val string) error

func (*FilePath) String

func (f *FilePath) String() string

func (*FilePath) Type

func (f *FilePath) Type() string

type Json

type Json string

Json is a string meant to hold a json value. - as a string: `{ "bucket": "name", "object": "/path/to/file" }` - as a reference to a file: "@dir/file" - from piped input: "-"

func (Json) Interface added in v1.0.2

func (j Json) Interface() (interface{}, error)

Interface unmarshals this JSON string into an empty interface{}. If the string value starts with '@', it looks for a file with that name and uses the content of the file.

func (Json) Map

func (j Json) Map() (map[string]interface{}, error)

Map returns the content of the Json string as a map[string]interface If the string value starts with '@', it looks for a file with that name and uses the content of the file.

func (Json) Unmarshal

func (j Json) Unmarshal(v interface{}) error

type PathOrReader

type PathOrReader struct {
	Path string
	Read Reader
}

PathOrReader implements flag.Value such as it can be used as an attribute in another struct and used with bflags bindings.

This allows the same struct to be used for command line parameter as well as in programmatic use.

**notes**

  • the path attributes _must_ be initialized otherwise bindings will error In the example below: `tr := &TestReader{Path: &PathOrReader{}}`
  • the attribute MUST be a pointer not a value (*PathOrReader not PathOrReader)

Example

type TestReader struct {
	Name string        `cmd:"flag"`
	Path *PathOrReader `cmd:"flag"`
}

func (*PathOrReader) CanRead

func (p *PathOrReader) CanRead() bool

func (*PathOrReader) Open

func (p *PathOrReader) Open() (Reader, error)

func (*PathOrReader) Set

func (p *PathOrReader) Set(path string) error

func (*PathOrReader) String

func (p *PathOrReader) String() string

func (*PathOrReader) Type

func (p *PathOrReader) Type() string

type PathOrWriter

type PathOrWriter struct {
	Path  string
	Write Writer
}

PathOrWriter implements flag.Value such as it can be used as an attribute in another struct and used with bflags bindings.

This allows the same struct to be used for command line parameter as well as in programmatic use.

**notes** - a PathOrWriter attribute _must_ be initialized for bindings to work. - the attribute MUST be a pointer not a value (*PathOrWriter not PathOrWriter)

see PathOrReader for an example.

func (*PathOrWriter) CanWrite

func (p *PathOrWriter) CanWrite() bool

func (*PathOrWriter) Create

func (p *PathOrWriter) Create() (Writer, error)

func (*PathOrWriter) Set

func (p *PathOrWriter) Set(path string) error

func (*PathOrWriter) String

func (p *PathOrWriter) String() string

func (*PathOrWriter) Type

func (p *PathOrWriter) Type() string

type Reader

type Reader interface {
	io.Reader
	io.Closer
}

func NopCloser

func NopCloser(f io.Reader) Reader

type Writer

type Writer interface {
	io.Writer
	io.Closer
}

func NopWriteCloser

func NopWriteCloser(w io.Writer) Writer

Jump to

Keyboard shortcuts

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