lwutil

package module
v0.0.0-...-912ac77 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2015 License: MIT Imports: 25 Imported by: 2

README

golangUtil

Documentation

Index

Constants

View Source
const (
	CACHE_LIFE_SEC = 3600
	SCRIPT_SET_KV  = `
		redis.call('set', 'kv/'..KEYS[1], KEYS[2])
		redis.call('zadd', 'kvz', KEYS[3], 'kv/'..KEYS[1])
	`
	SCRIPT_GET_EXPIRED_KV = `` /* 237-byte string literal not displayed */

	SCRIPT_GETDEL = `` /* 164-byte string literal not displayed */

)

Variables

View Source
var (
	HttpCodeInternalServerError = http.StatusInternalServerError
	HttpCodeBadRequest          = http.StatusBadRequest

	DbMap = make(map[string]*DB)
)
View Source
var AccessControlAllowOrigins map[string]bool = map[string]bool{}

Functions

func CheckError

func CheckError(err error, errType string)

func CheckMathod

func CheckMathod(r *http.Request, method string)

func CheckSsdbError

func CheckSsdbError(resp []string, err error)

func CheckSsdbErrorDesc

func CheckSsdbErrorDesc(resp []string, err error, desc string)

func DecodeRequestBody

func DecodeRequestBody(r *http.Request, v interface{}) error

func EndTx

func EndTx(tx *sql.Tx, err *error)

func GenUUID

func GenUUID() string

func GetKv

func GetKv(key string, out interface{}, rc redis.Conn) (exist bool, err error)

func GetKvDb

func GetKvDb(key string, out interface{}) (exist bool, err error)

func GetRedisTime

func GetRedisTime() time.Time

func GetRedisTimeUnix

func GetRedisTimeUnix() int64

func GetStructFieldKVs

func GetStructFieldKVs(data interface{}) ([]string, []interface{}, error)

func GetStructFieldKeys

func GetStructFieldKeys(data interface{}) ([]string, error)

func GetStructFieldValues

func GetStructFieldValues(data interface{}) ([]interface{}, error)

func HGetKvs

func HGetKvs(hkvs []Hkv) error

func HSetKvs

func HSetKvs(hkvs []Hkv) error

func HttpTest

func HttpTest(handler ReqHandler, w http.ResponseWriter, req *http.Request)

func KvDelDb

func KvDelDb(keys ...interface{}) error

func KvGet

func KvGet(keys ...interface{}) ([][]byte, error)

func KvGetDb

func KvGetDb(keys ...interface{}) ([][]byte, error)

func KvPut

func KvPut(kvs ...Kv) error

func KvPutDb

func KvPutDb(kvs ...Kv) error

func KvScan

func KvScan(in [][]byte, out ...interface{}) error

func KvStart

func KvStart(pool *redis.Pool) error

func LoadCsvArray

func LoadCsvArray(file string, slicePtr interface{}) (err error)

func LoadCsvMap

func LoadCsvMap(file string, keyCols []string, mapPtr interface{}) (err error)

use "key1,key2" for multi column key mapPtr must be *map[string]struct

func LoginAuth

func LoginAuth(username, password, host string) smtp.Auth

func Max

func Max(a, b int64) int64

func Min

func Min(a, b int64) int64

func NewErr

func NewErr(err error) error

func NewErrStr

func NewErrStr(err string) error

func PanicIfError

func PanicIfError(err error)

func PlainAuth

func PlainAuth(identity, username, password, host string) smtp.Auth

func RepeatSingletonTask

func RepeatSingletonTask(redisPool *redis.Pool, key string, f func() error)

use go keyword to start a goroutine

func SendError

func SendError(errType, errStr string)

func SendMail

func SendMail(addr string, a smtp.Auth, from string, to []string, msg []byte) error

SendMail connects to the server at addr, switches to TLS if possible, authenticates with mechanism a if possible, and then sends an email from address from, to addresses to, with message msg.

func SetKv

func SetKv(key string, value interface{}, rc redis.Conn) error

func SetKvDb

func SetKvDb(key string, value interface{}) error

func Sha224

func Sha224(s string) string

func Sha256

func Sha256(s string) string

func StartKV

func StartKV(db *DB, pool *redis.Pool)

func Truncate

func Truncate(v, min, max int64) int64

func WriteResponse

func WriteResponse(w http.ResponseWriter, v interface{})

Types

type Client

type Client struct {
	// Text is the textproto.Conn used by the Client. It is exported to allow for
	// clients to add extensions.
	Text *textproto.Conn
	// contains filtered or unexported fields
}

func Dial

func Dial(addr string) (*Client, error)

Dial returns a new Client connected to an SMTP server at addr.

func NewClient

func NewClient(conn net.Conn, host string) (*Client, error)

NewClient returns a new Client using an existing connection and host as a server name to be used when authenticating.

func (*Client) Auth

func (c *Client) Auth(a smtp.Auth) error

Auth authenticates a client using the provided authentication mechanism. A failed authentication closes the connection. Only servers that advertise the AUTH extension support this function.

func (*Client) Data

func (c *Client) Data() (io.WriteCloser, error)

Data issues a DATA command to the server and returns a writer that can be used to write the data. The caller should close the writer before calling any more methods on c. A call to Data must be preceded by one or more calls to Rcpt.

func (*Client) Extension

func (c *Client) Extension(ext string) (bool, string)

Extension reports whether an extension is support by the server. The extension name is case-insensitive. If the extension is supported, Extension also returns a string that contains any parameters the server specifies for the extension.

func (*Client) Mail

func (c *Client) Mail(from string) error

Mail issues a MAIL command to the server using the provided email address. If the server supports the 8BITMIME extension, Mail adds the BODY=8BITMIME parameter. This initiates a mail transaction and is followed by one or more Rcpt calls.

func (*Client) Quit

func (c *Client) Quit() error

Quit sends the QUIT command and closes the connection to the server.

func (*Client) Rcpt

func (c *Client) Rcpt(to string) error

Rcpt issues a RCPT command to the server using the provided email address. A call to Rcpt must be preceded by a call to Mail and may be followed by a Data call or another Rcpt call.

func (*Client) Reset

func (c *Client) Reset() error

Reset sends the RSET command to the server, aborting the current mail transaction.

func (*Client) StartTLS

func (c *Client) StartTLS(config *tls.Config) error

StartTLS sends the STARTTLS command and encrypts all further communication. Only servers that advertise the STARTTLS extension support this function.

func (*Client) Verify

func (c *Client) Verify(addr string) error

Verify checks the validity of an email address on the server. If Verify returns nil, the address is valid. A non-nil return does not necessarily indicate an invalid address. Many servers will not verify addresses for security reasons.

type DB

type DB struct {
	*sql.DB
	Name string
}

func OpenDb

func OpenDb(dbname string) (*DB, error)

type Err

type Err struct {
	Error       string
	ErrorString string
}

type Hkv

type Hkv struct {
	Db        *DB
	TableName string
	KeyName   string
	KeyValue  interface{}
	Value     interface{}
	Error     error
}

type Kv

type Kv struct {
	Key   interface{}
	Value interface{}
}

type ReqHandler

type ReqHandler func(http.ResponseWriter, *http.Request)

func (ReqHandler) ServeHTTP

func (fn ReqHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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