sim

package
v0.0.0-...-402caf0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2021 License: MIT Imports: 35 Imported by: 0

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

View Source
const (
	DB_DRIVER_MYSQL   = "mysql"
	DB_DRIVER_SQLITE3 = "sqlite3"
)

Variables

View Source
var Web = &WebEngine{}

Functions

func Debug

func Debug(v ...interface{})

控制台打印消息

func Division

func Division(a, b int) int

测试方法

func HttpGet

func HttpGet(link string, values url.Values, headers map[string]string) (result string)

发起一个get请求,获取字符串内容

func HttpPost

func HttpPost(link string, values url.Values, headers map[string]string) (result string)

发起一个post请求,获取字符串内容 @values params参数,可以为nil @headers 可为nil

func ParseCookie

func ParseCookie(cookie string) ([]*http.Cookie, error)

将cookie字符串解析为*http.Cookie对象

func ParseJson

func ParseJson(v interface{}, s string) (err error)

从json中反序列化对象(静态的数据结构)

func ParseJsonToDocument

func ParseJsonToDocument(s string) (doc *gabs.Container, err error)

将动态的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

func ReadTomlConfig(ref interface{}, filePath string) (err error)

读取toml配置文件内容

func SaveFileToLocalFromForm

func SaveFileToLocalFromForm(ctx iris.Context, localFilePath string)

从iris中读取form file,保存至本地 form中文件名称为file

func ToJson

func ToJson(v interface{}) (result string, err error)

json string生成

func ToJsonObject

func ToJsonObject(v interface{}) (r interface{})

将对象转为map对象,字段以小写字段显示,终端打印显示字段名

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 DB

type DB struct {
	*xorm.Engine
	DataSource, DriverName string
	ShowSql                bool
}

func (*DB) Init

func (this *DB) Init()

type H

type H map[string]interface{}

type Model

type Model struct {
	ID      int64 `xorm:"autoincr" json:"id"`
	Updated int64 `xorm:"updated" json:"updated"` //`xorm:"updated_at"`
	Created int64 `xorm:"created" json:"created"` //`xorm:"created_at" json:"created_at"`
	Deleted int64 `xorm:"deleted" json:"-"`
}

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 NewRequest

func NewRequest() *Request

返回curl类库的Request对象,使用方法见curl/readme

func (*Request) Get

func (this *Request) Get() (*Response, error)

发起get请求

func (*Request) Post

func (this *Request) Post() (*Response, error)

发起post请求

func (*Request) Send

func (this *Request) Send(url string, method string) (*Response, error)

发起请求

func (*Request) SetCookies

func (this *Request) SetCookies(cookies map[string]string) *Request

设置请求cookies

func (*Request) SetHeaders

func (this *Request) SetHeaders(headers map[string]string) *Request

设置请求头

func (*Request) SetMethod

func (this *Request) SetMethod(method string) *Request

设置请求方法

func (*Request) SetPostData

func (this *Request) SetPostData(postData map[string]interface{}) *Request

设置post请求的提交数据

func (*Request) SetQueries

func (this *Request) SetQueries(queries map[string]string) *Request

设置url查询参数

func (*Request) SetUrl

func (this *Request) SetUrl(url string) *Request

设置请求地址

type Response

type Response struct {
	Raw     *http.Response
	Headers map[string]string
	Body    string
}

func NewResponse

func NewResponse() *Response

func (*Response) IsOk

func (this *Response) IsOk() bool

type Result

type Result struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

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

func (this *WebEngine) GetWeappUser(c *iris.Context) (u WeappUser)

获取当前登陆的微信小程序用户

func (*WebEngine) Init

func (this *WebEngine) Init()

func (*WebEngine) Log

func (this *WebEngine) Log(v ...interface{})

func (*WebEngine) Start

func (this *WebEngine) Start()

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"`
}

Jump to

Keyboard shortcuts

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