1 Star 0 Fork 0

小小站长哎 / mgo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
type.go 2.59 KB
一键复制 编辑 原始数据 按行查看 历史
小小站长哎 提交于 2021-07-22 11:54 . 初次上传
package M
import (
"embed"
"net/http"
"sync"
"github.com/gorilla/websocket"
)
// http升级websocket协议的配置
var wsUpgrader = websocket.Upgrader{
// 允许所有CORS跨域请求
CheckOrigin: func(r *http.Request) bool {
return true
},
}
//web 服务全局配置 共享
type TServer struct {
Addr string //端口号
Router []Router //路由配置
public map[string]string //静态目录
static map[string]string //静态文件
embed bool //打开嵌入文件目录
efile embed.FS
SiteKey string
Root string //根目录
DBconfig
SessionConfig //session配置
Ws map[string]*wsConnection
wsMutex sync.Mutex
}
//运行时数据 独享
type S struct {
Method string //提交方式
Path string //访问url
Host string //ip
Gets map[string]string //路由参数
Get map[string]string //get参数
Post map[string]string
Req *http.Request
Res http.ResponseWriter
sessionid string
ISession
//websocket
WsCon *wsConnection //websocket
WsMsg *wsMessage
}
/**
路由结构图
Method POST GET DIR FILE
Uri 匹配网址
Func 执行函数
Domain 匹配的网址
Path 绑定路径
**/
type Router struct {
Method string
Uri string
Path string
Func func(*S)
Domain []string
}
//session配置文件
type SessionConfig struct {
Type string //缓存方式memory:内存 file 文件 redis
Name string //保存cookie的名字 默认GOSESSION
Domain string //可以设置 *.ab.com多域名共享session,默认当前域名
Maxtime int64 //缓存时间 默认24H
Path string //file 路径
Start bool //是否开启
}
//session 接口
type ISession interface {
Init(int64)
Get(string, string) string
Set(string, string, string) error
Del(string, string) error
}
//数据库配置文件
type DBconfig struct {
Type string //mysql sqlite3
DbName string //数据库名
Server string //数据库地址 //sqlite3
UserName string //用户名
UserPass string //密码
Port int //端口 默认3306
Charset string //编码 默认 utf8
Prefix string //前缀(待)
}
/**
json输出接口
**/
type H map[string]interface{}
// 客户端连接
type wsConnection struct {
Id string //独立id
wsSocket *websocket.Conn // 底层websocket
inChan chan string // 读队列
outChan chan string // 写队列
mutex sync.Mutex // 避免重复关闭管道
isClosed bool
closeChan chan byte // 关闭通知
f func(s *S) //回调函数
}
// 客户端读写消息
type wsMessage struct {
Type int //1 链接,2 消息,3 关闭
Data string
}
Go
1
https://gitee.com/yqs2009cl/mgo.git
git@gitee.com:yqs2009cl/mgo.git
yqs2009cl
mgo
mgo
master

搜索帮助