gokits

package module
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2019 License: MIT Imports: 21 Imported by: 12

README

gokits

Build Status codecov GitHub version MIT Licence GoDoc

Go常用工具包.

cache

重构来自muesli/cache2go

在原有访问缓存过期策略的基础上, 增加写入缓存过期策略.

在原有缓存Loader类型上, 增加异常返回值.

collections

字符串数组/切片工具

cond

条件表达式工具

gql

数据库访问工具

hashset

实现Java HashSet

hashtable

实现Java HashTable

http

HTTP工具

httpreq

网络请求工具

json

JSON序列化/反序列化工具

line_reader

实现Java LineReader

log4go

本地日志

Fork from https://github.com/alecthomas/log4go

Source Code from http://code.google.com/p/log4go/

Please see http://log4go.googlecode.com/

Installation:

  • Run goinstall log4go.googlecode.com/hg

Usage:

  • Add the following import: import l4g "log4go.googlecode.com/hg"

Acknowledgements:

  • pomack For providing awesome patches to bring log4go up to the latest Go spec
path

路径合并工具

properties

实现Java Properties

strconv

字符串数字转换工具

yaml

重构来自kylelemons/go-gypsy

ycomb

Go语言实现Y组合子

参考:

使用Lambda 表达式编写递归三:实现 Y 组合子 - 鹤冲天 - 博客园

Documentation

Overview

Gypsy is a simplified YAML parser written in Go. It is intended to be used as a simple configuration file, and as such does not support a lot of the more nuanced syntaxes allowed in full-fledged YAML. YAML does not allow indent with tabs, and GYPSY does not ever consider a tab to be a space character. It is recommended that your editor be configured to convert tabs to spaces when editing Gypsy config files.

Gypsy understands the following to be a list:

  • one
  • two
  • three

This is parsed as a `yaml.YamlList`, and can be retrieved from the `yaml.YamlNode.YamlList()` method. In this case, each element of the `yaml.YamlList` would be a `yaml.YamlScalar` whose value can be retrieved with the `yaml.YamlScalar.String()` method.

Gypsy understands the following to be a mapping:

key:     value
foo:     bar
running: away

A mapping is an unordered list of `key:value` pairs. All whitespace after the colon is stripped from the value and is used for alignment purposes during export. If the value is not a list or a map, everything after the first non-space character until the end of the line is used as the `yaml.YamlScalar` value.

Gypsy allows arbitrary nesting of maps inside lists, lists inside of maps, and maps and/or lists nested inside of themselves.

A map inside of a list:

  • name: John Smith age: 42
  • name: Jane Smith age: 45

A list inside of a map:

schools:
  - Meadow Glen
  - Forest Creek
  - Shady Grove
libraries:
  - Joseph Hollingsworth Memorial
  - Andrew Keriman Memorial

A list of lists:

  • - one
  • two
  • three
  • - un
  • deux
  • trois
  • - ichi
  • ni
  • san

A map of maps:

google:
  company: Google, Inc.
  ticker:  GOOG
  url:     http://google.com/
yahoo:
  company: Yahoo, Inc.
  ticker:  YHOO
  url:     http://yahoo.com/

In the case of a map of maps, all sub-keys must be on subsequent lines and indented equally. It is allowable for the first key/value to be on the same line if there is more than one key/value pair, but this is not recommended.

Values can also be expressed in long form (leading whitespace of the first line is removed from it and all subsequent lines). In the normal (baz) case, newlines are treated as spaces, all indentation is removed. In the folded case (bar), newlines are treated as spaces, except pairs of newlines (e.g. a blank line) are treated as a single newline, only the indentation level of the first line is removed, and newlines at the end of indented lines are preserved. In the verbatim (foo) case, only the indent at the level of the first line is stripped. The example:

foo: |
  lorem ipsum dolor
  sit amet
bar: >
  lorem ipsum

    dolor

  sit amet
baz:
  lorem ipsum
   dolor sit amet

The YAML subset understood by Gypsy can be expressed (loosely) in the following grammar (not including comments):

        OBJECT = MAPPING | SEQUENCE | SCALAR .
  SHORT-OBJECT = SHORT-MAPPING | SHORT-SEQUENCE | SHORT-SCALAR .
           EOL = '\n'

       MAPPING = { LONG-MAPPING | SHORT-MAPPING } .
      SEQUENCE = { LONG-SEQUENCE | SHORT-SEQUENCE } .
        SCALAR = { LONG-SCALAR | SHORT-SCALAR } .

  LONG-MAPPING = { INDENT KEY ':' OBJECT EOL } .
 SHORT-MAPPING = '{' KEY ':' SHORT-OBJECT { ',' KEY ':' SHORT-OBJECT } '}' EOL .

 LONG-SEQUENCE = { INDENT '-' OBJECT EOL } EOL .
SHORT-SEQUENCE = '[' SHORT-OBJECT { ',' SHORT-OBJECT } ']' EOL .

   LONG-SCALAR = ( '|' | '>' | ) EOL { INDENT SHORT-SCALAR EOL }
  SHORT-SCALAR = { alpha | digit | punct | ' ' | '\t' } .

           KEY = { alpha | digit }
        INDENT = { ' ' }

Any line where the first non-space character is a sharp sign (#) is a comment. It will be ignored. Only full-line comments are allowed.

Index

Constants

View Source
const (
	ExpireAfterWrite  = 0
	ExpireAfterAccess = 1
)
View Source
const (
	L4G_VERSION = "log4go-v4.0.1"
	L4G_MAJOR   = 4
	L4G_MINOR   = 0
	L4G_BUILD   = 1
)

Version information noinspection GoSnakeCaseUsage,GoUnusedConst

View Source
const (
	FINEST level = iota
	FINE
	DEBUG
	TRACE
	INFO
	WARNING
	ERROR
	CRITICAL
)
View Source
const (
	FORMAT_DEFAULT = "[%D %T] [%L] (%S) %M"
	FORMAT_SHORT   = "[%t %d] [%L] %M"
	FORMAT_ABBREV  = "[%L] %M"
)

noinspection GoSnakeCaseUsage

Variables

View Source
var (
	// ErrCacheKeyNotFound gets returned when a specific key couldn't be found
	ErrCacheKeyNotFound = errors.New("key not found in cache")
	// ErrCacheKeyNotFoundOrLoadable gets returned when a specific key couldn't be
	// found and loading via the data-loader callback also failed
	ErrCacheKeyNotFoundOrLoadable = errors.New("key not found and could not be loaded into cache")
)
View Source
var (
	LOG logWrapper
)
View Source
var (
	// LogBufferLength specifies how many log messages a particular log4go
	// logger can buffer at a time before writing them.
	LogBufferLength = 32
)

***** Variables *****

Functions

func ArrayContains added in v0.3.1

func ArrayContains(aStr string, arr []string) bool

func ArrayContainsIgnoreCase added in v0.3.1

func ArrayContainsIgnoreCase(aStr string, arr []string) bool

func ArrayIndexOf added in v0.3.1

func ArrayIndexOf(aStr string, arr []string) int

func ArrayIndexOfIgnoreCase added in v0.3.1

func ArrayIndexOfIgnoreCase(aStr string, arr []string) int

func Bool added in v0.3.1

func Bool(node YamlNode, spec string) (bool, error)

func BoolChild added in v0.3.0

func BoolChild(root YamlNode, spec string) (bool, error)

func Condition

func Condition(cond bool, trueVal, falseVal interface{}) interface{}

func DefaultIfNil

func DefaultIfNil(val, def interface{}) interface{}

func FormatLogRecord

func FormatLogRecord(format string, rec *LogRecord) string

Known format codes: %T - Time (15:04:05 MST) %t - Time (15:04) %D - Date (2006/01/02) %d - Date (01/02/06) %L - Level (FNST, FINE, DEBG, TRAC, WARN, EROR, CRIT) %S - Source %M - Message Ignores unknown formats Recommended: "[%D %T] [%L] (%S) %M"

func GqlConnection

func GqlConnection(name string) *sql.DB

func If

func If(cond bool, trueFunc func())

func Int added in v0.3.1

func Int(node YamlNode, spec string) (int64, error)

func Int64FromStr

func Int64FromStr(str string) (int64, error)

func IntChild added in v0.3.0

func IntChild(root YamlNode, spec string) (int64, error)

func IntFromStr

func IntFromStr(str string) (int, error)

func Json

func Json(v interface{}) string

func ListChildCount added in v0.3.0

func ListChildCount(root YamlNode, spec string) (int, error)

func ListCount added in v0.3.1

func ListCount(node YamlNode, spec string) (int, error)

func LoadGqlConfigFile

func LoadGqlConfigFile(filename string)

noinspection GoUnusedExportedFunction

func LoadGqlConfigString

func LoadGqlConfigString(yamlconf string)

noinspection GoUnusedExportedFunction

func PathJoin added in v0.3.1

func PathJoin(elem ...string) string

func ResponseContent added in v0.3.1

func ResponseContent(writer http.ResponseWriter,
	content, contentType, characterEncoding string)

func ResponseErrorContent added in v0.3.1

func ResponseErrorContent(writer http.ResponseWriter, statusCode int,
	errorContent, contentType, characterEncoding string)

func ResponseErrorHtml added in v0.3.1

func ResponseErrorHtml(writer http.ResponseWriter, statusCode int, html string)

noinspection GoUnusedExportedFunction

func ResponseErrorJson added in v0.3.1

func ResponseErrorJson(writer http.ResponseWriter, statusCode int, json string)

noinspection GoUnusedExportedFunction

func ResponseErrorText added in v0.3.1

func ResponseErrorText(writer http.ResponseWriter, statusCode int, text string)

noinspection GoUnusedExportedFunction

func ResponseHtml added in v0.3.1

func ResponseHtml(writer http.ResponseWriter, html string)

noinspection GoUnusedExportedFunction

func ResponseJson added in v0.3.1

func ResponseJson(writer http.ResponseWriter, json string)

noinspection GoUnusedExportedFunction

func ResponseText added in v0.3.1

func ResponseText(writer http.ResponseWriter, text string)

noinspection GoUnusedExportedFunction

func StrFromInt

func StrFromInt(i int) string

func StrFromInt64

func StrFromInt64(i int64) string

func String added in v0.3.1

func String(node YamlNode, spec string) (string, error)

func StringChild added in v0.3.0

func StringChild(root YamlNode, spec string) (string, error)

func UnJson

func UnJson(str string, v interface{}) interface{}

func Unless

func Unless(cond bool, falseFunc func())

func ValOrFunc

func ValOrFunc(val interface{}) interface{}

func YamlRender

func YamlRender(node YamlNode) string

YamlRender returns a string of the node as a YAML document. Note that Scalars will have a newline appended if they are rendered directly.

Types

type CacheItem

type CacheItem struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

CacheItem is an individual cache item Parameter data contains the user-set value in the cache.

func NewCacheItem

func NewCacheItem(key interface{}, lifeSpan time.Duration, data interface{}) *CacheItem

NewCacheItem returns a newly created CacheItem. Parameter key is the item's cache-key. Parameter lifeSpan determines after which time period without an access the item will get removed from the cache. Parameter data is the item's value.

func (*CacheItem) AccessCount

func (item *CacheItem) AccessCount() int64

AccessCount returns how often this item has been accessed.

func (*CacheItem) AccessedOn

func (item *CacheItem) AccessedOn() time.Time

AccessedOn returns when this item was last accessed.

func (*CacheItem) CreatedOn

func (item *CacheItem) CreatedOn() time.Time

CreatedOn returns when this item was added to the cache.

func (*CacheItem) Data

func (item *CacheItem) Data() interface{}

Data returns the value of this cached item.

func (*CacheItem) KeepAlive

func (item *CacheItem) KeepAlive()

KeepAlive marks an item to be kept for another expireDuration period. Ignored in ExpireAfterWrite cache

func (*CacheItem) Key

func (item *CacheItem) Key() interface{}

Key returns the key of this cached item.

func (*CacheItem) LifeSpan

func (item *CacheItem) LifeSpan() time.Duration

LifeSpan returns this item's expiration duration.

func (*CacheItem) SetAboutToExpireCallback

func (item *CacheItem) SetAboutToExpireCallback(f func(interface{}))

SetAboutToExpireCallback configures a callback, which will be called right before the item is about to be removed from the cache.

type CacheItemPair

type CacheItemPair struct {
	Key         interface{}
	AccessCount int64
}

CacheItemPair maps key to access counter

type CacheItemPairList

type CacheItemPairList []CacheItemPair

CacheItemPairList is a slice of CacheIemPairs that implements sort. Interface to sort by AccessCount.

func (CacheItemPairList) Len

func (p CacheItemPairList) Len() int

func (CacheItemPairList) Less

func (p CacheItemPairList) Less(i, j int) bool

func (CacheItemPairList) Swap

func (p CacheItemPairList) Swap(i, j int)

type CacheTable

type CacheTable struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

CacheTable is a table within the cache

func CacheExpireAfterAccess

func CacheExpireAfterAccess(table string) *CacheTable

noinspection GoUnusedExportedFunction

func CacheExpireAfterWrite

func CacheExpireAfterWrite(table string) *CacheTable

noinspection GoUnusedExportedFunction

func (*CacheTable) Add

func (table *CacheTable) Add(key interface{}, lifeSpan time.Duration, data interface{}) *CacheItem

Add adds a key/value pair to the cache. Parameter key is the item's cache-key. Parameter lifeSpan determines after which time period without an access the item will get removed from the cache. Parameter data is the item's value.

func (*CacheTable) Count

func (table *CacheTable) Count() int

Count returns how many items are currently stored in the cache.

func (*CacheTable) Delete

func (table *CacheTable) Delete(key interface{}) (*CacheItem, error)

Delete an item from the cache.

func (*CacheTable) Exists

func (table *CacheTable) Exists(key interface{}) bool

Exists returns whether an item exists in the cache. Unlike the Value method Exists neither tries to fetch data via the loadData callback nor does it keep the item alive in the cache.

func (*CacheTable) Flush

func (table *CacheTable) Flush()

Flush deletes all items from this cache table.

func (*CacheTable) Foreach

func (table *CacheTable) Foreach(trans func(key interface{}, item *CacheItem))

Foreach all items

func (*CacheTable) LoadingAdd

func (table *CacheTable) LoadingAdd(key interface{}, args ...interface{}) (*CacheItem, error)

func (*CacheTable) MostAccessed

func (table *CacheTable) MostAccessed(count int64) []*CacheItem

MostAccessed returns the most accessed items in this cache table

func (*CacheTable) NotFoundAdd

func (table *CacheTable) NotFoundAdd(key interface{}, lifeSpan time.Duration, data interface{}) bool

NotFoundAdd tests whether an item not found in the cache. Unlike the Exists method this also adds data if they key could not be found.

func (*CacheTable) SetAboutToDeleteItemCallback

func (table *CacheTable) SetAboutToDeleteItemCallback(f func(*CacheItem))

SetAboutToDeleteItemCallback configures a callback, which will be called every time an item is about to be removed from the cache.

func (*CacheTable) SetAddedItemCallback

func (table *CacheTable) SetAddedItemCallback(f func(*CacheItem))

SetAddedItemCallback configures a callback, which will be called every time a new item is added to the cache.

func (*CacheTable) SetDataLoader

func (table *CacheTable) SetDataLoader(f func(interface{}, ...interface{}) (*CacheItem, error))

SetDataLoader configures a data-loader callback, which will be called when trying to access a non-existing key. The key and 0...n additional arguments are passed to the callback function.

func (*CacheTable) SetLogger

func (table *CacheTable) SetLogger(logger *log.Logger)

SetLogger sets the logger to be used by this cache table.

func (*CacheTable) Value

func (table *CacheTable) Value(key interface{}, args ...interface{}) (*CacheItem, error)

Value returns an item from the cache and marks it to be kept alive. You can pass additional arguments to your DataLoader callback function.

type ConsoleLogWriter

type ConsoleLogWriter chan *LogRecord

This is the standard writer that prints to standard output.

func NewConsoleLogWriter

func NewConsoleLogWriter() ConsoleLogWriter

This creates a new ConsoleLogWriter

func (ConsoleLogWriter) Close

func (w ConsoleLogWriter) Close()

Close stops the logger from sending messages to standard output. Attempts to send log messages to this logger after a Close have undefined behavior.

func (ConsoleLogWriter) LogWrite

func (w ConsoleLogWriter) LogWrite(rec *LogRecord)

This is the ConsoleLogWriter's output method. This will block if the output buffer is full.

type ExpireStrategy

type ExpireStrategy int

type FileLogWriter

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

This log writer sends output to a file noinspection GoSnakeCaseUsage

func NewFileLogWriter

func NewFileLogWriter(fname string, rotate bool) *FileLogWriter

NewFileLogWriter creates a new LogWriter which writes to the given file and has rotation enabled if rotate is true.

If rotate is true, any time a new log file is opened, the old one is renamed with a .### extension to preserve it. The various Set* methods can be used to configure log rotation based on lines, size, and daily.

The standard log-line format is:

[%D %T] [%L] (%S) %M

func NewXMLLogWriter

func NewXMLLogWriter(fname string, rotate bool) *FileLogWriter

NewXMLLogWriter is a utility method for creating a FileLogWriter set up to output XML record log messages instead of line-based ones.

func (*FileLogWriter) Close

func (w *FileLogWriter) Close()

func (*FileLogWriter) LogWrite

func (w *FileLogWriter) LogWrite(rec *LogRecord)

This is the FileLogWriter's output method

func (*FileLogWriter) Rotate

func (w *FileLogWriter) Rotate()

Request that the logs rotate

func (*FileLogWriter) SetFormat

func (w *FileLogWriter) SetFormat(format string) *FileLogWriter

Set the logging format (chainable). Must be called before the first log message is written.

func (*FileLogWriter) SetHeadFoot

func (w *FileLogWriter) SetHeadFoot(head, foot string) *FileLogWriter

Set the logfile header and footer (chainable). Must be called before the first log message is written. These are formatted similar to the FormatLogRecord (e.g. you can use %D and %T in your header/footer for date and time).

func (*FileLogWriter) SetRotate

func (w *FileLogWriter) SetRotate(rotate bool) *FileLogWriter

SetRotate changes whether or not the old logs are kept. (chainable) Must be called before the first log message is written. If rotate is false, the files are overwritten; otherwise, they are rotated to another file before the new log is opened.

func (*FileLogWriter) SetRotateDaily

func (w *FileLogWriter) SetRotateDaily(daily bool) *FileLogWriter

Set rotate daily (chainable). Must be called before the first log message is written.

func (*FileLogWriter) SetRotateLines

func (w *FileLogWriter) SetRotateLines(maxlines int) *FileLogWriter

Set rotate at linecount (chainable). Must be called before the first log message is written.

func (*FileLogWriter) SetRotateSize

func (w *FileLogWriter) SetRotateSize(maxsize int) *FileLogWriter

Set rotate at size (chainable). Must be called before the first log message is written.

type FormatLogWriter

type FormatLogWriter chan *LogRecord

This is the standard writer that prints to standard output.

func NewFormatLogWriter

func NewFormatLogWriter(out io.Writer, format string) FormatLogWriter

This creates a new FormatLogWriter noinspection GoUnusedExportedFunction

func (FormatLogWriter) Close

func (w FormatLogWriter) Close()

Close stops the logger from sending messages to standard output. Attempts to send log messages to this logger after a Close have undefined behavior.

func (FormatLogWriter) LogWrite

func (w FormatLogWriter) LogWrite(rec *LogRecord)

This is the FormatLogWriter's output method. This will block if the output buffer is full.

type Gql

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

func DefaultGql

func DefaultGql() (*Gql, error)

func NewGql

func NewGql(connName string) (*Gql, error)

func (*Gql) New

func (gql *Gql) New() *gqlInst

type GqlConfig

type GqlConfig struct {
	DriverName      string
	DataSourceName  string
	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxLifetime int // Seconds
}

type Hashset added in v0.4.1

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

func NewHashset added in v0.4.1

func NewHashset() *Hashset

func (*Hashset) Add added in v0.4.1

func (hashset *Hashset) Add(item interface{}) bool

func (*Hashset) Contains added in v0.4.1

func (hashset *Hashset) Contains(item interface{}) bool

func (*Hashset) Items added in v0.4.1

func (hashset *Hashset) Items() []interface{}

func (*Hashset) Remove added in v0.4.1

func (hashset *Hashset) Remove(item interface{}) bool

func (*Hashset) Size added in v0.4.1

func (hashset *Hashset) Size() int

type Hashtable added in v0.4.0

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

func NewHashtable added in v0.4.0

func NewHashtable() *Hashtable

func (*Hashtable) Get added in v0.4.0

func (hashtable *Hashtable) Get(key interface{}) interface{}

func (*Hashtable) Keys added in v0.4.0

func (hashtable *Hashtable) Keys() []interface{}

func (*Hashtable) Put added in v0.4.0

func (hashtable *Hashtable) Put(key, value interface{}) interface{}

func (*Hashtable) Remove added in v0.4.0

func (hashtable *Hashtable) Remove(key interface{}) interface{}

func (*Hashtable) Size added in v0.4.0

func (hashtable *Hashtable) Size() int

type HttpReq

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

func NewHttpReq

func NewHttpReq(baseUrl string) *HttpReq

func (*HttpReq) Cookie

func (httpReq *HttpReq) Cookie(cookie *http.Cookie) *HttpReq

func (*HttpReq) Get

func (httpReq *HttpReq) Get() (string, error)

func (*HttpReq) Params

func (httpReq *HttpReq) Params(name string, value string, more ...string) *HttpReq

func (*HttpReq) ParamsMapping

func (httpReq *HttpReq) ParamsMapping(params map[string]string) *HttpReq

func (*HttpReq) Post

func (httpReq *HttpReq) Post() (string, error)

func (*HttpReq) Prop

func (httpReq *HttpReq) Prop(name string, value string) *HttpReq

func (*HttpReq) Req

func (httpReq *HttpReq) Req(req string) *HttpReq

func (*HttpReq) RequestBody

func (httpReq *HttpReq) RequestBody(requestBody string) *HttpReq

type LineReader added in v0.4.0

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

func NewLineReader added in v0.4.0

func NewLineReader(reader io.Reader) *LineReader

func (*LineReader) ReadLine added in v0.4.0

func (lineReader *LineReader) ReadLine() (int, error)

type LineReaderException added in v0.4.0

type LineReaderException struct {
	Message string
}

func (*LineReaderException) Error added in v0.4.0

func (e *LineReaderException) Error() string

type LogFilter added in v0.2.0

type LogFilter struct {
	Level level
	LogWriter
}

A LogFilter represents the log level below which no log records are written to the associated LogWriter.

type LogRecord

type LogRecord struct {
	Level   level     // The log level
	Created time.Time // The time at which the log message was created (nanoseconds)
	Source  string    // The message source
	Message string    // The log message
}

A LogRecord contains all of the pertinent information for each message

type LogWriter

type LogWriter interface {
	// This will be called to log a LogRecord message.
	LogWrite(rec *LogRecord)

	// This should clean up anything lingering about the LogWriter, as it is called before
	// the LogWriter is removed.  LogWrite should not be called after Close.
	Close()
}

This is an interface for anything that should be able to write logs

type Logger

type Logger map[string]*LogFilter

A Logger represents a collection of Filters through which log messages are written.

func NewDefaultLogger

func NewDefaultLogger(lvl level) Logger

Create a new logger with a "stdout" filter configured to send log messages at or above lvl to standard output.

func NewLogger

func NewLogger() Logger

Create a new logger.

func (Logger) AddFilter

func (log Logger) AddFilter(name string, lvl level, writer LogWriter) Logger

Add a new LogWriter to the Logger which will only log messages at lvl or higher. This function should not be called from multiple goroutines. Returns the logger for chaining.

func (Logger) Close

func (log Logger) Close()

Closes all log writers in preparation for exiting the program or a reconfiguration of logging. Calling this is not really imperative, unless you want to guarantee that all log messages are written. Close removes all filters (and thus all LogWriters) from the logger.

func (Logger) Critical

func (log Logger) Critical(arg0 interface{}, args ...interface{}) error

Critical logs a message at the critical log level and returns the formatted error, See Warn for an explanation of the performance and Debug for an explanation of the parameters.

func (Logger) Debug

func (log Logger) Debug(arg0 interface{}, args ...interface{})

Debug is a utility method for debug log messages. The behavior of Debug depends on the first argument:

  • arg0 is a string When given a string as the first argument, this behaves like Logf but with the DEBUG log level: the first argument is interpreted as a format for the latter arguments.
  • arg0 is a func()string When given a closure of type func()string, this logs the string returned by the closure iff it will be logged. The closure runs at most one time.
  • arg0 is interface{} When given anything else, the log message will be each of the arguments formatted with %v and separated by spaces (ala Sprint).

func (Logger) Error

func (log Logger) Error(arg0 interface{}, args ...interface{}) error

Error logs a message at the error log level and returns the formatted error, See Warn for an explanation of the performance and Debug for an explanation of the parameters.

func (Logger) Fine

func (log Logger) Fine(arg0 interface{}, args ...interface{})

Fine logs a message at the fine log level. See Debug for an explanation of the arguments.

func (Logger) Finest

func (log Logger) Finest(arg0 interface{}, args ...interface{})

Finest logs a message at the finest log level. See Debug for an explanation of the arguments.

func (Logger) Info

func (log Logger) Info(arg0 interface{}, args ...interface{})

Info logs a message at the info log level. See Debug for an explanation of the arguments.

func (Logger) LoadConfiguration

func (log Logger) LoadConfiguration(filename string)

Load XML configuration; see log_manual_test_example.xml for documentation

func (Logger) Log

func (log Logger) Log(lvl level, source, message string)

Send a log message with manual level, source, and message.

func (Logger) Logc

func (log Logger) Logc(lvl level, closure func() string)

Logc logs a string returned by the closure at the given log level, using the caller as its source. If no log message would be written, the closure is never called.

func (Logger) Logf

func (log Logger) Logf(lvl level, format string, args ...interface{})

Logf logs a formatted log message at the given log level, using the caller as its source.

func (Logger) Trace

func (log Logger) Trace(arg0 interface{}, args ...interface{})

Trace logs a message at the trace log level. See Debug for an explanation of the arguments.

func (Logger) Warn

func (log Logger) Warn(arg0 interface{}, args ...interface{}) error

Warn logs a message at the warning log level and returns the formatted error. At the warning level and higher, there is no performance benefit if the message is not actually logged, because all formats are processed and all closures are executed to format the error message. See Debug for further explanation of the arguments.

type Properties added in v0.4.0

type Properties struct {
	Hashtable
	// contains filtered or unexported fields
}

func NewProperties added in v0.4.0

func NewProperties() *Properties

func NewPropertiesDefault added in v0.4.0

func NewPropertiesDefault(defaults *Properties) *Properties

func (*Properties) GetProperty added in v0.4.0

func (properties *Properties) GetProperty(key string) string

func (*Properties) GetPropertyDefault added in v0.4.0

func (properties *Properties) GetPropertyDefault(key, defaultValue string) string

func (*Properties) List added in v0.4.0

func (properties *Properties) List(out io.Writer)

func (*Properties) Load added in v0.4.0

func (properties *Properties) Load(reader io.Reader) error

func (*Properties) PropertyNames added in v0.4.0

func (properties *Properties) PropertyNames() []interface{}

func (*Properties) Save added in v0.4.0

func (properties *Properties) Save(writer io.Writer, comments string)

func (*Properties) SetProperty added in v0.4.0

func (properties *Properties) SetProperty(key string, value string)

func (*Properties) Store added in v0.4.0

func (properties *Properties) Store(writer io.Writer, comments string) error

func (*Properties) StringPropertyNames added in v0.4.0

func (properties *Properties) StringPropertyNames() []string

func (*Properties) ToMap added in v0.4.0

func (properties *Properties) ToMap() map[interface{}]interface{}

type RecFunc

type RecFunc func(n interface{}) interface{}

func YComb

func YComb(b func(RecFunc) RecFunc) RecFunc

type SocketLogWriter

type SocketLogWriter chan *LogRecord

This log writer sends output to a socket

func NewSocketLogWriter

func NewSocketLogWriter(proto, hostport string) SocketLogWriter

func (SocketLogWriter) Close

func (w SocketLogWriter) Close()

func (SocketLogWriter) LogWrite

func (w SocketLogWriter) LogWrite(rec *LogRecord)

This is the SocketLogWriter's output method

type UnknownGqlConnectionName added in v0.2.0

type UnknownGqlConnectionName struct {
	Name string
}

func (*UnknownGqlConnectionName) Error added in v0.2.0

func (e *UnknownGqlConnectionName) Error() string

type YamlFile

type YamlFile struct {
	Root YamlNode
}

A YamlFile represents the top-level YAML node found in a file. It is intended for use as a configuration file.

func ConfigYamlFile

func ConfigYamlFile(filename string) *YamlFile

ConfigYamlFile reads a YAML configuration file from the given filename and panics if an error is found. This is a utility function and is intended for use in initializers. noinspection GoUnusedExportedFunction

func ConfigYamlString

func ConfigYamlString(yamlconf string) *YamlFile

ConfigYamlString reads a YAML configuration from a static string. If an error is found, it will panic. This is a utility function and is intended for use in initializers. noinspection GoUnusedExportedFunction

func ReadYamlFile

func ReadYamlFile(filename string) (*YamlFile, error)

ReadYamlFile reads a YAML configuration file from the given filename.

func ReadYamlString

func ReadYamlString(yamlconf string) (*YamlFile, error)

func (*YamlFile) GetBool

func (f *YamlFile) GetBool(spec string) (bool, error)

func (*YamlFile) GetInt

func (f *YamlFile) GetInt(spec string) (int64, error)

func (*YamlFile) GetList

func (f *YamlFile) GetList(spec string) (YamlList, error)

func (*YamlFile) GetListCount added in v0.3.0

func (f *YamlFile) GetListCount(spec string) (int, error)

func (*YamlFile) GetMap

func (f *YamlFile) GetMap(spec string) (YamlMap, error)

func (*YamlFile) GetNode added in v0.3.0

func (f *YamlFile) GetNode(spec string) (YamlNode, error)

func (*YamlFile) GetScalar

func (f *YamlFile) GetScalar(spec string) (YamlScalar, error)

func (*YamlFile) GetString

func (f *YamlFile) GetString(spec string) (string, error)

func (*YamlFile) RooListCount added in v0.3.0

func (f *YamlFile) RooListCount() (int, error)

func (*YamlFile) RootBool added in v0.3.0

func (f *YamlFile) RootBool() (bool, error)

func (*YamlFile) RootInt added in v0.3.0

func (f *YamlFile) RootInt() (int64, error)

func (*YamlFile) RootList added in v0.3.0

func (f *YamlFile) RootList() (YamlList, error)

func (*YamlFile) RootMap added in v0.3.0

func (f *YamlFile) RootMap() (YamlMap, error)

func (*YamlFile) RootScalar added in v0.3.0

func (f *YamlFile) RootScalar() (YamlScalar, error)

func (*YamlFile) RootString added in v0.3.0

func (f *YamlFile) RootString() (string, error)

type YamlList

type YamlList []YamlNode

A YamlList is a YAML Sequence of Nodes.

func List added in v0.3.0

func List(node YamlNode, spec string) (YamlList, error)

func ListChild added in v0.3.0

func ListChild(root YamlNode, spec string) (YamlList, error)

func (YamlList) Item

func (node YamlList) Item(idx int) YamlNode

GetString the idx'th item from the YamlList.

func (YamlList) Len

func (node YamlList) Len() int

GetString the number of items in the YamlList.

type YamlMap

type YamlMap map[string]YamlNode

A YamlMap is a YAML Mapping which maps Strings to Nodes.

func Map added in v0.3.0

func Map(node YamlNode, spec string) (YamlMap, error)

func MapChild added in v0.3.0

func MapChild(root YamlNode, spec string) (YamlMap, error)

func (YamlMap) Key

func (node YamlMap) Key(key string) YamlNode

Key returns the value associeted with the key in the map.

type YamlNode

type YamlNode interface {
	// contains filtered or unexported methods
}

A YamlNode is a YAML YamlNode which can be a YamlMap, YamlList or YamlScalar.

func YamlChild

func YamlChild(root YamlNode, spec string) (YamlNode, error)

YamlChild retrieves a child node from the specified node as follows:

.mapkey   - GetString the key 'mapkey' of the YamlNode, which must be a YamlMap
[idx]     - Choose the index from the current YamlNode, which must be a YamlList

The above selectors may be applied recursively, and each successive selector applies to the result of the previous selector. For convenience, a "." is implied as the first character if the first character is not a "." or "[". The node tree is walked from the given node, considering each token of the above format. If a node along the evaluation path is not found, an error is returned. If a node is not the proper type, an error is returned. If the final node is not a YamlScalar, an error is returned.

func YamlParse

func YamlParse(r io.Reader) (node YamlNode, err error)

YamlParse returns a root-level YamlNode parsed from the lines read from r. In general, this will be done for you by one of the YamlFile constructors.

type YamlNodeNotFound

type YamlNodeNotFound struct {
	Full string
	Spec string
}

func (*YamlNodeNotFound) Error

func (e *YamlNodeNotFound) Error() string

type YamlNodeTypeMismatch

type YamlNodeTypeMismatch struct {
	Full     string
	Spec     string
	Token    string
	Node     YamlNode
	Expected string
}

func (*YamlNodeTypeMismatch) Error

func (e *YamlNodeTypeMismatch) Error() string

type YamlScalar

type YamlScalar string

A YamlScalar is a YAML YamlScalar.

func Scalar added in v0.3.0

func Scalar(node YamlNode, spec string) (YamlScalar, error)

func ScalarChild added in v0.3.0

func ScalarChild(root YamlNode, spec string) (YamlScalar, error)

func (YamlScalar) Bool

func (node YamlScalar) Bool() (bool, error)

func (YamlScalar) Int

func (node YamlScalar) Int() (int64, error)

func (YamlScalar) String

func (node YamlScalar) String() (string, error)

String returns the string represented by this YamlScalar.

Notes

Bugs

  • Multi-line strings are currently not supported.

Jump to

Keyboard shortcuts

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