Documentation
¶
Overview ¶
* 通用数据模型 * author: sban * email: 9830131#qq.com * date: 2017/3/16
* 文件暂无名 * author: liyi * email: 9830131#qq.com * date: 2017/6/26
* 小程序用户自动登陆 * author: liyi * email: 9830131#qq.com * date: 2017/4/14
* author: liyi * email: 9830131#qq.com * date: 2017/3/21
Index ¶
- Constants
- Variables
- func Debug(v ...interface{})
- func Division(a, b int) int
- func HttpGet(link string, values url.Values, headers map[string]string) (result string)
- func HttpPost(link string, values url.Values, headers map[string]string) (result string)
- func ParseCookie(cookie string) ([]*http.Cookie, error)
- func ParseJson(v interface{}, s string) (err error)
- func ParseJsonToDocument(s string) (doc *gabs.Container, err error)
- func ReadTomlConfig(ref interface{}, filePath string) (err error)
- func SaveFileToLocalFromForm(ctx iris.Context, localFilePath string)
- func ToJson(v interface{}) (result string, err error)
- func ToJsonObject(v interface{}) (r interface{})
- type Config
- type DB
- type H
- type Model
- type QiniuController
- type Request
- func (this *Request) Get() (*Response, error)
- func (this *Request) Post() (*Response, error)
- func (this *Request) Send(url string, method string) (*Response, error)
- func (this *Request) SetCookies(cookies map[string]string) *Request
- func (this *Request) SetHeaders(headers map[string]string) *Request
- func (this *Request) SetMethod(method string) *Request
- func (this *Request) SetPostData(postData map[string]interface{}) *Request
- func (this *Request) SetQueries(queries map[string]string) *Request
- func (this *Request) SetUrl(url string) *Request
- type Response
- type Result
- type WeappController
- type WeappSession
- type WeappUser
- type WebEngine
- type WeixinAccessToken
Constants ¶
const ( DB_DRIVER_MYSQL = "mysql" DB_DRIVER_SQLITE3 = "sqlite3" )
Variables ¶
var Web = &WebEngine{}
Functions ¶
func ParseCookie ¶
将cookie字符串解析为*http.Cookie对象
func ParseJsonToDocument ¶
将动态的json解析为文档对象 参见:https://github.com/Jeffail/gabs 使用示例: value, ok = doc.Path("outter.inner.value1").Data().(float64) value == 10.0, ok == true value, ok = doc.Search("outter", "inner", "value1").Data().(float64) value == 10.0, ok == true value, ok = doc.Path("does.not.exist").Data().(float64) value == 0.0, ok == false exists := doc.Exists("outter", "inner", "value1") exists == true exists := doc.Exists("does", "not", "exist") exists == false
func ReadTomlConfig ¶
读取toml配置文件内容
func SaveFileToLocalFromForm ¶
从iris中读取form file,保存至本地 form中文件名称为file
Types ¶
type Config ¶
type Config struct {
Version int `toml:"version"`
Debug bool `toml:"debug"`
Addr string `toml:"addr"`
Mysql struct {
Enable bool `toml:"enable"`
DataSource string `toml:"data_source"`
} `toml:"mysql"`
Sqlite3 struct {
Enable bool `toml:"enable"`
Filepath string `toml:"filepath"`
} `toml:"sqlite3"`
Weapp struct {
Enable bool `toml:"enable"`
AppId string `toml:"app_id"`
AppSecret string `toml:"app_secret"`
} `toml:"weapp"`
Cors struct {
Enable bool `toml:"enable"`
} `toml:"cors"`
Html struct {
Enable bool `toml:"enable"`
TemplateDir string `toml:"template_dir"`
} `toml:"html"`
Static struct {
Enable bool `toml:"enable"`
StaticDir string `toml:"static_dir"`
} `toml:"static"`
Session struct {
Enable bool `toml:"enable"`
Key string `toml:"key"`
} `toml:"session"`
Qiniu struct {
Enable bool `toml:"enable"`
Scope string `toml:"scope"`
AccessKey string `toml:"access_key"`
SecretKey string `toml:"secret_key"`
Watermark string `toml:"watermark"`
ServerBase string `toml:"server_base"`
} `toml:"qiniu"`
}
type QiniuController ¶
type QiniuController struct {
Web *WebEngine
Scope string //bucket
AccessKey, SecretKey string
Watermark string //图片的水印尾缀
ServerBase string //七牛空间的基地址
// contains filtered or unexported fields
}
QINIU_IMAGE_SCALEMODE = "imageView2/2/w/360"
func (*QiniuController) Init ¶
func (this *QiniuController) Init()
func (*QiniuController) UploadImageFromForm ¶
func (this *QiniuController) UploadImageFromForm(file multipart.File) (path string)
上传文件对象至七牛
func (*QiniuController) UploadImageFromLocale ¶
func (this *QiniuController) UploadImageFromLocale(f *os.File) (path string)
从本地上传文件对象至七牛
func (*QiniuController) UploadImageFromUrl ¶
func (this *QiniuController) UploadImageFromUrl(url string, key string) string
从远程文件上传七牛云存储,key可以传空字符串
type Request ¶
type Request struct {
Raw *http.Request
Method string
Url string
Headers map[string]string
Cookies map[string]string
Queries map[string]string
PostData map[string]interface{}
// contains filtered or unexported fields
}
Request构造类
func (*Request) SetCookies ¶
设置请求cookies
func (*Request) SetHeaders ¶
设置请求头
func (*Request) SetPostData ¶
设置post请求的提交数据
func (*Request) SetQueries ¶
设置url查询参数
type Response ¶
func NewResponse ¶
func NewResponse() *Response
type WeappController ¶
type WeappController struct {
Web *WebEngine
AppId, AppSecret string
// contains filtered or unexported fields
}
func (*WeappController) ImageUrlForWeixinMediaId ¶
func (this *WeappController) ImageUrlForWeixinMediaId(mediaId string) string
以mediaId得到获取媒体文件的url
func (*WeappController) Init ¶
func (this *WeappController) Init()
type WeappSession ¶
type WeappSession struct {
SessionKey string `json:"session_key"`
ExpiresIn int `json:"expires_in"`
Openid string `json:"openid"`
}
微信json2session返回的数据结构
type WeappUser ¶
type WeappUser struct {
Model `xorm:"extends"`
OpenID string `xorm:"char(32)" json:"openId"`
UnionID string `xorm:"char(32)" json:"unionId"`
Nickname string `xorm:"char(50)" json:"nickName"`
Gender int `xorm:"tinyint" json:"gender"`
City string `xorm:"char(20)" json:"city"`
Province string `xorm:"char(20)" json:"province"`
Country string `xorm:"char(20)" json:"country"`
AvatarURL string `xorm:"tinytext" json:"avatarUrl"`
Language string `xorm:"char(10)" json:"language"`
Watermark struct {
Timestamp int64 `json:"timestamp"`
AppID string `json:"appid"`
} `xorm:"json" json:"watermark"`
}
type WebEngine ¶
type WebEngine struct {
*iris.Framework
Config Config
DB *DB
Weapp *WeappController
Qiniu *QiniuController
}
func (*WebEngine) GetWeappUser ¶
获取当前登陆的微信小程序用户
type WeixinAccessToken ¶
type WeixinAccessToken struct {
AccessToken string `json:"access_token"` // 网页授权接口调用凭证
ExpiresIn int64 `json:"expires_in"` // access_token 接口调用凭证超时时间, 单位: 秒
RefreshToken string `json:"refresh_token"` //刷新 access_token 的凭证
OpenId string `json:"openid,omitempty"`
Scope string `json:"scope,omitempty"` //用户授权的作用域, 使用逗号(,)分隔
ExpiresTime time.Time `json:"-"`
CreatedAt int64 `json:"created_at,omitempty"` //access_token 创建时间, unixtime, 分布式系统要求时间同步, 建议使用 NTP
UnionId string `json:"unionid,omitempty"`
}