gokits

package module
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2021 License: MIT Imports: 38 Imported by: 12

README

gokits

Build Status codecov GitHub release (latest by date) MIT Licence GoDoc GitHub code size

Go常用工具包.

boolean

string to bool工具.

cache

重构来自muesli/cache2go

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

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

collections

字符串数组/切片工具

cond

条件表达式工具

gql

数据库访问工具

hashset

实现Java HashSet

hashtable

实现Java HashTable

http

HTTP工具

httpdownload

HTTP文件下载

httpelf && httpserver

HTTPServer工具

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

random

随机字符串

rsa

RSA非对称加密算法工具, 包括密钥生成, 公钥加密/私钥解密, 私钥签名/公钥验签.

secret

HmacSha256, AES工具

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
)

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 (
	SHA1WithRSA   = Signer{/* contains filtered or unexported fields */}
	SHA256WithRSA = Signer{/* contains filtered or unexported fields */}
)
View Source
var ContextPathDisabled = func(o *HandleFuncOptions) { o.ContextPathEnabled = false }
View Source
var ContextPathEnabled = func(o *HandleFuncOptions) { o.ContextPathEnabled = true }
View Source
var DumpRequestDisabled = func(o *HandleFuncOptions) { o.DumpRequestEnabled = false }
View Source
var DumpRequestEnabled = func(o *HandleFuncOptions) { o.DumpRequestEnabled = true }
View Source
var EmptyHandler http.HandlerFunc = func(_ http.ResponseWriter, _ *http.Request) {}
View Source
var GzipResponseDisabled = func(o *HandleFuncOptions) { o.GzipResponseEnabled = false }
View Source
var GzipResponseEnabled = func(o *HandleFuncOptions) { o.GzipResponseEnabled = true }
View Source
var ModelContextDisabled = func(o *HandleFuncOptions) { o.ModelContextEnabled = false }
View Source
var ModelContextEnabled = func(o *HandleFuncOptions) { o.ModelContextEnabled = true }
View Source
var ReverseProxyUserAgent = ""

Functions

func AESDecrypt added in v0.5.0

func AESDecrypt(value, key string) string

func AESEncrypt added in v0.5.0

func AESEncrypt(value, key string) string

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 DecryptByRSAKey added in v0.6.0

func DecryptByRSAKey(cipherBytes []byte, privateKey *rsa.PrivateKey) ([]byte, error)

func DecryptByRSAKeyString added in v0.6.0

func DecryptByRSAKeyString(cipherBytes []byte, privateKeyString string) ([]byte, error)

func DefaultIfNil

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

func DumpRequest added in v0.5.0

func DumpRequest(handlerFunc http.HandlerFunc) http.HandlerFunc

func EncryptByRSAKey added in v0.6.0

func EncryptByRSAKey(plainBytes []byte, publicKey *rsa.PublicKey) ([]byte, error)

func EncryptByRSAKeyString added in v0.6.0

func EncryptByRSAKeyString(plainBytes []byte, publicKeyString string) ([]byte, error)

func FirstNonLoopbackAddress added in v0.6.0

func FirstNonLoopbackAddress() (net.IP, error)

func FormIntValue added in v0.5.0

func FormIntValue(request *http.Request, key string) int

func FormIntValueDefault added in v0.5.0

func FormIntValueDefault(request *http.Request, key string, defaultValue int) int

func GetIpInt64 added in v0.6.0

func GetIpInt64() (int64, error)

func GzipResponse added in v0.5.0

func GzipResponse(handlerFunc http.HandlerFunc) http.HandlerFunc

func HandleFunc added in v0.5.0

func HandleFunc(mux *http.ServeMux, path string, handler http.HandlerFunc, opts ...HandleFuncOption)

func HmacSha256Base64 added in v0.5.0

func HmacSha256Base64(plainText string, key string) string

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 IsAjaxRequest added in v0.5.0

func IsAjaxRequest(request *http.Request) bool

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 MinifyCSS added in v0.5.0

func MinifyCSS(cssString string, devMode bool) string

func MinifyHTML added in v0.5.0

func MinifyHTML(htmlString string, devMode bool) string

func MinifyJs added in v0.5.0

func MinifyJs(jsString string, devMode bool) string

func NextId added in v0.6.0

func NextId() string

func PathJoin added in v0.3.1

func PathJoin(elem ...string) string

func RSAPrivateKeyDecoded added in v0.6.0

func RSAPrivateKeyDecoded(privateKeyString string) (*rsa.PrivateKey, error)

func RSAPublicKeyDecoded added in v0.6.0

func RSAPublicKeyDecoded(publicKeyString string) (*rsa.PublicKey, error)

func RandomString added in v0.5.0

func RandomString(length int) string

func RequestBody added in v0.5.0

func RequestBody(request *http.Request) (string, error)

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)

func ResponseErrorJson added in v0.3.1

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

func ResponseErrorText added in v0.3.1

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

func ResponseHtml added in v0.3.1

func ResponseHtml(writer http.ResponseWriter, html string)

func ResponseJson added in v0.3.1

func ResponseJson(writer http.ResponseWriter, json string)

func ResponseText added in v0.3.1

func ResponseText(writer http.ResponseWriter, text string)

func ReverseProxy added in v0.5.0

func ReverseProxy(target *url.URL) *httputil.ReverseProxy

func ServeAjax added in v0.5.0

func ServeAjax(handlerFunc http.HandlerFunc) http.HandlerFunc

func ServeGet added in v0.5.0

func ServeGet(handlerFunc http.HandlerFunc) http.HandlerFunc

func ServeMethod added in v0.5.0

func ServeMethod(handlerFunc http.HandlerFunc, httpMethods ...string) http.HandlerFunc

func ServeModelContext added in v0.5.0

func ServeModelContext(handlerFunc http.HandlerFunc) http.HandlerFunc

func ServeModelContextWithValueFunc added in v0.5.0

func ServeModelContextWithValueFunc(handlerFunc http.HandlerFunc, valueFunc ModelCtxValueFunc) http.HandlerFunc

func ServePost added in v0.5.0

func ServePost(handlerFunc http.HandlerFunc) http.HandlerFunc

func ServeRedirect added in v0.5.0

func ServeRedirect(redirect string) http.HandlerFunc

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 ToBool added in v0.6.0

func ToBool(str string) bool

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 NewCacheExpireAfterAccess added in v0.6.1

func NewCacheExpireAfterAccess(table string) *CacheTable

func NewCacheExpireAfterWrite added in v0.6.1

func NewCacheExpireAfterWrite(table string) *CacheTable

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 Duration added in v0.6.2

type Duration struct {
	time.Duration
}

func (*Duration) MarshalText added in v0.6.2

func (d *Duration) MarshalText() ([]byte, error)

func (*Duration) UnmarshalText added in v0.6.2

func (d *Duration) UnmarshalText(text []byte) error

type ExpireStrategy

type ExpireStrategy int

type GzipResponseWriter added in v0.5.0

type GzipResponseWriter struct {
	io.Writer
	http.ResponseWriter
}

func (GzipResponseWriter) Write added in v0.5.0

func (w GzipResponseWriter) Write(b []byte) (int, error)

type HandleFuncOption added in v0.5.0

type HandleFuncOption func(*HandleFuncOptions)

type HandleFuncOptions added in v0.5.0

type HandleFuncOptions struct {
	DumpRequestEnabled  bool
	GzipResponseEnabled bool
	ModelContextEnabled bool
	ContextPathEnabled  bool
}

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 HttpDownload added in v0.5.0

type HttpDownload struct {
	RawURL    string
	DstDir    string
	FileName  string
	OverWrite bool
}

func NewHttpDownload added in v0.5.0

func NewHttpDownload(opts ...HttpDownloadOption) *HttpDownload

func (*HttpDownload) Start added in v0.5.0

func (download *HttpDownload) Start(opts ...HttpDownloadDelegateOption)

type HttpDownloadDelegate added in v0.5.0

type HttpDownloadDelegate struct {
	DownloadDidFailWithError    func(*HttpDownload, error)
	DownloadDidStarted          func(*HttpDownload)
	DownloadingWithProgress     func(*HttpDownload, float64)
	DownloadingProgressInterval time.Duration
	DownloadDidFinish           func(*HttpDownload)
}

type HttpDownloadDelegateOption added in v0.5.0

type HttpDownloadDelegateOption func(*HttpDownloadDelegateOptions)

func WithDownloadDidFailWithError added in v0.5.0

func WithDownloadDidFailWithError(f func(*HttpDownload, error)) HttpDownloadDelegateOption

func WithDownloadDidFinish added in v0.5.0

func WithDownloadDidFinish(f func(*HttpDownload)) HttpDownloadDelegateOption

func WithDownloadDidStarted added in v0.5.0

func WithDownloadDidStarted(f func(*HttpDownload)) HttpDownloadDelegateOption

func WithDownloadingProgressInterval added in v0.5.1

func WithDownloadingProgressInterval(interval time.Duration) HttpDownloadDelegateOption

func WithDownloadingWithProgress added in v0.5.0

func WithDownloadingWithProgress(f func(*HttpDownload, float64)) HttpDownloadDelegateOption

type HttpDownloadDelegateOptions added in v0.5.0

type HttpDownloadDelegateOptions struct {
	DownloadDidFailWithError    func(*HttpDownload, error)
	DownloadDidStarted          func(*HttpDownload)
	DownloadingWithProgress     func(*HttpDownload, float64)
	DownloadingProgressInterval time.Duration
	DownloadDidFinish           func(*HttpDownload)
}

type HttpDownloadOption added in v0.5.0

type HttpDownloadOption func(*HttpDownloadOptions)

func WithDstDir added in v0.5.0

func WithDstDir(dstDir string) HttpDownloadOption

func WithFileName added in v0.5.0

func WithFileName(fileName string) HttpDownloadOption

func WithOverWrite added in v0.5.0

func WithOverWrite(overWrite bool) HttpDownloadOption

func WithRawURL added in v0.5.0

func WithRawURL(rawURL string) HttpDownloadOption

type HttpDownloadOptions added in v0.5.0

type HttpDownloadOptions struct {
	RawURL    string
	DstDir    string
	FileName  string
	OverWrite bool
}

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 HttpServerConfig added in v0.5.0

type HttpServerConfig struct {
	Port        int
	ContextPath string
}
var GlobalHttpServerConfig *HttpServerConfig = nil

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 ModelCtx added in v0.5.0

type ModelCtx struct {
	context.Context
	Model map[string]interface{}
}

func ModelContext added in v0.5.0

func ModelContext(parent context.Context) *ModelCtx

func ModelContextWithValue added in v0.5.0

func ModelContextWithValue(parent context.Context, key string, val interface{}) *ModelCtx

func (*ModelCtx) String added in v0.5.0

func (m *ModelCtx) String() string

func (*ModelCtx) Value added in v0.5.0

func (m *ModelCtx) Value(key interface{}) interface{}

type ModelCtxValueFunc added in v0.5.0

type ModelCtxValueFunc func() (string, interface{})

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(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 RSAKeyPair added in v0.6.0

type RSAKeyPair struct {
	PrivateKey *rsa.PrivateKey
	PublicKey  *rsa.PublicKey
}

func GenerateRSAKeyPair added in v0.6.0

func GenerateRSAKeyPair(keySize int) (*RSAKeyPair, error)

func GenerateRSAKeyPairDefault added in v0.6.0

func GenerateRSAKeyPairDefault() (*RSAKeyPair, error)

func (*RSAKeyPair) RSAPrivateKeyEncoded added in v0.6.0

func (p *RSAKeyPair) RSAPrivateKeyEncoded() (string, error)

func (*RSAKeyPair) RSAPublicKeyEncoded added in v0.6.0

func (p *RSAKeyPair) RSAPublicKeyEncoded() (string, error)

type RecFunc

type RecFunc func(interface{}) interface{}

func YComb

func YComb(f func(RecFunc) RecFunc) RecFunc

type Signer added in v0.6.0

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

func (*Signer) SignBase64ByRSAKey added in v0.6.0

func (s *Signer) SignBase64ByRSAKey(plainText string, privateKey *rsa.PrivateKey) (string, error)

func (*Signer) SignBase64ByRSAKeyString added in v0.6.0

func (s *Signer) SignBase64ByRSAKeyString(plainText, privateKeyString string) (string, error)

func (*Signer) SignByRSAKey added in v0.6.0

func (s *Signer) SignByRSAKey(plainText string, privateKey *rsa.PrivateKey) ([]byte, error)

func (*Signer) SignByRSAKeyString added in v0.6.0

func (s *Signer) SignByRSAKeyString(plainText, privateKeyString string) ([]byte, error)

func (*Signer) VerifyBase64ByRSAKey added in v0.6.0

func (s *Signer) VerifyBase64ByRSAKey(plainText, signText string, publicKey *rsa.PublicKey) error

func (*Signer) VerifyBase64ByRSAKeyString added in v0.6.0

func (s *Signer) VerifyBase64ByRSAKeyString(plainText, signText, publicKeyString string) error

func (*Signer) VerifyByRSAKey added in v0.6.0

func (s *Signer) VerifyByRSAKey(plainText string, sign []byte, publicKey *rsa.PublicKey) error

func (*Signer) VerifyByRSAKeyString added in v0.6.0

func (s *Signer) VerifyByRSAKeyString(plainText string, sign []byte, publicKeyString string) error

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