goutil

package module
v1.0.0-0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2017 License: Apache-2.0 Imports: 16 Imported by: 2

README

goutils

Documentation

Index

Constants

View Source
const (
	SyslogPriInfo = srslog.LOG_LOCAL7 | srslog.LOG_INFO
	SyslogPriErr  = srslog.LOG_LOCAL7 | srslog.LOG_ERR

	FileFlagsAppend = os.O_APPEND | os.O_CREATE | os.O_WRONLY
	FileModeDefault = 0640
	DirModeDefault  = 0750

	LoggerFlags = log.LstdFlags
)
View Source
const (
	NameIx  int = 0
	ValueIx int = 1
)

Variables

This section is empty.

Functions

func AllowedMethodHandler

func AllowedMethodHandler(h http.Handler, methods ...string) http.Handler

AllowedMethodHandler restricts http requests to methods provided.

func CompareObjects

func CompareObjects(t1, t2 interface{}, tid string) (ss [][]string, err error)

CompareObjects compares the field count, order, names, and values of two structs objects. If the field count or order is different, the structs are not comparable and the function returns an error. If the structs differ only in field values, the function returns a list of differences. Fields can be renamed using tags (tid) and omitted with a tag value of '-'.

func ErrorDecorator

func ErrorDecorator(err error) error

ErrorDecorator prepends function filename, line number, and function name to error messages.

func MkdirOpen

func MkdirOpen(fn string) (*os.File, error)

func ObjecToSlice

func ObjecToSlice(t interface{}, tid string) (ss [][]string, err error)

ObjecToSlice converts a single-tier struct into a slice of slices in the form {{name, value}, {name, value}, ...} for consumption by other methods. The outer slice maintains the fields in the same order as the struct. The tag parameter is the name of the struct tag to use for special processing. The primary purpose of this function is to offload tag processing for other functions.

func ObjectDbCols

func ObjectDbCols(t interface{}, tid string) (cols []string, err error)

ObjectDbCols is a convenience method that returns relevant and valid database column names for use in constructing SQL statements. Only columns representing fields that will not cause a panic are included. Columns are further filtered by the tag provided. To be included, the tag must exist and must not have a '-' value.

func ObjectDbSQL

func ObjectDbSQL(cmd, tbl string, cols []string) (sql string, err error)

ObjectDbSQL generates basic SQL statements from struct fields.

func ObjectDbVals

func ObjectDbVals(t interface{}, tid string) (vals []interface{}, err error)

ObjectDbVals is a convenience method that returns an entire database row for simpler insert statements. Only fields that will not cause a panic are included. Fields are further filtered by the tag provided. To be included, the tag must exist and must not have a '-' value. The table or view DDL must have the same columns with the same names in the same order or the query will fail. Can be combined with the method ObjectDbCols for a less brittle solution.

func ObjectDbValsByCol

func ObjectDbValsByCol(t interface{}, tid string, cols []string) (vals []interface{}, err error)

ObjectDbValsByCol is a convenience method that returns a database row based on the column names provided by the caller, which are ostensibly taken from the database table or view. The column names are matched to the tag on the struct field. An error is returned if a column is not found or if the associated field returns false for the IsValid(), CanAddr(), or CanInterface() reflect methods.

func ObjectToCSV

func ObjectToCSV(t interface{}) (b []byte, err error)

ObjectToCSV converts a single-tier struct to a string suitable for writing to a CSV file. For the csv package, we need to rearranage the elements from an ordered list of {{name, value}, {name, value}, ...} to an ordered list of {{name, name, ...}, {value, value, ...}}.

func ObjectToNVP

func ObjectToNVP(t interface{}) (b []byte, err error)

ObjectToNVP converts a single-tier struct to a string containing name- value pairs separated by newlines.

func RestoreObject

func RestoreObject(fn string, t interface{}) (err error)

RestoreObject restores an object from a JSON file.

func RowToMap

func RowToMap(vid, pid, sn string, rows *sql.Rows) (mss map[string]string, err error)

RowToMap converts a database row into a map of string values indexed by column name.

func SaveObject

func SaveObject(t interface{}, fn string) (err error)

SaveObject persists an object to a JSON file.

Types

type MultiLoggerWriter

type MultiLoggerWriter struct {
	Options struct {
		LogFiles struct {
			System bool
			Access bool
			Error  bool
		}

		Console struct {
			System bool
			Access bool
			Error  bool
		}

		Syslog struct {
			System bool
			Access bool
			Error  bool
		}

		UseFlags struct {
			System bool
			Access bool
			Error  bool
		}

		LoggerFlags struct {
			UTC       bool
			Date      bool
			Time      bool
			LongFile  bool
			ShortFile bool
			Standard  bool
		}

		RecoveryStack bool
	}

	Config struct {
		AppName string

		AppDir string
		LogDir string

		LogFiles struct {
			System string
			Access string
			Error  string
		}

		LoggerFlags struct {
			System int
			Access int
			Error  int
		}

		LogTags struct {
			System string
			Access string
			Error  string
		}

		Syslog struct {
			Prot string
			Host string
			Port string
			Tag  string
		}
	}
	// contains filtered or unexported fields
}

func NewMultiLoggerWriter

func NewMultiLoggerWriter(cf ...string) *MultiLoggerWriter

func (*MultiLoggerWriter) AccessLog

func (this *MultiLoggerWriter) AccessLog(s string) *MultiLoggerWriter

func (*MultiLoggerWriter) AccessTag

func (this *MultiLoggerWriter) AccessTag(s string) *MultiLoggerWriter

func (*MultiLoggerWriter) AccessUseFlags

func (this *MultiLoggerWriter) AccessUseFlags(b bool) *MultiLoggerWriter

func (*MultiLoggerWriter) AppDir

func (this *MultiLoggerWriter) AppDir(s string) *MultiLoggerWriter

func (*MultiLoggerWriter) AppName

func (this *MultiLoggerWriter) AppName(s string) *MultiLoggerWriter

func (*MultiLoggerWriter) Defaults

func (this *MultiLoggerWriter) Defaults() *MultiLoggerWriter

func (*MultiLoggerWriter) DefaultsInit

func (this *MultiLoggerWriter) DefaultsInit() *MultiLoggerWriter

func (*MultiLoggerWriter) EnableAccess

func (this *MultiLoggerWriter) EnableAccess(b bool) *MultiLoggerWriter

func (*MultiLoggerWriter) EnableConsole

func (this *MultiLoggerWriter) EnableConsole(b bool) *MultiLoggerWriter

func (*MultiLoggerWriter) EnableError

func (this *MultiLoggerWriter) EnableError(b bool) *MultiLoggerWriter

func (*MultiLoggerWriter) EnableLogFiles

func (this *MultiLoggerWriter) EnableLogFiles(b bool) *MultiLoggerWriter

func (*MultiLoggerWriter) EnableSyslog

func (this *MultiLoggerWriter) EnableSyslog(b bool) *MultiLoggerWriter

func (*MultiLoggerWriter) EnableSystem

func (this *MultiLoggerWriter) EnableSystem(b bool) *MultiLoggerWriter

func (*MultiLoggerWriter) ErrorLog

func (this *MultiLoggerWriter) ErrorLog(s string) *MultiLoggerWriter

func (*MultiLoggerWriter) ErrorTag

func (this *MultiLoggerWriter) ErrorTag(s string) *MultiLoggerWriter

func (*MultiLoggerWriter) ErrorUseFlags

func (this *MultiLoggerWriter) ErrorUseFlags(b bool) *MultiLoggerWriter

func (*MultiLoggerWriter) FlagsDate

func (this *MultiLoggerWriter) FlagsDate(b bool) *MultiLoggerWriter

func (*MultiLoggerWriter) FlagsLongFile

func (this *MultiLoggerWriter) FlagsLongFile(b bool) *MultiLoggerWriter

func (*MultiLoggerWriter) FlagsShortFile

func (this *MultiLoggerWriter) FlagsShortFile(b bool) *MultiLoggerWriter

func (*MultiLoggerWriter) FlagsStandard

func (this *MultiLoggerWriter) FlagsStandard(b bool) *MultiLoggerWriter

func (*MultiLoggerWriter) FlagsTime

func (this *MultiLoggerWriter) FlagsTime(b bool) *MultiLoggerWriter

func (*MultiLoggerWriter) FlagsUTC

func (this *MultiLoggerWriter) FlagsUTC(b bool) *MultiLoggerWriter

func (*MultiLoggerWriter) GetAccessBufWriter

func (this *MultiLoggerWriter) GetAccessBufWriter() io.Writer

func (*MultiLoggerWriter) GetAccessLogger

func (this *MultiLoggerWriter) GetAccessLogger() *log.Logger

func (*MultiLoggerWriter) GetAccessWriter

func (this *MultiLoggerWriter) GetAccessWriter() io.Writer

func (*MultiLoggerWriter) GetConfig

func (this *MultiLoggerWriter) GetConfig() (b []byte, err error)

func (*MultiLoggerWriter) GetErrorBufWriter

func (this *MultiLoggerWriter) GetErrorBufWriter() io.Writer

func (*MultiLoggerWriter) GetErrorLogger

func (this *MultiLoggerWriter) GetErrorLogger() *log.Logger

func (*MultiLoggerWriter) GetErrorWriter

func (this *MultiLoggerWriter) GetErrorWriter() io.Writer

func (*MultiLoggerWriter) GetSystemBufWriter

func (this *MultiLoggerWriter) GetSystemBufWriter() io.Writer

func (*MultiLoggerWriter) GetSystemLogger

func (this *MultiLoggerWriter) GetSystemLogger() *log.Logger

func (*MultiLoggerWriter) GetSystemWriter

func (this *MultiLoggerWriter) GetSystemWriter() io.Writer

func (*MultiLoggerWriter) Init

func (this *MultiLoggerWriter) Init() *MultiLoggerWriter

func (*MultiLoggerWriter) LogDir

func (this *MultiLoggerWriter) LogDir(s string) *MultiLoggerWriter

func (*MultiLoggerWriter) RecoveryStack

func (this *MultiLoggerWriter) RecoveryStack(b bool) *MultiLoggerWriter

func (*MultiLoggerWriter) SaveConfig

func (this *MultiLoggerWriter) SaveConfig(cf string) (err error)

func (*MultiLoggerWriter) SyslogHost

func (this *MultiLoggerWriter) SyslogHost(s string) *MultiLoggerWriter

func (*MultiLoggerWriter) SyslogPort

func (this *MultiLoggerWriter) SyslogPort(s string) *MultiLoggerWriter

func (*MultiLoggerWriter) SyslogProt

func (this *MultiLoggerWriter) SyslogProt(s string) *MultiLoggerWriter

func (*MultiLoggerWriter) SyslogTag

func (this *MultiLoggerWriter) SyslogTag(s string) *MultiLoggerWriter

func (*MultiLoggerWriter) SystemLog

func (this *MultiLoggerWriter) SystemLog(s string) *MultiLoggerWriter

func (*MultiLoggerWriter) SystemTag

func (this *MultiLoggerWriter) SystemTag(s string) *MultiLoggerWriter

func (*MultiLoggerWriter) SystemUseFlags

func (this *MultiLoggerWriter) SystemUseFlags(b bool) *MultiLoggerWriter

type MultiWriter

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

MultiWriter is an io.Writer that sends output to multiple destinations.

func NewMultiWriter

func NewMultiWriter() (this *MultiWriter)

NewMultiWriter returns an initialized MultiWriter object.

func (*MultiWriter) AddConsole

func (this *MultiWriter) AddConsole(h *os.File)

AddConsole appends a console to a MultiWriter writer. Consoles are treated separately as they shouldn't be closed on termination.

func (*MultiWriter) AddFile

func (this *MultiWriter) AddFile(f string)

AddFile appends a file to a MultiWriter writer.

func (*MultiWriter) AddWriter

func (this *MultiWriter) AddWriter(w io.Writer)

AddWriter appends a writer to a MultiWriter writer.

func (*MultiWriter) Close

func (this *MultiWriter) Close()

Close syncs and closes underlying file writers in MultiWriter.

func (*MultiWriter) Count

func (this *MultiWriter) Count() (n int)

Count returns the number of writers in MultiWriter.

func (*MultiWriter) Println

func (this *MultiWriter) Println(t ...interface{})

Println writes to each writer in default format with trailing newline.

func (*MultiWriter) Sync

func (this *MultiWriter) Sync()

Sync syncs underlying file and console writers in MultiWriter.

func (*MultiWriter) Write

func (this *MultiWriter) Write(b []byte) (n int, err error)

Write writes output to each writer in MultiWriter.

func (*MultiWriter) WriteError

func (this *MultiWriter) WriteError(e error)

WriteError converts an error to []byte and then calls Write.

func (*MultiWriter) WriteString

func (this *MultiWriter) WriteString(s string) (n int, err error)

WriteString converts string input to []byte and then calls Write.

Jump to

Keyboard shortcuts

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