adapters

package
v1.6.4 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2023 License: ISC Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArgumentParser added in v1.1.0

type ArgumentParser interface {
	OptionString(name string, value string) *string
	PositionalArguments() []string
	ParseArguments(args []string) error
	Parse() error
}

ArgumentParser parses command line flags.

type DB

type DB interface {
	Ping() error
	Query(query string, args ...interface{}) (DBRows, error)
	Exec(query string, args ...interface{}) (sql.Result, error)
}

DB is an adapter interface for database/sql.DB.

type DBAdapter added in v1.4.1

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

func NewDBAdapter

func NewDBAdapter(db *sql.DB) DBAdapter

NewDBAdapter returns an implementation of DB.

func (DBAdapter) Exec added in v1.4.1

func (adapter DBAdapter) Exec(query string, args ...interface{}) (sql.Result, error)

Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.

func (DBAdapter) Ping added in v1.4.1

func (adapter DBAdapter) Ping() error

Ping verifies a connection to the database is still alive, establishing a connection if necessary.

func (DBAdapter) Query added in v1.4.1

func (adapter DBAdapter) Query(query string, args ...interface{}) (DBRows, error)

Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.

type DBRows

type DBRows interface {
	Next() bool
	Scan(dest ...interface{}) error
	Close() error
}

DBRows is the result of a query. Its cursor starts before the first row of the result set. Use Next to advance from row to row.

type File

type File interface {
	os.FileInfo
}

File is used to mock os.FileInfo

type FileSystem

type FileSystem interface {
	ReadDir(dirname string) ([]os.FileInfo, error)
	ReadFile(filename string) ([]byte, error)
	WriteFile(filename string, data []byte, perm fs.FileMode) error
}

FileSystem is an interface to read contents from the file system.

type FlagArgumentParser added in v1.4.1

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

FlagArgumentParser is an implementation of ArgumentParser using the package flag.

func NewArgumentParser added in v1.1.0

func NewArgumentParser() FlagArgumentParser

func (FlagArgumentParser) OptionString added in v1.4.1

func (adapter FlagArgumentParser) OptionString(name string, value string) *string

OptionString defines a string flag with specified name, default value, and usage string. The return value is the address of a string variable that stores the value of the flag.

func (FlagArgumentParser) Parse deprecated added in v1.4.1

func (adapter FlagArgumentParser) Parse() error

Deprecated: use ParseArguments instead. Parse is deprecated.

func (FlagArgumentParser) ParseArguments added in v1.4.1

func (adapter FlagArgumentParser) ParseArguments(args []string) error

ParseArguments parses the command-line flags from os.Args[1:]. Must be called after all flags are defined and before flags are accessed by the program.

func (FlagArgumentParser) PositionalArguments added in v1.4.1

func (adapter FlagArgumentParser) PositionalArguments() []string

PositionalArguments returns the non-flag command-line arguments.

type IOUtilAdapter

type IOUtilAdapter struct{}

IOUtilAdapter is an implementation of FileSystem using io/ioutil and os.

func (IOUtilAdapter) ReadDir

func (adapter IOUtilAdapter) ReadDir(dirname string) ([]os.FileInfo, error)

ReadDir list the files on a given directory.

func (IOUtilAdapter) ReadFile

func (adapter IOUtilAdapter) ReadFile(filename string) ([]byte, error)

ReadFile reads the contents of a file.

func (IOUtilAdapter) WriteFile added in v1.5.0

func (adapter IOUtilAdapter) WriteFile(filename string, data []byte, perm fs.FileMode) error

type NilPrinterAdapter added in v1.4.0

type NilPrinterAdapter struct{}

func (NilPrinterAdapter) Print added in v1.4.0

func (adapter NilPrinterAdapter) Print(writer io.Writer, format string, a ...interface{}) error

Print outputs a string given a format.

type Printer

type Printer interface {
	Print(writer io.Writer, format string, a ...interface{}) error
}

Printer formats and prints messages to the given writer.

type PrinterAdapter

type PrinterAdapter struct{}

PrinterAdapter is an implementation of Printer.

func (PrinterAdapter) Print

func (adapter PrinterAdapter) Print(writer io.Writer, format string, a ...interface{}) error

Print outputs a string given a format.

type SQLResult

type SQLResult interface {
	sql.Result
}

SQLResult is used to mock sql.Result

Jump to

Keyboard shortcuts

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