Documentation ¶
Overview ¶
Package yiigo 简单易用的 Go Web 微框架
获取:(推荐使用Glide)
glide init glide get github.com/iiinsomnia/yiigo go get github.com/iiinsomnia/yiigo
使用:(自动根据配置初始化组件)
import "github.com/iiinsomnia/yiigo"
获取相关依赖包:
glide update
For more details, see the documentation for the types and methods.
Index ¶
- Variables
- func DBConn(conn ...string) (*sqlx.DB, error)
- func Date(timestamp int64, format ...string) string
- func Err(c *gin.Context, code int, msg ...string)
- func HTTPGet(url string, headers map[string]string, timeout ...time.Duration) ([]byte, error)
- func HTTPPost(url string, body []byte, headers map[string]string, timeout ...time.Duration) ([]byte, error)
- func IP2long(ip string) int64
- func InSliceFloat64(x float64, a []float64) bool
- func InSliceInt(x int, a []int) bool
- func InSliceInt64(x int64, a []int64) bool
- func InSliceString(x string, a []string) bool
- func InsertSQL(table string, data interface{}) (string, []interface{})
- func IsXhr(c *gin.Context) bool
- func Long2IP(ip int64) string
- func MD5(s string) string
- func MongoSession(conn ...string) (*mgo.Session, error)
- func MyTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
- func OK(c *gin.Context, data ...interface{})
- func PGConn(conn ...string) (*sqlx.DB, error)
- func PGInsertSQL(table string, data interface{}) (string, []interface{})
- func PGUpdateSQL(query string, data interface{}, args ...interface{}) (string, []interface{})
- func RedisPool(conn ...string) (*redis.Pool, error)
- func SearchInt64s(a []int64, x int64) int
- func SeqID(session *mgo.Session, db string, collection string, seqs ...int64) (int64, error)
- func SortInt64s(a []int64)
- func UniqueFloat64(a []float64) []float64
- func UniqueInt(a []int) []int
- func UniqueInt64(a []int64) []int64
- func UniqueString(a []string) []string
- func UpdateSQL(query string, data interface{}, args ...interface{}) (string, []interface{})
- type HTTPSCert
- type Int64Slice
- type Mailer
- type ReqBody
- type Sequence
- type Spider
- type X
Constants ¶
This section is empty.
Variables ¶
var ( // DB default mysql connection DB *sqlx.DB )
var Env *env
Env enviroment
var ErrEnvNil = errors.New("yiigo: env config not found")
ErrEnvNil returned when config not found.
var Logger *zap.Logger
Logger yiigo logger
var ( // Mongo default mongo session Mongo *mgo.Session )
var ( // PG default postgres connection PG *sqlx.DB )
var ( // Redis default redis connection pool Redis *redis.Pool )
var YiiClient = &http.Client{ Timeout: 5 * time.Second, }
YiiClient HTTP request client
Functions ¶
func Date ¶
Date format a local time/date and returns a string formatted according to the given format string using the given timestamp of int64. The default format is: 2006-01-02 15:04:05.
func HTTPPost ¶
func HTTPPost(url string, body []byte, headers map[string]string, timeout ...time.Duration) ([]byte, error)
HTTPPost http post request
func IP2long ¶ added in v1.3.5
IP2long converts a string containing an (IPv4) Internet Protocol dotted address into a long integer
func InSliceFloat64 ¶ added in v1.2.0
InSliceFloat64 checks if x exists in a slice of float64s and returns TRUE if x is found.
func InSliceInt ¶ added in v1.2.0
InSliceInt checks if x exists in a slice of ints and returns TRUE if x is found.
func InSliceInt64 ¶ added in v1.2.0
InSliceInt64 checks if x exists in a slice of int64s and returns TRUE if x is found.
func InSliceString ¶ added in v1.2.0
InSliceString checks if x exists in a slice of strings and returns TRUE if x is found.
func InsertSQL ¶
InsertSQL returns mysql insert sql and binds. param data expects struct, []struct, yiigo.X, []yiigo.X.
func Long2IP ¶ added in v1.3.5
Long2IP converts an long integer address into a string in (IPv4) Internet standard dotted format
func MongoSession ¶
MongoSession returns a mongo session.
func MyTimeEncoder ¶
func MyTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
MyTimeEncoder zap time encoder.
func PGInsertSQL ¶
PGInsertSQL returns postgres insert sql and binds. param data expects struct, []struct, yiigo.X, []yiigo.X.
func PGUpdateSQL ¶
PGUpdateSQL returns postgres update sql and binds. param query expects eg: "UPDATE table SET $1 WHERE id = $2". param data expects struct, yiigo.X.
func SearchInt64s ¶ added in v1.2.0
SearchInt64s searches for x in a sorted slice of ints and returns the index as specified by Search. The return value is the index to insert x if x is not present (it could be len(a)). The slice must be sorted in ascending order.
func SortInt64s ¶ added in v1.2.0
func SortInt64s(a []int64)
SortInt64s sorts a slice of int64s in increasing order.
func UniqueFloat64 ¶ added in v1.2.0
UniqueFloat64 takes an input slice of float64s and returns a new slice of float64s without duplicate values.
func UniqueInt ¶
UniqueInt takes an input slice of ints and returns a new slice of ints without duplicate values.
func UniqueInt64 ¶
UniqueInt64 takes an input slice of int64s and returns a new slice of int64s without duplicate values.
func UniqueString ¶
UniqueString takes an input slice of strings and returns a new slice of strings without duplicate values.
Types ¶
type Int64Slice ¶ added in v1.2.0
type Int64Slice []int64
Int64Slice attaches the methods of Interface to []int64, sorting a increasing order.
func (Int64Slice) Len ¶ added in v1.2.0
func (p Int64Slice) Len() int
func (Int64Slice) Less ¶ added in v1.2.0
func (p Int64Slice) Less(i, j int) bool
func (Int64Slice) Swap ¶ added in v1.2.0
func (p Int64Slice) Swap(i, j int)
type Mailer ¶
type Mailer struct { Title string Subject string From string To []string Cc []string Content string Attach []string Charset string Encoding gomail.Encoding }
Mailer email
type ReqBody ¶ added in v1.1.3
type ReqBody struct { // URL 请求地址 URL string // Host 请求头Host Host string // PostData post参数 PostData url.Values // SetCookie 请求是否需要加cookie SetCookie bool // SaveCookie 是否保存返回的cookie SaveCookie bool // ClearOldCookie 是否需要清空原来的cookie CleanOldCookie bool // Referer 请求头Referer Referer string }
ReqBody http request body
type Spider ¶
type Spider struct {
// contains filtered or unexported fields
}
Spider 爬虫基础类 包括:http、https(CA证书)、cookie处理
做爬虫时需用到另外两个库:
1、gbk 转 utf8:gopkg.in/iconv.v1 [https://github.com/qiniu/iconv] 2、页面 dom 处理:github.com/PuerkitoBio/goquery
HTTPS CA证书需用 `openssl` 转化为 `pem` 格式:cert.pem、key.pem