您现在的位置是:网站首页> Go语言
原创Go Web框架
- Go语言
- 2024-04-21
- 1347人已阅读
原创Go Web框架
该框架的库框架支持原始库使用也就是单纯的和框架无关的库操作,只要在配置文件web.ini里,设置分布式库=false
框架初始重要函数
WebEngine.go
初始化函数
func InitJsonMode(LoadWebModes func(InitOneJsonMode func(name string, Mode interface{}), m_WebEngineData *WebEngineData))
路由处理函数
func HomePage(res http.ResponseWriter, req *http.Request)
执行路由函数
func CallJsonMode(name string, funcname, DotName string, res http.ResponseWriter, req *http.Request, m_ParameHH map[string]interface{}, ReturnType int)
返回数据函数
func ReturnCall(name string, funcname string, UserName string, center_js_uuid string, m_ReturnJson *ReturnJson, ReturnType int, res http.ResponseWriter, req *http.Request)
获得请求参数
func GetRequestParameHH(req *http.Request) map[string]interface{}
LayUI开源界面
/CoreSYS/MainMini
LayUI商业授权=false
启用即时通讯=false
访问如:
访问页面:/CoreSYS/HelloPage
ajax访问:/CoreSYS/HelloPage.ajax
配置文件/web/conf/app.ini 内容:
[WEB服务配置]
Go独立部署=false #不适用ASP.NET远程数据库
LayUI商业授权=false #是否用商业LayUI界面
启用即时通讯=true #是否启用即时通讯
IM节点名=imnode-001-0001
IM路由名=wsroute-001-0001
IM通知节点=wsnotify-001-0001
主机HOST=www.minicti.com
端口=9800
HTTPS站点=false
HTTPS证书名=5574094_www.test.com
默认模块=CoreSYS
默认函数=index
WEB节点名=web-001-0001
WEB节点地址=http://www.test.com:9800
WEB服务节点IP=102.74.17.112
WEB服务节点令牌=1223
ASP.NET服务地址=http://www.test.com
ASP.NET服务IP=1.1.1.1
ASP.NET服务令牌=55
统一认证=true
统一认证地址=http://www.center.minicti.com/WebSSO/index.aspx
中心认证KEY=5454545
中心授权KEY=99009999
数据中心模式=false #数据中心模式不是使用ASP.NET的数据库
数据中心编号=001 #数据中心的编号三位001到999
分布式库=true #是否分布式数据库
ASPNET库=true #是否ASPNET数据库
远程ASPNET库=true #是否使用远程序ASPNET数据库 配合ASPDB.exe使用
ASPNET远程库服务IP=1.1.1.1 #远程访问数据库服务地址
ASPNET远程库服务端口=1234 #远程访问数据库服务端口
ASPNET远程库服务令牌=abc123$%^ #远程库访问服务口令
ASPNET远程库连接数=10 #远程库访问连接数
库类型=MSSQL #库类型
连接IP=127.0.0.1 #库本地地址
GO库名=GoDBCenter_001 #Go的库名
ASPNET库名=DBCenter #ASPNET库名
库端口=1433 #库端口
库用户名=xn #库用户名
库密码=2222 #库密码
redis的IP=127.0.0.1
redis端口=1234
redis口令=hello
邮箱服务器=smtp.exmail.qq.com
邮箱地址=hello@qq.com
邮箱名字=GoWeb框架
邮箱账户=hello@qq.com
邮箱口令=12234
框架基础类
type OneFunction struct {
Name string //模块名
FName string //函数名
CanNoLogin bool //是否可不登陆调用
Func reflect.Value //函数实体
}
type OneMode struct {
Name string
M_FunctionMAP map[string]*OneFunction
}
type OneHome struct {
Regionno string `json:"regionno"`
Sys_orgs_nodeuuid string `json:"sys_orgs_nodeuuid"`
Orgname string `json:"orgname"`
Sys_deps_nodeuuid string `json:"sys_deps_nodeuuid"`
Depname string `json:"depname"`
Center_js_uuid string `json:"center_js_uuid"`
Jsname string `json:"jsname"`
}
type OneUserIDInRegionNO struct {
RegionNO string `json:"regionno"`
Sys_users_nodeuuid string `json:"sys_users_nodeuuid"`
Center_js_uuid string `json:"center_js_uuid"`
Jsname string `json:"jsname"`
}
type SessionLink struct {
Center_userids_uuid string `json:"center_userids_uuid"`
Sys_users_nodeuuid string `json:"sys_users_nodeuuid"`
Username string `json:"username"`
Nickname string `json:"nickname"`
Realname string `json:"realname"`
Sign string `json:"sign"`
Headpic string `json:"headpic"`
Center_js_uuid string `json:"center_js_uuid"`
Jsname string `json:"jsname"`
Lng string `json:"lng"`
Lat string `json:"lat"`
Country string `json:"country"`
Region string `json:"region"`
City string `json:"city"`
Address string `json:"address"`
Score int `json:"score"`
Lgkey string `json:"lgkey"`
M_UserIDFromRegionNOMAP map[string]*OneUserIDInRegionNO `json:"m_useridfromregionnomap"` //通过数据中心编号regionno获得用户在数据中心的sys_users_nodeuuid
M_Homes []*OneHome `json:"m_homes"` //用户归宿的企业
}
type OneFunctionMemo struct {
FullClassName string
FName string
FMemo string
FInParame string
FOutParame string
}
type ReturnJson struct {
BOK bool `json:"bOK"`
SMsg string `json:"sMsg"`
M_ReturnOBJ interface{} `json:"m_ReturnOBJ"`
}
过滤函数不暴露的函数WebEngine.go
func InitFilterJsonFunction() {
m_FilterFunctionMAP["INITJSONMODE"] = ""
...
}
func InitPageFilterJsonFunction() {
m_PageFilterFunctionMAP["RENDERVIEW"] = ""
m_PageFilterFunctionMAP["NETRETURNDATA"] = ""
m_PageFilterFunctionMAP["RUNFUNCTION"] = ""
m_PageFilterFunctionMAP["RUNSHAREFUNCTION"] = ""
m_ModeShareFilterFunctionExtMAP["___SHARE"] = ""
}
基类添加页面模板函数和页面模板例子
func (c *BaseJsonMode) InitBaseJsonMode(FullClassName string) {
if !c.BoolInitJsonMode {
c.FullClassName = FullClassName
c.BoolInitJsonMode = true
} else {
c.InsertTemplatFunc("GetEN2CNWord", c.GetEN2CNWord)
c.InsertTemplatFunc("GetCN2ENWord", c.GetCN2ENWord)
c.InsertTemplatFunc("PageHavePower", c.PageHavePower)
fmt.Println(c.FullClassName+":在基类里内执行InitBaseJsonMode", "ModeName:", c.ModeName)
}
}
func PageHavePower(Center_js_uuid, Username, sys_users_nodeuuid, IP string, FullCLassName, FunctionName string) bool {
if m_GlobalWebEngineData.M_IDB.IsGoDB() {
return true
keyString := strings.ToUpper(FullCLassName) + "-" + strings.ToUpper(FunctionName)
m_OneFunction, ok := m_AllModeFunctionMAP[keyString]
if ok {
if m_OneFunction.CanNoLogin {
return true
}
} else {
}
if Center_js_uuid == "" {
return false
}
OK, _ := M_IDB.HavePower(Center_js_uuid, Username, sys_users_nodeuuid, IP, FullCLassName, FunctionName)
return OK
} else {
longname := strings.ToUpper(FullCLassName) + "-" + strings.ToUpper(FunctionName)
m_OneFunction, ok := m_AllModeFunctionMAP[longname]
//fmt.Println("判断权限-" + longname)
if !ok {
//fmt.Println("未找到")
ok, _ := PageHaveASPPower(Username, FullCLassName, FunctionName)
return ok
} else {
if m_OneFunction.CanNoLogin {
return true
}
if Center_js_uuid == "" {
return false
}
//fmt.Println("判断权限-" + FullCLassName + "," + FunctionName)
OK, _ := M_IDB.HavePower(Center_js_uuid, Username, sys_users_nodeuuid, IP, FullCLassName, FunctionName)
return OK
}
}
}
func (c *BaseJsonMode) GetEN2CNWord(s string) string {
c.m_WordRW.RLock()
defer c.m_WordRW.RUnlock()
v, ok := c.m_WordMAP["en-cn-"+s]
if ok {
return v
}
return s
}
func (c *BaseJsonMode) GetCN2ENWord(s string) string {
c.m_WordRW.RLock()
defer c.m_WordRW.RUnlock()
v, ok := c.m_WordMAP["cn-en-"+s]
if ok {
return v
}
return s
}
渲染页面函数
func (c *BaseJsonMode) RenderView(res http.ResponseWriter, req *http.Request, UserName string, center_js_uuid, sys_users_nodeuuid, IP, viewname string, m_Data interface{}, args ...template.FuncMap) {
var err error
name := viewname + ".html"
t := template.New(name)
//注册模板函数
for _, arg := range args {
t.Funcs(arg)
}
if c.M_TemplateFuncArray != nil {
for i := 0; i < len(c.M_TemplateFuncArray); i++ {
t.Funcs(c.M_TemplateFuncArray[i])
}
}
t.Funcs(template.FuncMap{"HelloTMP": helloTMP})
t.Funcs(template.FuncMap{"HelloTMP2": helloTMP2})
//t.Funcs(template.FuncMap{"PageHavePower": c.PageHavePower})
TM := "PC"
if !c.isPCClient(req) {
TM = "Device"
}
isCN := c.IsCN(req)
FName := "web/view/" + c.ModeName + "/" + TM + "/layui/zh-CN/" + viewname + ".html"
if !isCN {
FName = "web/view/" + c.ModeName + "/" + TM + "/layui/en-us/" + viewname + ".html"
}
ok, _ := pathExists(FName)
if ok == true {
} else {
if TM == "PC" {
TM = "Device"
} else {
TM = "PC"
}
FName = "web/view/" + c.ModeName + "/" + TM + "/layui/zh-CN/" + viewname + ".html"
if !isCN {
FName = "web/view/" + c.ModeName + "/" + TM + "/layui/en-us/" + viewname + ".html"
}
}
t, err = t.ParseFiles(FName)
if err != nil {
fmt.Println(err)
} else {
m_PageData := make(map[string]interface{})
m_PageData["center_js_uuid"] = center_js_uuid
m_PageData["username"] = UserName
m_PageData["sys_users_nodeuuid"] = sys_users_nodeuuid
m_PageData["IP"] = IP
m_PageData["data"] = m_Data
res.Header().Set("Content-Type", "text/html; charset=utf-8")
err = t.Execute(res, m_PageData)
if err != nil {
fmt.Println(err)
}
}
}
模块基类中添加
func (c *CoreSYS) InitJsonMode() {
c.SetNoLoginFunction("CoreSYS", "Hello")
c.SetNoLoginFunction("CoreSYS", "Index")
c.SetNoLoginFunction("CoreSYS", "Login")
c.SetNoLoginFunction("CoreSYS", "AppLogin")
c.SetNoLoginFunction("CoreSYS", "LoginLGKey")
c.SetNoLoginFunction("CoreSYS", "Hello")
c.SetNoLoginFunction("CoreSYS", "YZCode")
c.SetNoLoginFunction("CoreSYS", "Test")
c.SetNoLoginFunction("CoreSYS", "TestSQL")
c.SetNoLoginFunction("CoreSYS", "TestManySQL")
c.SetNoLoginFunction("CoreSYS", "AuthSuperEMQ_RawJson")
c.SetNoLoginFunction("CoreSYS", "AuthEMQ_RawJson")
c.SetNoLoginFunction("CoreSYS", "AuthALCEMQ_RawJson")
c.SetNoLoginFunction("CoreSYS", "HelloCoreSYS")
c.SetNoLoginFunction("CoreSYS", "GetMapKeys")
c.SetNoLoginFunction("CoreSYS", "GetUserIDTable___Share")
c.SetNoLoginFunction("CoreSYS", "GetUserWordTable___Share")
c.SetNoLoginFunction("CoreSYS", "GetUserFriendGroupsTable___Share")
c.SetNoLoginFunction("CoreSYS", "SetLanguage")
c.SetNoLoginFunction("CoreSYS", "HelloVUE")
c.SetNoLoginFunction("CoreSYS", "HelloReact")
c.SetNoLoginFunction("CoreSYS", "HelloDB")
c.SetNoLoginFunction("CoreSYS", "HelloLayui")
c.SetNoLoginFunction("CoreSYS", "HelloPage")
c.SetNoLoginFunction("CoreSYS", "HelloASPDB")
c.SetNoLoginFunction("CoreSYS", "HelloASPNET")
c.SetNoLoginFunction("CoreSYS", "TransferASP")
c.SetNoLoginFunction("CoreSYS", "GetHttpPage")
c.SetNoLoginFunction("CoreSYS", "FromASPAction")
c.SetNoLoginFunction("CoreSYS", "P2PPage")
c.CoreSYS_API_SetNoLoginFunction()
c.InsertTemplatFunc("HelloMyPage", helloMyPage)
c.InsertTemplatFunc("HelloMyPage2", helloMyPage2)
c.InsertTemplatFunc("getMenuIcon", c.getMenuIcon)
if c.BoolInitJsonMode {
fmt.Println("在CoreSYS内执行InitJsonMode")
c.initCoreSYS()
}
//将时间戳设置成种子数
rand.Seed(time.Now().UnixNano())
c.BaseJsonMode.InitBaseJsonMode("CoreSYS")
}
func helloMyPage(a, b int) string {
return fmt.Sprintln(a*100 + b*100)
}
func helloMyPage2(a, b int) string {
return fmt.Sprintln(a*200 + b*200)
}
func (c *CoreSYS) getMenuIcon(a int) string {
if a < 0 {
nn := len(c.m_Icons)
nn = rand.Intn(nn)
return c.m_Icons[nn]
} else {
if a < len(c.m_Icons) {
fmt.Println("icon,a", c.m_Icons[a], a)
return c.m_Icons[a]
} else {
return c.m_Icons[0]
}
}
return ""
}
页面中模板函数的调用
func (c *CoreSYS) HelloPage(res http.ResponseWriter, req *http.Request, m_ParameHH map[string]interface{}) *ReturnJson {
m_SessionLink := c.GetSessionLink(res, req, m_ParameHH)
fmt.Println(m_SessionLink)
m_ReturnJson := new(ReturnJson)
m_ReturnJson.BOK = true
pagedata := make(map[string]interface{})
pagedata["aa"] = 1
pagedata["bb"] = 7
m_ReturnJson.M_ReturnOBJ = pagedata
return m_ReturnJson
}
func helloTMP2(a, b int) string {
return fmt.Sprintln(a - b)
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="/css/assets/css/admin.css">
<link rel="stylesheet" href="/css/assets/css/amazeui.css">
<link rel="stylesheet" href="/css/assets/css/app.css">
<script type="text/javascript" src="/js/main.js?a=ee2e4442223222e434"></script>
</head>
<body style="overflow: auto;">
<div style="overflow: auto;">
{{HelloTMP2 .data.aa .data.bb}}
{{if PageHavePower .center_js_uuid .username .sys_users_nodeuuid .IP "CoreSYS" "EditUser"}}
有权限调用CoreSYS/EditUser
{{else}}
无权限调用CoreSYS/EditUser
{{end}}
<br>
{{if PageHavePower .center_js_uuid .username .sys_users_nodeuuid .IP "CoreSYS.SYS" "EditUser"}}
有权限调用CoreSYS.SYS/EditUser
{{else}}
无权限CoreSYS.SYS/EditUser
{{end}}
</div>
</body>
</html>
字符串比较
{{if eq .data.nodeuuid_nodeuuid ""}}
变量是前面加$
脚本控制语句
if 配合逻辑函数判断
if eq 等于:{{if eq 参数0 参数1 参数2 … }} {{end}},
if ne 不等于:{{if ne 参数1 参数2}} {{end}}
if lt 小于:{{if lt 参数1 参数2}} {{end}}
if le 小于等于:{{if le 参数1 参数2}} {{end}}
if gt 大于:{{if gt 参数1 参数2}} {{end}}
if ge 大于等于:{{if ge 参数1 参数2}} {{end}}
if and 与:{{if and (表达式1) (表达式2) …}} {{end}},
逐个判断各表达式,遇到空返回该表达式值(false),
或返回最后表达式值(true)
表达式可以是 eq gt等判断函数,也可是变量。
if or 或:{{if or (表达式1) (表达式2) … }} {{end}},
类似and,逐个判断,返回首个非空表达式值,否则返回最后一个表达式值。
if not 非:{{if not 表达式}} {{end}},返回表达式的否定值。
以上参数、表达式都可以包含 变量 或 函数返回值,例如 {{if eq $ v_str (FUNC_ADD 0 $v_i)}}
建议:如非必要,使用简单形式 {{if eq $ i 1}} … {{end}}
循环遍历
{{range $i,$v:=.user}}
{{$i}}:{{$v}}
{{end}}
with结构
{{with . user}}
{{. name}}
{{else}}
{{/* . user 为空 */}}
{{end}}
with 赋值语句
{{with $val := "Today is : %s}}
{{printf . “2021-07-01”}}
{{end}}
printf . 中的点 等同 $val。
嵌套模板
我们平常开发Web应用的时候,经常会遇到一些模板有些部分是固定不变的,然后可以抽取出来作为一个独立的部
分,例如一个博客的头部和尾部是不变的,而唯一改变的是中间的内容部分。所以我们可以定义成
header 、 content 、 footer 三个部分。Go语言中通过如下的语法来申明
{{define " 子模板名称 "}} 内容 {{end}}
通过如下方式来调用:
{{template " 子模板名称 "}}
接下来我们演示如何使用嵌套模板,我们定义三个文件, header.tmpl 、 content.tmpl 、 footer.tmpl 文件,
里面的内容如下
//header.tmpl
{{define "header"}}
<html>
<head>
<title> 演示信息 </title>
</head>
<body>
{{end}}
//content.tmpl
{{define "content"}}
{{template "header"}}
<h1> 演示嵌套 </h1>
<ul>
<li> 嵌套使用 define 定义子模板 </li>
<li> 调用使用 template</li>
</ul>
{{template "footer"}}
{{end}}
//footer.tmpl
{{define "footer"}}
</body>
</html>
{{end}}
演示代码如下:
package main
import (
"fmt"
"os"
"text/template"
)
func main() {
s1, _ := template.ParseFiles("header.tmpl", "content.tmpl", "footer.tmpl")
s1.ExecuteTemplate(os.Stdout, "header", nil)
fmt.Println()
s1.ExecuteTemplate(os.Stdout, "content", nil)
fmt.Println()
s1.ExecuteTemplate(os.Stdout, "footer", nil)
fmt.Println()
s1.Execute(os.Stdout, nil)
}
通过上面的例子我们可以看到通过 template.ParseFiles 把所有的嵌套模板全部解析到模板里面,其实每一个定
义的{{define}}都是一个独立的模板,他们相互独立,是并行存在的关系,内部其实存储的是类似map的一种关系
(key是模板的名称,value是模板的内容),然后我们通过 ExecuteTemplate 来执行相应的子模板内容,我们可以看
到header、footer都是相对独立的,都能输出内容,contenrt中因为嵌套了header和footer的内容,就会同时输出三
个的内容。但是当我们执行 s1.Execute ,没有任何的输出,因为在默认的情况下没有默认的子模板,所以不会输出
任何的东西。
其中模块基类
type BaseJsonMode struct {
BoolInitJsonMode bool
WebNO string //web节点编号
IMNO string //IM节点编号
IMRounterNO string //IM路由编号
IMNotifyNO string //通知服务编号
MyNodeName string //本服务节点名
MyNodeUrl string //本服务节点url
MyNodeIP string //本服务IP
MyNodeMarkKey string //本服务服务节点令牌
ASPWebUrl string //ASP.NET服务地址
ASPWebIP string //ASP.NET服务IP
ASPMarkKey string //ASP.NET服务令牌
ModeName string //模块名
FullClassName string //类名
//M_DBEngine *DB.DBEngine //库连接
M_IDB IDB.IDB
BUserSSO bool //是否统一认证
SSOUrl string //统一认证地址
AuthKeyString string //中心认证Key
PostAuthKeyString string //中心授权Key
M_AllModeFunctionMAP map[string]*OneFunction //方法函数映射
M_FilterFunctionMAP map[string]string
M_FrameRedis *RedisEngine.FrameRedis
M_S2SMessage *S2SMessage.S2SMessage
M_S2STask *S2STask.S2STask
//基类函数指针
WriteLog func(string) bool
SaveCookie func(http.ResponseWriter, string, string, int)
SaveHttpOnlyCookie func(http.ResponseWriter, string, string, int)
DeleteCookie func(http.ResponseWriter, string)
ReadCookie func(*http.Request, string) (bool, string)
Redirect func(http.ResponseWriter, *http.Request, string)
GetSessionLink func(http.ResponseWriter, *http.Request, map[string]interface{}) *SessionLink
SaveSessionLink func(http.ResponseWriter, string, *SessionLink) bool
ClearSessionLink func(http.ResponseWriter, *http.Request) bool
PageHavePower func(Center_js_uuid, Username, sys_users_nodeuuid, IP string, FullCLassName, FunctionName string) bool
IsPost func(*http.Request) bool
NullString func(sql.NullString) string
NullBool func(sql.NullBool) bool
NullFloat64 func(sql.NullFloat64) float64
NullInt64 func(sql.NullInt64) int64
HavePower func(*SessionLink, string,string, string) (bool, string)
GetAddressFromIP func(IP string) (bool, string, string, string)
GetDBAddressFromJW func(bool, string, string) (bool, string, string, string, string)
GetAddressFromJWKEY func(bool, string, string, string) (bool, string, string, string, string)
SendMail func(string, string, string, string) bool
M_TemplateFuncArray []template.FuncMap
m_WordRW *sync.RWMutex
m_WordMAP map[string]string
M_AllModeFunctionMemoMAP map[string]*OneFunctionMemo
}
实用函数:
/*插入View模板函数*/
func (c *BaseJsonMode) InsertTemplatFunc(FName string, F interface{}) {
if c.M_TemplateFuncArray == nil {
c.M_TemplateFuncArray = make([]template.FuncMap, 1)
c.M_TemplateFuncArray[0] = template.FuncMap{FName: F}
} else {
c.M_TemplateFuncArray = append(c.M_TemplateFuncArray, template.FuncMap{FName: F})
}
}
/*绑定消息*/
func (c *BaseJsonMode) BindMessage(msgType string, messageFunc func(fromNode, msgType string, msgData interface{})) {
if c.M_S2SMessage != nil {
c.M_S2SMessage.BindMessage(msgType, messageFunc)
}
return
}
/*发布公有消息*/
func (c *BaseJsonMode) PostPublicMessage(msgType string, msgData interface{}) bool {
if c.M_S2SMessage != nil {
return c.M_S2SMessage.PostPublicMessage(msgType, msgData)
}
return false
}
/*发布私人消息*/
func (c *BaseJsonMode) PostPersonMessage(tonodename, msgType string, msgData interface{}) bool {
if c.M_S2SMessage != nil {
return c.M_S2SMessage.PostPersonMessage(tonodename, msgType, msgData)
}
return false
}
/*绑定任务*/
func (c *BaseJsonMode) BindWork(workType string, WorkFunc func(fromNode, workType string, workData interface{})) {
if c.M_S2STask != nil {
c.M_S2STask.BindWork(workType, WorkFunc)
}
return
}
/*添加公有任务*/
func (c *BaseJsonMode) AddOneTask(workType string, workData interface{}) bool {
if c.M_S2STask != nil {
return c.M_S2STask.AddOneTask(workType, workData)
}
return false
}
/*添加私人任务*/
func (c *BaseJsonMode) AddOnePersonTask(tonodename, workType string, workData interface{}) bool {
if c.M_S2STask != nil {
return c.M_S2STask.AddOnePersonTask(tonodename, workType, workData)
}
return false
}
/*初始化模块*/
func (c *BaseJsonMode) InitBaseJsonMode(FullClassName string) {
if !c.BoolInitJsonMode {
c.FullClassName = FullClassName
c.BoolInitJsonMode = true
} else {
/*插入视模板函数*/
c.InsertTemplatFunc("GetEN2CNWord", c.GetEN2CNWord)
c.InsertTemplatFunc("GetCN2ENWord", c.GetCN2ENWord)
c.InsertTemplatFunc("PageHavePower", c.PageHavePower)
fmt.Println(c.FullClassName+":在基类里内执行InitBaseJsonMode", "ModeName:", c.ModeName)
}
}
//添加翻译文本英文到汉字
func (c *BaseJsonMode) AddEN2CNWord(s, d string) {
c.m_WordRW.Lock()
defer c.m_WordRW.Unlock()
c.m_WordMAP["en-cn-"+s] = d
}
func (c *BaseJsonMode) AddCN2ENWord(s, d string) {
c.m_WordRW.Lock()
defer c.m_WordRW.Unlock()
c.m_WordMAP["cn-en-"+s] = d
}
func (c *BaseJsonMode) GetEN2CNWord(s string) string {
c.m_WordRW.RLock()
defer c.m_WordRW.RUnlock()
v, ok := c.m_WordMAP["en-cn-"+s]
if ok {
return v
}
return s
}
func (c *BaseJsonMode) GetCN2ENWord(s string) string {
c.m_WordRW.RLock()
defer c.m_WordRW.RUnlock()
v, ok := c.m_WordMAP["cn-en-"+s]
if ok {
return v
}
return s
}
func (c *BaseJsonMode) GetWord(req *http.Request, s string) string {
if c.IsCN(req) {
return c.GetEN2CNWord(s)
} else {
return c.GetCN2ENWord(s)
}
}
执行别的模块函数
func (c *BaseJsonMode) RunShareFunction(name, fname string, res http.ResponseWriter, req *http.Request, m_ParameHH map[string]interface{}) *ReturnJson
获得参数
func (c *BaseJsonMode) GetParameValue(m_MAP map[string]interface{}, KeyString string) (bool, string)
func (c *BaseJsonMode) GetParameValues(m_MAP map[string]interface{}, KeyStrings ...string) (bool, []string)
func (c *BaseJsonMode) GetParameRawValue(m_MAP map[string]interface{}, KeyString string) (bool, interface{})
func (c *BaseJsonMode) GetParameRawValues(m_MAP map[string]interface{}, KeyStrings ...string) (bool, []interface{})
func (c *BaseJsonMode) GetParameJsonString(m_MAP map[string]interface{}) (bool, string)
func (c *BaseJsonMode) GetParameDataString(m_MAP map[string]interface{}) (bool, string)
func (c *BaseJsonMode) GetParameDataBytes(m_MAP map[string]interface{}) (bool, []byte)
func (c *BaseJsonMode) GetParameFile(m_MAP map[string]interface{}, FileFormName string) (bool, string)
调用ASP.NET
func (c *BaseJsonMode) AdminCallASPNET(ClassFullName, FunctionName, UserName string, m_Data interface{}) *ReturnJson
func (c *BaseJsonMode) CallASPNET(ClassFullName, FunctionName string, m_SessionLink *SessionLink, m_Data interface{}) *ReturnJson
func (c *BaseJsonMode) AdminRunASPNETFunction(ClassFullName, FunctionName, UserName string, m_Data interface{}) *ReturnJson
func (c *BaseJsonMode) RunASPNETFunction(ClassFullName, FunctionName string, m_SessioLink *SessionLink, m_Data interface{}) *ReturnJson
判断是否有ASP.NET权限
func (c *BaseJsonMode) HaveASPPower(ClassName, FunctionName string, m_SessionLink *SessionLink) (bool, string)
func (c *BaseJsonMode) AdminHaveASPPower(ClassName, FunctionName, username string) (bool, string)
派生类
系统模块
type CoreSYS struct {
BaseJsonMode
...
}
func (c *CoreSYS) InitJsonMode() {
/*设置不登录访问函数*/
c.SetNoLoginFunction("CoreSYS", "Hello")
c.SetNoLoginFunction("CoreSYS", "Index")
c.SetNoLoginFunction("CoreSYS", "Login")
c.SetNoLoginFunction("CoreSYS", "AppLogin")
c.SetNoLoginFunction("CoreSYS", "LoginLGKey")
c.SetNoLoginFunction("CoreSYS", "Hello")
c.SetNoLoginFunction("CoreSYS", "YZCode")
c.SetNoLoginFunction("CoreSYS", "Test")
c.SetNoLoginFunction("CoreSYS", "TestSQL")
c.SetNoLoginFunction("CoreSYS", "TestManySQL")
c.SetNoLoginFunction("CoreSYS", "AuthSuperEMQ_RawJson")
c.SetNoLoginFunction("CoreSYS", "AuthEMQ_RawJson")
c.SetNoLoginFunction("CoreSYS", "AuthALCEMQ_RawJson")
c.SetNoLoginFunction("CoreSYS", "HelloCoreSYS")
c.SetNoLoginFunction("CoreSYS", "GetMapKeys")
c.SetNoLoginFunction("CoreSYS", "GetUserIDTable___Share")
c.SetNoLoginFunction("CoreSYS", "GetUserWordTable___Share")
c.SetNoLoginFunction("CoreSYS", "GetUserFriendGroupsTable___Share")
c.SetNoLoginFunction("CoreSYS", "SetLanguage")
c.SetNoLoginFunction("CoreSYS", "HelloVUE")
c.SetNoLoginFunction("CoreSYS", "HelloReact")
c.SetNoLoginFunction("CoreSYS", "HelloDB")
c.SetNoLoginFunction("CoreSYS", "HelloLayui")
c.SetNoLoginFunction("CoreSYS", "HelloPage")
c.SetNoLoginFunction("CoreSYS", "HelloASPDB")
c.SetNoLoginFunction("CoreSYS", "HelloASPNET")
c.SetNoLoginFunction("CoreSYS", "TransferASP")
c.SetNoLoginFunction("CoreSYS", "GetHttpPage")
c.SetNoLoginFunction("CoreSYS", "FromASPAction")
c.SetNoLoginFunction("CoreSYS", "P2PPage")
c.CoreSYS_API_SetNoLoginFunction()
/*插入视模板函数*/
c.InsertTemplatFunc("HelloMyPage", helloMyPage)
c.InsertTemplatFunc("HelloMyPage2", helloMyPage2)
c.InsertTemplatFunc("getMenuIcon", c.getMenuIcon)
if c.BoolInitJsonMode {
fmt.Println("在CoreSYS内执行InitJsonMode")
//初始化模块
c.initCoreSYS()
}
//将时间戳设置成种子数
rand.Seed(time.Now().UnixNano())
//调用基类初始化
c.BaseJsonMode.InitBaseJsonMode("CoreSYS")
}
func (c *CoreSYS) initCoreSYS() {
go c.testDB()
//函数说明
c.SetOneFunctionMemo("Login", "登陆平台", "输入参数(code:验证码|username:登陆账户|password:口令)", "返回(成功|失败)")
c.SetOneFunctionMemo("AppLogin", "手机端平台", "输入参数(username:登陆账户|password:口令|lng:经度|lat:纬度|address:地址)", "返回(成功|失败)")
c.SetOneFunctionMemo("Register", "注册账户", "输入参数(username:账户,password:口令,code:校验码)", "返回(成功|失败)")
c.SetOneFunctionMemo("SendVCode", "发送验证码", "输入参数(username:账户,email:邮箱)", "返回(成功|失败)")
c.SetOneFunctionMemo("DisableUser", "禁止账户", "输入参数(username:账户)", "返回(成功|失败)")
c.SetOneFunctionMemo("EnableUser", "启用账户", "输入参数(username:账户)", "返回(成功|失败)")
c.SetOneFunctionMemo("GetUPFileToken", "获得上传凭证", "输入参数(无)", "返回(成功token)")
c.SetOneFunctionMemo("UpFile", "上传文件", "输入参数(token:凭证|file:文件)", "返回(成功fileurl)")
c.SetOneFunctionMemo("EditUser", "编辑账户", "输入参数(username:账户|nickname:匿名|realname:正式姓名|headpic:头像|sex:性别|birthday:生日|healthno:健康卡号|healthcard:健康卡图片|ssno:身份证号|sscard:身份证照片|phoneno:电话号码|address:地址)", "返回(成功|失败)")
c.SetOneFunctionMemo("EditMyInfo", "更改个人信息", "输入参数(nickname:匿名|realname:正式姓名|headpic:头像|sex:性别|birthday:生日|healthno:健康卡号|healthcard:健康卡图片|ssno:身份证号|sscard:身份证照片|phoneno:电话号码|address:地址|sign:签名)", "返回(成功|失败)")
c.SetOneFunctionMemo("ShowAPI", "查看平台API页面", "输入参数(无)", "返回(成功|失败)")
c.SetOneFunctionMemo("GetAPI_RawJson", "查看平台API", "输入参数(limit:页面大小|page:第几页|fullclassname:全类名|funcname:函数名)", "返回(成功(code:0成功|1失败|count:记录数|data:数据) 失败)")
c.SetOneFunctionMemo("AddOneFieldType", "创建字段类型", "输入参数(fieldtype:字段类型|fieldtypeshowname:字段显示类型)", "返回(成功|失败)")
c.SetOneFunctionMemo("DeleteOneFieldType", "删除字段类型", "输入参数(sys_fieldtypes_uuid:字段类型id)", "返回(成功|失败)")
c.SetOneFunctionMemo("GetCountry", "获得国家列表", "输入参数(无)", "返回(成功|失败)")
c.SetOneFunctionMemo("GetRegion", "获得区域列表", "输入参数(cnty:国家)", "返回(成功|失败)")
c.SetOneFunctionMemo("GetCity", "获得城市列表", "输入参数(cnty:国家|prov:区域)", "返回(成功|失败)")
c.SetOneFunctionMemo("ResetPWD", "重置用户口令", "输入参数(center_userids_uuid:要重置的用户id|username:账户|oldpwd:旧口令|newpwd:新口令)", "返回(成功|失败)")
c.SetOneFunctionMemo("ResetMyPWD", "重置用户口令", "输入参数(oldpwd:旧口令|newpwd:新口令)", "返回(成功|失败)")
c.SetOneFunctionMemo("GetMyInfo", "获得我的信息", "输入参数(无)", "返回(成功|失败)")
c.SetOneFunctionMemo("GetMapKeys", "获得地图keys", "输入参数", "返回(成功|失败)")
c.SetOneFunctionMemo("IMUpImage_RawJson", "上传图片文件", "输入参数(file:文件)", "返回(成功fileurl)")
c.SetOneFunctionMemo("IMUpFile_RawJson", "上传文件", "输入参数(file:文件)", "返回(成功fileurl)")
//设置语言
c.AddCN2ENWord("登陆成功", "Login successfully")
c.AddCN2ENWord("账号只能由字符和数字组成不能包含特殊字符", "Accounts can only be composed of characters and numbers, not special characters.")
c.AddCN2ENWord("查询账户信息失败", "Failed to query account information")
c.AddCN2ENWord("该账户已经注册过,请换个账户注册", "This account has already been registered. Please register for another account.")
c.AddCN2ENWord("存储校验码失败", "Storage Check Code Failure")
c.AddCN2ENWord("亲爱的客户", "Dear Customer")
c.AddCN2ENWord("3KM验证码", "3KM verification code")
c.AddCN2ENWord("你的验证码", "Your Verification Code")
c.AddCN2ENWord("验证码已经发送", "Verification code has been sent")
c.AddCN2ENWord("发送验证码失败", "Failed to send authentication code")
c.AddCN2ENWord("参数错误", "Parameter error")
c.AddCN2ENWord("获得用户信息失败", "Failed to obtain user information")
c.AddCN2ENWord("参数有误", "Incorrect parameters")
c.AddCN2ENWord("获得验证码失败", "Failure to obtain authentication code")
c.AddCN2ENWord("请输入正确的验证码", "Please enter the correct validation code")
c.AddCN2ENWord("查询注册账号失败", "Failed to query registered account")
c.AddCN2ENWord("该账户已注册", "The account has been registered")
c.AddCN2ENWord("获得新用户落点失败", "Failed to get a new user landing point")
c.AddCN2ENWord("获得数据中心默认角色失败", "Failed to obtain default role for data center")
c.AddCN2ENWord("获得用户的好友组失败", "Failure to get user's friend group")
c.AddCN2ENWord("注册用户成功", "Registered User Success")
c.AddCN2ENWord("注册用户失败", "Registered User Failed")
c.AddCN2ENWord("缺少账户登陆信息", "The lack of account login information")
c.AddCN2ENWord("查询用户所得的id表失败", "Failed to query the ID table obtained by the user")
c.AddCN2ENWord("查询用户的数据中心id失败", "Failed to query user's data center ID")
c.AddCN2ENWord("获得用户在数据中心的用户id失败", "Failed to get user ID in data center")
c.AddCN2ENWord("更改自己信息失败", "Failed to change your information")
c.AddCN2ENWord("更改自己信息成功", "Successful Change of Your Information")
c.InitEMQ()
c.resetMapKey()
if c.M_IDB.IsGoDB() {
c.m_nameTableFromHeadMAP = make(map[string]map[string]string)
m_tableTypeDefTableMAP := make(map[string]string)
SQLString := "select tabletype,deftablename from center_nametables "
ok1, m_UTableArray := c.M_IDB.XNGetRecord(false, SQLString)
if !ok1 {
return
}
for i := 0; i < len(m_UTableArray); i++ {
tabletype := m_UTableArray[i]["tabletype"].(string)
deftablename := m_UTableArray[i]["deftablename"].(string)
m_OneMAP := make(map[string]string)
c.m_nameTableFromHeadMAP[tabletype] = m_OneMAP
m_tableTypeDefTableMAP[tabletype] = deftablename
}
SQLString = "select * from center_namerules "
ok2, m_RulesArray := c.M_IDB.XNGetRecord(false, SQLString)
if !ok2 {
for tabletype, m_OneMAP := range c.m_nameTableFromHeadMAP {
deftablename, _ := m_tableTypeDefTableMAP[tabletype]
m_OneMAP["*"] = deftablename
}
return
}
if m_RulesArray == nil {
for tabletype, m_OneMAP := range c.m_nameTableFromHeadMAP {
deftablename, _ := m_tableTypeDefTableMAP[tabletype]
m_OneMAP["*"] = deftablename
}
return
}
if len(m_RulesArray) == 0 {
for tabletype, m_OneMAP := range c.m_nameTableFromHeadMAP {
deftablename, _ := m_tableTypeDefTableMAP[tabletype]
m_OneMAP["*"] = deftablename
}
return
}
for i := 0; i < len(m_RulesArray); i++ {
head, _ := m_RulesArray[i]["namehead"].(string)
tabletype := m_RulesArray[i]["tabletype"].(string)
tablename := m_RulesArray[i]["tablename"].(string)
head = strings.ToLower(head)
if head == "*" {
m_OneMAP, ok := c.m_nameTableFromHeadMAP[tabletype]
if ok {
m_OneMAP["*"] = tablename
}
} else {
m_OneMAP, ok := c.m_nameTableFromHeadMAP[tabletype]
if ok {
m_OneMAP[head] = tablename
}
}
}
}
c.m_Icons = append(c.m_Icons, "layui-icon-home")
c.m_Icons = append(c.m_Icons, "layui-icon-camera-fill")
c.m_Icons = append(c.m_Icons, "layui-icon-praise")
c.m_Icons = append(c.m_Icons, "layui-icon-dialogue")
c.m_Icons = append(c.m_Icons, "layui-icon-layer")
c.m_Icons = append(c.m_Icons, "layui-icon-water")
c.m_Icons = append(c.m_Icons, "layui-icon-layouts")
c.m_Icons = append(c.m_Icons, "layui-icon-tree")
c.m_Icons = append(c.m_Icons, "layui-icon-chart-screen")
c.m_Icons = append(c.m_Icons, "layui-icon-print")
c.m_Icons = append(c.m_Icons, "layui-icon-rate-half")
c.m_Icons = append(c.m_Icons, "layui-icon-rate-solid")
c.m_Icons = append(c.m_Icons, "layui-icon-cellphone")
c.m_Icons = append(c.m_Icons, "layui-icon-vercode")
c.m_Icons = append(c.m_Icons, "layui-icon-username")
c.m_Icons = append(c.m_Icons, "layui-icon-snowflake")
c.m_Icons = append(c.m_Icons, "layui-icon-home")
c.m_Icons = append(c.m_Icons, "layui-icon-senior")
c.m_Icons = append(c.m_Icons, "layui-icon-flag")
c.m_Icons = append(c.m_Icons, "layui-icon-theme")
c.m_Icons = append(c.m_Icons, "layui-icon-notice")
c.m_Icons = append(c.m_Icons, "layui-icon-website")
c.m_Icons = append(c.m_Icons, "layui-icon-template-1")
c.m_Icons = append(c.m_Icons, "layui-icon-app")
c.m_Icons = append(c.m_Icons, "layui-icon-template")
c.m_Icons = append(c.m_Icons, "layui-icon-camera")
c.m_Icons = append(c.m_Icons, "layui-icon-rmb")
c.m_Icons = append(c.m_Icons, "layui-icon-dollar")
c.m_Icons = append(c.m_Icons, "layui-icon-diamond")
c.m_Icons = append(c.m_Icons, "layui-icon-fire")
c.m_Icons = append(c.m_Icons, "layui-icon-read")
c.m_Icons = append(c.m_Icons, "layui-icon-carousel")
c.m_Icons = append(c.m_Icons, "layui-icon-star")
}
//典型接口函数
func (c *CoreSYS) Login(res http.ResponseWriter, req *http.Request, m_ParameHH map[string]interface{}) *ReturnJson {
m_ReturnJson := new(ReturnJson)
fmt.Println("Login:", m_ParameHH)
if c.IsPost(req) {
//获得参数
ok, m_PArray := c.GetParameValues(m_ParameHH, "code", "username", "password")
if ok {
code := m_PArray[0]
username := strings.ToLower(m_PArray[1])
password := m_PArray[2]
ok, idkey := c.ReadCookie(req, "code")
if ok {
fmt.Println("读出idkey:", idkey)
if c.verfiyCaptcha(idkey, code) {
fmt.Println("验证通过")
//if c.M_DBEngine.IsGoDB() {
if c.M_IDB.IsGoDB() {
password = Share.GetMd5String(password)
} else {
password = Share.Sha256(password)
}
userIDTable := c.getuseridsTable(username)
center_userhomes := c.getuserhomesTable(username)
center_useridinregionno := c.getuseridinregionnoTable(username)
center_userids_uuid := ""
mysys_users_nodeuuid := ""
sys_users_nodeuuid := ""
m_SessionLink := new(SessionLink)
m_SessionLink.Address = ""
m_SessionLink.Address = ""
m_SessionLink.Country = ""
m_SessionLink.Region = ""
m_SessionLink.City = ""
ok55, m_PArray55 := c.GetParameValues(m_ParameHH, "lng", "lat")
if ok55 {
m_SessionLink.Lat = m_PArray55[1]
m_SessionLink.Lng = m_PArray55[0]
_, m_SessionLink.Country, m_SessionLink.Region, m_SessionLink.City, _ = c.GetDBAddressFromJW(c.IsCN(req), m_SessionLink.Lng, m_SessionLink.Lat)
} else {
//获得客户端ip
sIP := GetClientIP(req)
//fmt.Println("sIP:", sIP)
ok2, country, _, _ := c.GetAddressFromIP(sIP)
if ok2 {
m_SessionLink.Country = country
}
m_SessionLink.Lat = "31.22"
m_SessionLink.Lng = "121.48"
}
lgkey := ""
if c.M_IDB.IsGoDB() {
ok1, m_userIDS := c.M_IDB.XNGetRecord(false, "select * from "+userIDTable+" where username=? and password=?", m_PArray[1], password)
if !ok1 {
m_ReturnJson.BOK = false
m_ReturnJson.SMsg = "查询用户的ID失败"
return m_ReturnJson
}
if len(m_userIDS) == 0 {
m_ReturnJson.BOK = false
m_ReturnJson.SMsg = "未能查询到用户的ID"
return m_ReturnJson
}
m_SessionLink.M_Homes = make([]*OneHome, 0)
m_SessionLink.M_UserIDFromRegionNOMAP = make(map[string]*OneUserIDInRegionNO)
m_SessionLink.Sign = m_userIDS[0]["sign"].(string)
center_userids_uuid = m_userIDS[0]["center_userids_uuid"].(string)
//fmt.Println("center_userids_uuid:", center_userids_uuid)
m_SessionLink.Center_userids_uuid = center_userids_uuid
m_SessionLink.Username = m_userIDS[0]["username"].(string)
m_SessionLink.Nickname = m_userIDS[0]["nickname"].(string)
m_SessionLink.Realname = m_userIDS[0]["realname"].(string)
m_SessionLink.Center_js_uuid = m_userIDS[0]["center_js_uuid"].(string)
m_SessionLink.Jsname = m_userIDS[0]["jsname"].(string)
if m_userIDS[0]["score"].(string) == "" {
m_SessionLink.Score = 0
} else {
m_SessionLink.Score, _ = strconv.Atoi(m_userIDS[0]["score"].(string))
}
ok2, m_HomeArray := c.M_IDB.XNGetRecord(false, "select * from "+center_userhomes+" where center_userids_uuid=?", center_userids_uuid)
if ok2 {
if m_HomeArray != nil {
for i := 0; i < len(m_HomeArray); i++ {
m_OneHome := new(OneHome)
m_OneHome.Regionno = m_HomeArray[i]["regionno"].(string)
m_OneHome.Sys_orgs_nodeuuid = m_HomeArray[i]["sys_orgs_crossnodeuuid"].(string)
m_OneHome.Orgname = m_HomeArray[i]["orgname"].(string)
m_OneHome.Sys_deps_nodeuuid = m_HomeArray[i]["sys_deps_crossnodeuuid"].(string)
m_OneHome.Depname = m_HomeArray[i]["depname"].(string)
m_OneHome.Center_js_uuid = m_HomeArray[i]["center_js_uuid"].(string)
m_OneHome.Jsname = m_HomeArray[i]["jsname"].(string)
m_SessionLink.M_Homes = append(m_SessionLink.M_Homes, m_OneHome)
}
}
}
ok3, m_RegionUserIDArray := c.M_IDB.XNGetRecord(false, "select * from "+center_useridinregionno+" where center_userids_uuid=?", center_userids_uuid)
//fmt.Println("center_useridinregionno:", center_useridinregionno, ",center_userids_uuid:", center_userids_uuid)
if ok3 {
if m_RegionUserIDArray != nil {
for i := 0; i < len(m_RegionUserIDArray); i++ {
m_OneUserIDInRegionNO := new(OneUserIDInRegionNO)
regionno := m_RegionUserIDArray[i]["regionno"].(string)
sys_users_nodeuuid := m_RegionUserIDArray[i]["sys_users_crossnodeuuid"].(string)
center_js_uuid := m_RegionUserIDArray[i]["center_js_uuid"].(string)
janame := m_RegionUserIDArray[i]["jsname"].(string)
m_OneUserIDInRegionNO.RegionNO = regionno
m_OneUserIDInRegionNO.Sys_users_nodeuuid = sys_users_nodeuuid
m_OneUserIDInRegionNO.Center_js_uuid = center_js_uuid
m_OneUserIDInRegionNO.Jsname = janame
m_SessionLink.M_UserIDFromRegionNOMAP[regionno] = m_OneUserIDInRegionNO
//fmt.Println("regionno:", regionno, ",c.M_IDB.GetRegionNO:", c.M_IDB.GetRegionNO())
if regionno == c.M_IDB.GetRegionNO() {
mysys_users_nodeuuid = sys_users_nodeuuid
m_SessionLink.Sys_users_nodeuuid = mysys_users_nodeuuid
//fmt.Println("mysys_users_nodeuuid:", mysys_users_nodeuuid)
}
}
}
}
lgkey = Share.GetUuid() + "(" + userIDTable + ")" + c.M_IDB.GetBaseDBNOFromUUid(mysys_users_nodeuuid)
m_ManySQLArgs := new(DB.ManySQLArgs)
nowString := c.M_IDB.GetDBNowDateString()
m_ManySQLArgs.AddOneSQL("update sys_users set lgkey_uuid=?,lgkeytime=? where sys_users_nodeuuid=?", lgkey, nowString, mysys_users_nodeuuid)
m_ManySQLArgs.AddOneSQL("update "+userIDTable+" set lgkey_uuid=?,lgtime=?,lgcountry=?,lgregion=?,lgcity=?,lgsys_users_crossnodeuuid=?,lglng=?,lglat=?,lgaddress=? where center_userids_uuid=?", lgkey, nowString, m_SessionLink.Country, m_SessionLink.Region, m_SessionLink.City, m_SessionLink.Sys_users_nodeuuid, m_SessionLink.Lng, m_SessionLink.Lat, m_SessionLink.Address, center_userids_uuid)
fmt.Println("userIDTable:", userIDTable, ",center_userids_uuid:", center_userids_uuid, ",lgkey_uuid:", lgkey, ",lgcountry:", m_SessionLink.Country, ",lgregion:", m_SessionLink.Region, ",lgcity:", m_SessionLink.City, ",lgsys_users_crossnodeuuid:", m_SessionLink.Sys_users_nodeuuid)
ok = c.M_IDB.XNActManySQLArgs(m_ManySQLArgs)
if !ok {
m_ReturnJson.BOK = false
m_ReturnJson.SMsg = "设置登陆KEY失败"
return m_ReturnJson
}
} else {
ok1, m_userIDS := c.M_IDB.XNGetRecord(false, "select sys_users_nodeuuid from "+userIDTable+" where username=?", m_PArray[1])
if !ok1 {
m_ReturnJson.BOK = false
m_ReturnJson.SMsg = "查询用户的ID失败"
return m_ReturnJson
}
if len(m_userIDS) == 0 {
m_ReturnJson.BOK = false
m_ReturnJson.SMsg = "未能查询到用户的ID"
return m_ReturnJson
}
sys_users_nodeuuid = m_userIDS[0]["sys_users_nodeuuid"].(string)
fmt.Println("sys_users_nodeuuid:", sys_users_nodeuuid)
//m_RecordReturn := c.M_DBEngine.Select(&m_UserArray, "select * from sys_users where sys_users_nodeuuid=? and password=? order by sys_users_nodeuuid", 999999999, 1, "", sys_users_nodeuuid, password)
//ok1, m_userArray := c.M_IDB.XNGetRecord(false, "select cast(sys_users_nodeuuid as nvarchar) as sys_users_nodeuuid ,cast(sys_companys_nodeuuid as nvarchar) as sys_companys_nodeuuid,cast(sys_companyorgs_nodeuuid as nvarchar) as sys_companyorgs_nodeuuid,cast(sys_js_uuid as nvarchar) as sys_js_uuid,username,realname from sys_users where sys_users_nodeuuid=? and password=? order by sys_users_nodeuuid", sys_users_nodeuuid, password)
ok1, m_userArray := c.M_IDB.XNGetRecord(false, "select sys_users_nodeuuid , sys_companys_nodeuuid, sys_companyorgs_nodeuuid, sys_js_uuid,username,realname from sys_users where sys_users_nodeuuid=? and password=? order by sys_users_nodeuuid", sys_users_nodeuuid, password)
if !ok1 {
m_ReturnJson.BOK = false
m_ReturnJson.SMsg = "查询账户信息出错1"
return m_ReturnJson
}
if m_userArray == nil {
m_ReturnJson.BOK = false
m_ReturnJson.SMsg = "查询账户信息出错2"
return m_ReturnJson
}
if len(m_userArray) == 0 {
m_ReturnJson.BOK = false
m_ReturnJson.SMsg = "未能查询到账户信息"
return m_ReturnJson
}
sys_users_nodeuuid = m_userArray[0]["sys_users_nodeuuid"].(string)
if sys_users_nodeuuid == "" {
m_ReturnJson.BOK = false
m_ReturnJson.SMsg = "登陆失败请核实账户名或口令再登陆"
return m_ReturnJson
}
m_SessionLink.Sys_users_nodeuuid = sys_users_nodeuuid
m_SessionLink.Username = m_userArray[0]["username"].(string)
m_SessionLink.Realname = m_userArray[0]["realname"].(string)
Sys_orgs_nodeuuid := m_userArray[0]["sys_companys_nodeuuid"].(string)
Sys_deps_nodeuuid := m_userArray[0]["sys_companyorgs_nodeuuid"].(string)
m_SessionLink.Center_js_uuid = m_userArray[0]["sys_js_uuid"].(string)
ok2, m_OrgsArray := c.M_IDB.XNGetRecord(false, "select a.company,b.companyorg_name from sys_companys a,sys_companyorgs b where a.sys_companys_nodeuuid=b.sys_companys_nodeuuid and b.sys_companyorgs_nodeuuid=? ", Sys_deps_nodeuuid)
if !ok2 {
m_ReturnJson.BOK = false
m_ReturnJson.SMsg = "查询用户的企业部门信息失败"
return m_ReturnJson
}
if m_OrgsArray == nil {
m_ReturnJson.BOK = false
m_ReturnJson.SMsg = "未能查询用户的企业部门信息"
return m_ReturnJson
}
if len(m_OrgsArray) == 0 {
m_ReturnJson.BOK = false
m_ReturnJson.SMsg = "未能查询用户的企业部门信息"
return m_ReturnJson
}
Depname := m_OrgsArray[0]["companyorg_name"].(string)
Orgname := m_OrgsArray[0]["company"].(string)
ok3, m_JSArray := c.M_IDB.XNGetRecord(false, "select jsname from sys_js where sys_js_uuid=?", m_SessionLink.Center_js_uuid)
if !ok3 {
m_ReturnJson.BOK = false
m_ReturnJson.SMsg = "查询角色信息失败"
return m_ReturnJson
}
if m_JSArray == nil {
m_ReturnJson.BOK = false
m_ReturnJson.SMsg = "未能查询到角色信息"
return m_ReturnJson
}
if len(m_JSArray) == 0 {
m_ReturnJson.BOK = false
m_ReturnJson.SMsg = "未能查询到角色信息"
return m_ReturnJson
}
m_SessionLink.Jsname = m_JSArray[0]["jsname"].(string)
m_SessionLink.M_Homes = make([]*OneHome, 0)
m_OneHome := new(OneHome)
m_OneHome.Center_js_uuid = m_SessionLink.Center_js_uuid
m_OneHome.Depname = Depname
m_OneHome.Jsname = m_SessionLink.Jsname
m_OneHome.Orgname = Orgname
m_OneHome.Regionno = c.M_IDB.GetRegionNO()
m_OneHome.Sys_deps_nodeuuid = Sys_deps_nodeuuid
m_OneHome.Sys_orgs_nodeuuid = Sys_orgs_nodeuuid
m_SessionLink.M_Homes = append(m_SessionLink.M_Homes, m_OneHome)
m_SessionLink.M_UserIDFromRegionNOMAP = make(map[string]*OneUserIDInRegionNO)
m_OneUserIDInRegionNO := new(OneUserIDInRegionNO)
m_OneUserIDInRegionNO.Center_js_uuid = m_SessionLink.Center_js_uuid
m_OneUserIDInRegionNO.Jsname = m_SessionLink.Jsname
m_OneUserIDInRegionNO.RegionNO = c.M_IDB.GetRegionNO()
m_OneUserIDInRegionNO.Sys_users_nodeuuid = sys_users_nodeuuid
m_SessionLink.Sys_users_nodeuuid = sys_users_nodeuuid
m_SessionLink.M_UserIDFromRegionNOMAP[m_OneUserIDInRegionNO.RegionNO] = m_OneUserIDInRegionNO
lgkey = Share.GetUuid() + c.M_IDB.GetBaseDBNOFromUUid(sys_users_nodeuuid)
//ok, _ = c.M_DBEngine.XNActSQL("update sys_users set lgkey_uuid=? ,lgkeytime=? where sys_users_nodeuuid=?", lgkey, c.M_DBEngine.GetDBNowDateString(), sys_users_nodeuuid)
ok, _ = c.M_IDB.XNActSQL("update sys_users set lgkey_uuid=? ,lgkeytime=? where sys_users_nodeuuid=?", lgkey, c.M_IDB.GetDBNowDateString(), sys_users_nodeuuid)
if !ok {
m_ReturnJson.BOK = false
m_ReturnJson.SMsg = "更改登陆key失败"
return m_ReturnJson
}
}
if !c.SaveSessionLink(res, lgkey, m_SessionLink) {
m_ReturnJson.BOK = false
m_ReturnJson.SMsg = "保存登陆状态失败"
return m_ReturnJson
}
m_ReturnJson.BOK = true
m_ReturnJson.SMsg = "登陆成功"
} else {
fmt.Println("验证失败")
m_ReturnJson.BOK = false
m_ReturnJson.SMsg = "验证失败"
}
} else {
fmt.Println("读取cookie失败")
m_ReturnJson.BOK = false
m_ReturnJson.SMsg = "读取cookie失败"
}
} else {
fmt.Println("获得验证码参数失败")
m_ReturnJson.BOK = false
m_ReturnJson.SMsg = "获得验证码参数失败"
}
} else {
m_SessionLink := c.GetSessionLink(res, req, m_ParameHH)
if m_SessionLink != nil {
c.Redirect(res, req, "/CoreSYS/index")
return nil
}
fmt.Println("CoreSYS 动态调用成功")
//c.ListFunction()
m_HelloST := new(HelloST)
m_HelloST.Name = "徐能"
m_ReturnJson.BOK = true
m_ReturnJson.M_ReturnOBJ = m_HelloST
}
return m_ReturnJson
}
模块调用数据库访问函数,通过IDB接口访问
c.M_IDB.
接口定义:
type IDB interface {
//基础BaseDB类的接口函数开始
WriteDBLog(Msg string) bool
XNGetRecord(rawData bool, SQLString string, args ...interface{}) (bool, []map[string]interface{})
XNGetPageRecord(rawData bool, SQLString string, nPageSize, nCurPage int, sSumField string, args ...interface{}) *DB.RecordReturn
Select(dest interface{}, SQLString string, nPageSize, nCurPage int, sSumField string, args ...interface{}) *DB.RecordReturn
XNActSQL(SQLString string, args ...interface{}) (bool, int64)
XNActManySQL(SQLStringArray []string, argsArray [][]interface{}) bool
XNActManySQLArgs(m_ManySQLArgs *DB.ManySQLArgs) bool
//基础类BaseDB的接口函数结束
//扩展基础支持节点类DBEngine的接口函数开始
InitNodeDB() bool
IsGoDB() bool
CreateNodeUUid(nodeuuid string) string
GetBaseDBNOFromUUid(nodeuuid string) string
GetDBNowDateString() string
GetBaseDBFromDBNO(dbno string) *DB.BaseDB
//扩展基础支持节点类DBEngine的接口函数结束
//数据中心接口
IsRegionDB() bool
XNAllRegionDBSQL(SQLString string, args ...interface{}) int
//指定数据节点执行
DBNOXNGetRecord(dbno string, rawData bool, SQLString string, args ...interface{}) (bool, []map[string]interface{})
DBNOXNGetPageRecord(dbno string, rawData bool, SQLString string, nPageSize, nCurPage int, sSumField string, args ...interface{}) *DB.RecordReturn
DBNOSelect(dbno string, dest interface{}, SQLString string, nPageSize, nCurPage int, sSumField string, args ...interface{}) *DB.RecordReturn
DBNOXNActSQL(dbno, SQLString string, args ...interface{}) (bool, int64)
DBNOXNActManySQL(dbno string, SQLStringArray []string, argsArray [][]interface{}) bool
DBNOXNActManySQLArgs(dbno string, m_ManySQLArgs *DB.ManySQLArgs) bool
//中心获得数据
CenterXNGetRecord(rawData bool, SQLString string, args ...interface{}) (bool, []map[string]interface{})
CenterXNGetPageRecord(rawData bool, SQLString string, nPageSize, nCurPage int, sSumField string, args ...interface{}) *DB.RecordReturn
CenterSelect(dest interface{}, SQLString string, nPageSize, nCurPage int, sSumField string, args ...interface{}) *DB.RecordReturn
//共享节点执行
ShareDBXNGetRecord(rawData bool, SQLString string, args ...interface{}) (bool, []map[string]interface{})
ShareDBXNGetPageRecord(rawData bool, SQLString string, nPageSize, nCurPage int, sSumField string, args ...interface{}) *DB.RecordReturn
ShareDBSelect(dest interface{}, SQLString string, nPageSize, nCurPage int, sSumField string, args ...interface{}) *DB.RecordReturn
ShareDBXNActSQL(SQLString string, args ...interface{}) bool
ShareDBXNActManySQL(SQLStringArray []string, argsArray [][]interface{}) bool
ShareDBXNActManySQLArgs(m_ManySQLArgs *DB.ManySQLArgs) bool
HavePower(center_js_uuid, FullClassName, FunctioName string) (bool, string)
//区域查询数据
UserRangeXNGetPageRecord(m_UserRange *DB.UserRange, rawData bool, SQLString string, nPageSize, nCurPage int, sSumField string, args ...interface{}) *DB.RecordReturn
UserRangeXNGetRecord(m_UserRange *DB.UserRange, rawData bool, SQLString string, args ...interface{}) (bool, []map[string]interface{})
UserRangeSelect(m_UserRange *DB.UserRange, dest interface{}, SQLString string, nPageSize, nCurPage int, sSumField string, args ...interface{}) *DB.RecordReturn
IsCenterPersonDataTable(tablename string) bool
SetDBFrameRedis(m_FrameRedis *RedisEngine.FrameRedis)
CacheXNGetRecord(rawData bool, SQLString string, args ...interface{}) (bool, []map[string]interface{})
CacheXNGetPageRecord(rawData bool, SQLString string, nPageSize, nCurPage int, sSumField string, args ...interface{}) *DB.RecordReturn
CacheSelect(dest interface{}, SQLString string, nPageSize, nCurPage int, sSumField string, args ...interface{}) *DB.RecordReturn
CacheDBNOXNGetRecord(dbno string, rawData bool, SQLString string, args ...interface{}) (bool, []map[string]interface{})
CacheDBNOXNGetPageRecord(dbno string, rawData bool, SQLString string, nPageSize, nCurPage int, sSumField string, args ...interface{}) *DB.RecordReturn
CacheDBNOSelect(dbno string, dest interface{}, SQLString string, nPageSize, nCurPage int, sSumField string, args ...interface{}) *DB.RecordReturn
CacheShareDBXNGetRecord(rawData bool, SQLString string, args ...interface{}) (bool, []map[string]interface{})
CacheShareDBXNGetPageRecord(rawData bool, SQLString string, nPageSize, nCurPage int, sSumField string, args ...interface{}) *DB.RecordReturn
CacheShareDBSelect(dest interface{}, SQLString string, nPageSize, nCurPage int, sSumField string, args ...interface{}) *DB.RecordReturn
CacheUserRangeXNGetPageRecord(m_UserRange *DB.UserRange, rawData bool, SQLString string, nPageSize, nCurPage int, sSumField string, args ...interface{}) *DB.RecordReturn
CacheUserRangeXNGetRecord(m_UserRange *DB.UserRange, rawData bool, SQLString string, args ...interface{}) (bool, []map[string]interface{})
CacheUserRangeSelect(m_UserRange *DB.UserRange, dest interface{}, SQLString string, nPageSize, nCurPage int, sSumField string, args ...interface{}) *DB.RecordReturn
GetRegionNO() string
CreateUuid() string
GetNewUserRangeDBNO(m_UserRange *DB.UserRange) (bool, string)
GetNewUserRangeDB(m_UserRange *DB.UserRange) *DB.BaseDB
CreateNodeUUidFromDBNO(dbno string) string
GetDBType() string
}
添加模块注意事项
在函数内添加
func LoadWebModes(InitOneJsonMode func(name string, Mode interface{}), m_WebEngineData *WebEngineData) {
...
m_CoreSYS := new(CoreSYS)
m_CoreSYS.ModeName = "CoreSYS"
InitOneJsonMode("CoreSYS", m_CoreSYS)
m_CoreSYS.SetWebEngineData(m_WebEngineData)
m_CoreSYS.InitJsonMode()
...
}
Go访问远程ASP.NET数据库
ASP.NET远程数据库服务DBServiceApp
配置文件:
[DB中心节点服务配置]
DB数据服务中心编号=000
DB节点服务端IP=110.74.17.102
DB节点服务端口=1234
数据中心模式=false
分布式库=true
ASPNET库=true
库类型=MSSQL
连接IP=127.0.0.1
GO库名=GoDBCenter_002
ASPNET库名=DBCenter
库端口=1433
库用户名=hello
库密码=123
web端的配置文件:
数据中心模式=false
数据中心编号=001
分布式库=true
ASPNET库=true
远程ASPNET库=true
ASPNET远程库服务IP=112.74.17.122
ASPNET远程库服务端口=1234
ASPNET远程库服务令牌=abc123$%^
ASPNET远程库连接数=10
ASPNET远程库服务令牌这个在DBCenter库表里,由ASP.NET远程数据库服务DBServiceApp查询,语句为
select token from center_regiondbsrvs where dbsrvip=? and dbsrvport=? and isuse=1
CREATE TABLE [dbo].[center_regiondbsrvs](
[center_regiondbsrvs] [nvarchar](60) NOT NULL,
[regionno] [nvarchar](50) NULL,
[dbsrvip] [nvarchar](50) NULL,
[dbsrvport] [nvarchar](50) NULL,
[isuse] [bit] NULL,
[weight] [int] NULL,
[token] [nvarchar](50) NULL,
[createtime] [datetime] NULL,
CONSTRAINT [PK_center_regiondbs] PRIMARY KEY CLUSTERED
(
[center_regiondbsrvs] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
center_regiondbsrvs regionno dbsrvip dbsrvport isuse weight token createtime
1111 000 112.74.17.122 1234 1 32 abc123$%^ NULL
if m_DBEngine.isRemoteASPNETDB {
SQLArray := make([]string, 0)
ArgsArrayT := make([][]interface{}, 0)
SQLArray = append(SQLArray, SQLString)
ArgsArrayT = append(ArgsArrayT, args)
bOK := m_DBEngine.XNActRemoteManySQL(SQLArray, ArgsArrayT)
return bOK, 0
}
func (m_DBEngine *DBEngine) XNActRemoteManySQL(SQLStringArray []string, argsArrayT [][]interface{}) bool {
if !m_DBEngine.isRemoteASPNETDB {
return false
}
var m_OneRemoteASPNETDBLink *OneRemoteASPNETDBLink = nil
if m_DBEngine.m_ASPNETDBSrv == nil {
return false
}
m_OneRemoteASPNETDBLink = <-m_DBEngine.m_ASPNETDBSrv.m_RemoteASPNETDBLinkCHAN
if m_OneRemoteASPNETDBLink != nil {
if !m_OneRemoteASPNETDBLink.LinkOK {
nRCnt := 0
for {
client, err := rpc.DialHTTP("tcp", m_OneRemoteASPNETDBLink.SrvIP+":"+m_OneRemoteASPNETDBLink.Port)
if err != nil {
if nRCnt > m_DBEngine.nMaxAtmp {
return false
} else {
nRCnt += 1
runtime.Gosched() //设防cpu其他用
}
} else {
m_OneRemoteASPNETDBLink.LinkOK = true
m_OneRemoteASPNETDBLink.Client = client
var m_in XNActManySQL_in
var m_out XNActManySQL_out
m_in.Token = m_OneRemoteASPNETDBLink.Token
m_in.SQLStringArray = make([]string, len(SQLStringArray))
m_in.ArgsArrayT = make([][]interface{}, len(SQLStringArray))
for m := 0; m < len(SQLStringArray); m++ {
m_in.SQLStringArray[m] = SQLStringArray[m]
m_in.ArgsArrayT[m] = make([]interface{}, len(argsArrayT[m]))
for n := 0; n < len(argsArrayT[m]); n++ {
m_in.ArgsArrayT[m][n] = argsArrayT[m][n]
}
}
err = client.Call("RpcDB.XNActManySQL", &m_in, &m_out)
if err != nil {
if strings.Index(err.Error(), "shut down") != -1 {
m_OneRemoteASPNETDBLink.LinkOK = false
}
m_DBEngine.m_ASPNETDBSrv.m_RemoteASPNETDBLinkCHAN <- m_OneRemoteASPNETDBLink
return false
} else {
m_DBEngine.m_ASPNETDBSrv.m_RemoteASPNETDBLinkCHAN <- m_OneRemoteASPNETDBLink
return m_out.BOK
}
}
}
} else {
var m_in XNActManySQL_in
var m_out XNActManySQL_out
m_in.Token = m_OneRemoteASPNETDBLink.Token
m_in.SQLStringArray = make([]string, len(SQLStringArray))
m_in.ArgsArrayT = make([][]interface{}, len(SQLStringArray))
for m := 0; m < len(SQLStringArray); m++ {
m_in.SQLStringArray[m] = SQLStringArray[m]
m_in.ArgsArrayT[m] = make([]interface{}, len(argsArrayT[m]))
for n := 0; n < len(argsArrayT[m]); n++ {
m_in.ArgsArrayT[m][n] = argsArrayT[m][n]
}
}
bHaveCall := false
for {
err := m_OneRemoteASPNETDBLink.Client.Call("RpcDB.XNActManySQL", &m_in, &m_out)
if err != nil {
if bHaveCall {
return false
}
bHaveCall = true
if strings.Index(err.Error(), "shut down") != -1 {
m_OneRemoteASPNETDBLink.LinkOK = false
nRCnt := 0
for {
client, err := rpc.DialHTTP("tcp", m_OneRemoteASPNETDBLink.SrvIP+":"+m_OneRemoteASPNETDBLink.Port)
if err != nil {
if nRCnt > m_DBEngine.nMaxAtmp {
return false
} else {
nRCnt += 1
runtime.Gosched() //设防cpu其他用
}
} else {
m_OneRemoteASPNETDBLink.LinkOK = true
m_OneRemoteASPNETDBLink.Client = client
break
}
}
} else {
m_DBEngine.m_ASPNETDBSrv.m_RemoteASPNETDBLinkCHAN <- m_OneRemoteASPNETDBLink
return false
}
} else {
m_DBEngine.m_ASPNETDBSrv.m_RemoteASPNETDBLinkCHAN <- m_OneRemoteASPNETDBLink
return m_out.BOK
}
}
}
} else {
return false
}
return false
}
if m_DBEngine.isRemoteASPNETDB {
var m_OneRemoteASPNETDBLink *OneRemoteASPNETDBLink = nil
fmt.Println("获得远程连接")
m_OneRemoteASPNETDBLink = <-m_DBEngine.m_ASPNETDBSrv.m_RemoteASPNETDBLinkCHAN
fmt.Println(m_OneRemoteASPNETDBLink)
if m_OneRemoteASPNETDBLink != nil {
if !m_OneRemoteASPNETDBLink.LinkOK {
nRCnt := 0
for {
client, err := rpc.DialHTTP("tcp", m_OneRemoteASPNETDBLink.SrvIP+":"+m_OneRemoteASPNETDBLink.Port)
if err != nil {
if nRCnt > m_DBEngine.nMaxAtmp {
return false, nil
} else {
nRCnt += 1
runtime.Gosched() //设防cpu其他用
}
} else {
m_OneRemoteASPNETDBLink.LinkOK = true
m_OneRemoteASPNETDBLink.Client = client
var m_in XNGetRecord_in
var m_out XNGetRecord_out
m_in.Token = m_OneRemoteASPNETDBLink.Token
m_in.RawData = rawData
m_in.SQLString = SQLString
m_in.Args = make([]interface{}, 0)
for _, arg := range args {
m_in.Args = append(m_in.Args, arg)
}
err = client.Call("RpcDB.XNGetRecord", &m_in, &m_out)
if err != nil {
if strings.Index(err.Error(), "shut down") != -1 {
m_OneRemoteASPNETDBLink.LinkOK = false
}
m_DBEngine.m_ASPNETDBSrv.m_RemoteASPNETDBLinkCHAN <- m_OneRemoteASPNETDBLink
return false, nil
} else {
m_DBEngine.m_ASPNETDBSrv.m_RemoteASPNETDBLinkCHAN <- m_OneRemoteASPNETDBLink
return m_out.BOK, m_out.Rows
}
}
}
} else {
var m_in XNGetRecord_in
var m_out XNGetRecord_out
m_in.Token = m_OneRemoteASPNETDBLink.Token
m_in.RawData = rawData
m_in.SQLString = SQLString
m_in.Args = make([]interface{}, 0)
for _, arg := range args {
m_in.Args = append(m_in.Args, arg)
}
bHaveCall := false
for {
err := m_OneRemoteASPNETDBLink.Client.Call("RpcDB.XNGetRecord", &m_in, &m_out)
if err != nil {
if bHaveCall {
return false, nil
}
bHaveCall = true
if strings.Index(err.Error(), "shut down") != -1 {
m_OneRemoteASPNETDBLink.LinkOK = false
nRCnt := 0
for {
client, err := rpc.DialHTTP("tcp", m_OneRemoteASPNETDBLink.SrvIP+":"+m_OneRemoteASPNETDBLink.Port)
if err != nil {
if nRCnt > m_DBEngine.nMaxAtmp {
return false, nil
} else {
nRCnt += 1
runtime.Gosched() //设防cpu其他用
}
} else {
m_OneRemoteASPNETDBLink.LinkOK = true
m_OneRemoteASPNETDBLink.Client = client
break
}
}
} else {
m_DBEngine.m_ASPNETDBSrv.m_RemoteASPNETDBLinkCHAN <- m_OneRemoteASPNETDBLink
return false, nil
}
} else {
m_DBEngine.m_ASPNETDBSrv.m_RemoteASPNETDBLinkCHAN <- m_OneRemoteASPNETDBLink
return m_out.BOK, m_out.Rows
}
}
}
} else {
return false, nil
}
}
角色相关表
CREATE TABLE [dbo].[center_js](
[center_js_uuid] [nvarchar](60) NOT NULL,
[center_parentjs_uuid] [nvarchar](60) NULL,
[jsname] [nvarchar](50) NULL,
[createtime] [nvarchar](50) NULL,
CONSTRAINT [PK_center_js] PRIMARY KEY CLUSTERED
(
[center_js_uuid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
CREATE TABLE [dbo].[center_jsbusiness](
[center_jsbusiness_uuid] [nvarchar](60) NOT NULL,
[center_js_uuid] [nvarchar](60) NULL,
[center_business_uuid] [nvarchar](60) NULL,
[fullclassname] [nvarchar](50) NULL,
[createtime] [datetime] NULL,
CONSTRAINT [PK_center_jsbusiness] PRIMARY KEY CLUSTERED
(
[center_jsbusiness_uuid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
CREATE TABLE [dbo].[center_jsdisfuncs](
[center_jsdisfuncs_uuid] [nvarchar](60) NOT NULL,
[center_jsbusiness_uuid] [nvarchar](60) NULL,
[funcname] [nvarchar](50) NULL,
[fullclassname] [nvarchar](50) NULL,
[center_js_uuid] [nvarchar](60) NULL,
[isparent] [bit] NULL,
[createtime] [datetime] NULL,
CONSTRAINT [PK_center_jsdisfuncs] PRIMARY KEY CLUSTERED
(
[center_jsdisfuncs_uuid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
CREATE TABLE [dbo].[center_jsmaxrun](
[center_jsmaxrun_uuid] [nvarchar](60) NOT NULL,
[center_jsbusiness_uuid] [nvarchar](60) NULL,
[funcname] [nvarchar](50) NULL,
[fullclassname] [nvarchar](50) NULL,
[center_js_uuid] [nvarchar](60) NULL,
[maxrun] [int] NULL,
[runtype] [nvarchar](50) NULL,
[isparent] [bit] NULL,
[createtime] [datetime] NULL,
CONSTRAINT [PK_center_jsmaxrun] PRIMARY KEY CLUSTERED
(
[center_jsmaxrun_uuid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
CREATE TABLE [dbo].[center_jstimelimits](
[center_jstimelimits_uuid] [nvarchar](60) NOT NULL,
[center_jsbusiness_uuid] [nvarchar](60) NULL,
[funcname] [nvarchar](50) NULL,
[fullclassname] [nvarchar](50) NULL,
[center_js_uuid] [nvarchar](60) NULL,
[isday] [bit] NULL,
[starttime] [datetime] NULL,
[endtime] [datetime] NULL,
[days] [int] NULL,
[isparent] [bit] NULL,
[createtime] [datetime] NULL,
CONSTRAINT [PK_center_jstimelimits] PRIMARY KEY CLUSTERED
(
[center_jstimelimits_uuid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
获得请求参数包括文件
<form class="layui-form" action="/AD/AD" id="newDlg" style="display:none" style="padding-top:10px;" enctype ="multipart/form-data">
<input type="hidden" name="ad_datas_nodeuuid" id="ad_datas_nodeuuid">
<input type="hidden" name="acttype" id="acttype">
<div class="layui-form-item" style="margin-top:20px;">
<label class="layui-form-label">广告名</label>
<div class="layui-input-block" style="margin-right:20px">
<input type="text" name="adname" id="adname" required lay-verify="required" placeholder="请输入广告名" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">广告说明</label>
<div class="layui-input-block" style="margin-right:20px">
<textarea type="text" placeholder="请输入内容" class="layui-textarea" name="admemo" id="admemo"></textarea >
</div>
</div>
<div class="layui-form-item" >
<label class="layui-form-label">视频文件</label>
<div class="layui-input-block" style="margin-right:20px">
<input type="file" name="adurl" id="adurl" accept="video/*" ></div>
</div>
</div>
func (c *AD) EditAD(res http.ResponseWriter, req *http.Request, m_ParameHH map[string]interface{}) *ReturnJson {
m_ReturnJson := new(ReturnJson)
ok, m_PArray := c.GetParameValues(m_ParameHH, "ad_datas_nodeuuid", "adname", "admemo")
if !ok {
m_ReturnJson.BOK = false
m_ReturnJson.SMsg = "获得参数失败"
fmt.Println(m_ReturnJson.SMsg)
return m_ReturnJson
}
ad_datas_nodeuuid := m_PArray[0]
adname := m_PArray[1]
admemo := m_PArray[2]
ok, adurl := c.GetParameFile(m_ParameHH, "adurl")//获得文件
Go访问ASP.NET页面或函数
直接Go服务地址访问
如Go服务的地址是:http://www.1xn1.com:9800
那么可访问:
当访问ASPX页面时
http://www.1xn1.com:9800/CoreSYS.SYS/index.aspx
当访问Ajax如在Go中没有找到函数那么调用ASP.NET的函数
http://www.1xn1.com:9800/CoreSYS.SYS/index.ajax
Go框架权限相关
通过IDB接口
初始化权限及权限判断函数
type IDB interface {
LoadPower() map[string]interface{}//该接口未用
HavePower(center_js_uuid, FullClassName, FunctioName string) (bool, string)
...
}
实际装载权限在DBEngine的函数
func (m_DBEngine *DBEngine) initPower() bool {
if m_DBEngine.IsGoDB() {
return m_DBEngine.initGoPower()
}
return m_DBEngine.initASPPower()
}
是在 DBEngine调用open里调用initSLVDB时完成权限的数据初始化
Go框架使用WebSocket
func InitWeb_WebSocket(LoadWebModes func(InitOneJsonMode func(name string, Mode interface{}), m_WebEngineData *WebEngineData), m_WebSocketCallBackArgs ...func(ws *websocket.Conn, m_WS interface{})) {
t1 := time.Now()
m_GlobalIMNodeCallBack = nil
m_GlobalIMRounterCallBack = nil
m_GlobalIMNotifyCallBack = nil
for nIndex, CallBack := range m_WebSocketCallBackArgs {
switch nIndex {
case 0:
m_GlobalIMNodeCallBack = CallBack
case 1:
m_GlobalIMRounterCallBack = CallBack
case 2:
m_GlobalIMNotifyCallBack = CallBack
}
}
...
}
WebEngine.InitWeb_WebSocket(LoadWebModes, OnIMNodeWebSocket, OnIMRounterWebSocket, OnIMSubNotifyWebSocket)
func OnIMNodeWebSocket(ws *websocket.Conn, m_WSClass interface{}) {
defer ws.Close()
var m_IMSendData IMSendData
var m_IMReturnData ShareModel.IMReturnData
var err error
address := ws.LocalAddr().String()
fmt.Println("连接上来WebSocket", address) //, ",m_WSClass:", m_WSClass)
m_OneIM := new(OneIM)
m_OneIM.ws = ws
m_OneIM.bClose = false
m_OneIM.m_SessionLink = nil
m_IMessage := m_WSClass.(*IMessage)
if m_IMessage != nil {
fmt.Println("m_IMessage.ModeName:", m_IMessage.ModeName)
}
var res http.ResponseWriter = new(wsResponse)
var req = new(http.Request)
req.Host = m_IMessage.m_Host
fmt.Println("OnIMNodeWebSocket,req.Host:", req.Host)
m_iChan := make(chan int)
go waitLG(ws, m_iChan)
for {
m_IMSendData.M_COMData = nil
if err = websocket.JSON.Receive(ws, &m_IMSendData); err != nil {
fmt.Println("websocket 连接断开")
if m_OneIM.m_SessionLink != nil {
if m_OneIM.bClose {
break
}
m_IMessage.setUserState(m_OneIM.m_SessionLink.Center_userids_uuid, m_OneIM.m_SessionLink.Lgkey, false)
m_IMUserLK.Lock()
delete(m_WSToIMUserMap, ws)
delete(m_NameToIMUserMap, m_OneIM.m_SessionLink.Username)
key1, key2, key3 := getRegionKeyString(m_OneIM.m_SessionLink.Country, m_OneIM.m_SessionLink.Region, m_OneIM.m_SessionLink.City)
if key1 != "" {
m_IMMap, ok := m_IMRegionUserMap[key1]
if !ok {
} else {
delete(m_IMMap, m_OneIM.m_SessionLink.Username)
}
}
if key2 != "" {
m_IMMap, ok := m_IMRegionUserMap[key2]
if !ok {
} else {
delete(m_IMMap, m_OneIM.m_SessionLink.Username)
}
}
if key3 != "" {
m_IMMap, ok := m_IMRegionUserMap[key3]
if !ok {
} else {
delete(m_IMMap, m_OneIM.m_SessionLink.Username)
}
}
m_IMUserLK.Unlock()
}
break
} else {
byteArray, err := json.Marshal(m_IMSendData)
if err == nil {
m_IMessage.WriteLog("收到数据:" + string(byteArray))
}
m_IMReturnData.M_COMData = nil
m_IMReturnData.M_COM = m_IMSendData.M_COM
m_IMReturnData.PackMark = m_IMSendData.PackMark
if m_OneIM.m_SessionLink == nil {
if m_IMSendData.M_COM == "CALLMODE" {
fmt.Println("m_IMSendData:", m_IMSendData)
m_ModeCall := getModeCall(&m_IMSendData) //.M_COMData.(*ModeCall)
m_ReturnModeCall := new(ReturnModeCall)
m_ReturnModeCall.ClassFullName = m_ModeCall.ClassFullName
m_ReturnModeCall.FunctionName = m_ModeCall.FunctionName
m_IMReturnData.M_COMData = m_ReturnModeCall
if m_ModeCall.ClassFullName == "IMessage" && m_ModeCall.FunctionName == "RequestLink" {
m_Parame := m_ModeCall.M_Parame.(map[string]interface{})
if m_Parame == nil {
m_Parame = make(map[string]interface{})
}
m_Parame["#ws#"] = ""
m_ReturnJson := m_IMessage.LoginLGKey(res, req, m_Parame)
//bArray, _ := json.Marshal(m_ReturnJson.M_ReturnOBJ)
//fmt.Println("登录返回:", string(bArray))
fmt.Println("登录返回:", m_ReturnJson)
if !m_ReturnJson.BOK {
m_iChan <- 0
ws.Close()
break
} else {
m_iChan <- 0
m_LGReturn := m_ReturnJson.M_ReturnOBJ.(*LGReturn)
m_OneIM.m_SessionLink = m_LGReturn.m_SessionLink
key1, key2, key3 := getRegionKeyString(m_OneIM.m_SessionLink.Country, m_OneIM.m_SessionLink.Region, m_OneIM.m_SessionLink.City)
m_IMessage.setUserState(m_OneIM.m_SessionLink.Center_userids_uuid, m_OneIM.m_SessionLink.Lgkey, true)
m_IMUserLK.Lock()
m_TOneIM, ok := m_NameToIMUserMap[m_OneIM.m_SessionLink.Username]
fmt.Println("m_TOneIM:", m_TOneIM)
if ok {
m_TOneIM.bClose = true
delete(m_WSToIMUserMap, m_TOneIM.ws)
delete(m_NameToIMUserMap, m_TOneIM.m_SessionLink.Username)
key1, key2, key3 := getRegionKeyString(m_TOneIM.m_SessionLink.Country, m_TOneIM.m_SessionLink.Region, m_TOneIM.m_SessionLink.City)
if key1 != "" {
m_IMMap, ok := m_IMRegionUserMap[key1]
if !ok {
} else {
delete(m_IMMap, m_TOneIM.m_SessionLink.Username)
}
}
if key2 != "" {
m_IMMap, ok := m_IMRegionUserMap[key2]
if !ok {
} else {
delete(m_IMMap, m_TOneIM.m_SessionLink.Username)
}
}
if key3 != "" {
m_IMMap, ok := m_IMRegionUserMap[key3]
if !ok {
} else {
delete(m_IMMap, m_TOneIM.m_SessionLink.Username)
}
}
m_TOneIM.ws.Close()
fmt.Println("m_TOneIM.ws.Close():", m_TOneIM.m_SessionLink.Username)
}
m_WSToIMUserMap[ws] = m_OneIM
m_NameToIMUserMap[m_OneIM.m_SessionLink.Username] = m_OneIM
if key1 != "" {
m_IMMap, ok := m_IMRegionUserMap[key1]
if !ok {
m_IMMap = make(map[string]*OneIM)
m_IMRegionUserMap[key1] = m_IMMap
}
m_IMMap[m_OneIM.m_SessionLink.Username] = m_OneIM
}
if key2 != "" {
m_IMMap, ok := m_IMRegionUserMap[key2]
if !ok {
m_IMMap = make(map[string]*OneIM)
m_IMRegionUserMap[key2] = m_IMMap
}
m_IMMap[m_OneIM.m_SessionLink.Username] = m_OneIM
}
if key3 != "" {
m_IMMap, ok := m_IMRegionUserMap[key3]
if !ok {
m_IMMap = make(map[string]*OneIM)
m_IMRegionUserMap[key3] = m_IMMap
}
m_IMMap[m_OneIM.m_SessionLink.Username] = m_OneIM
}
m_IMUserLK.Unlock()
m_UserInfo := new(ShareModel.UserInfo)
m_UserInfo.UserName = m_OneIM.m_SessionLink.Username
m_UserInfo.RealName = m_OneIM.m_SessionLink.Realname
m_UserInfo.Headpic = m_OneIM.m_SessionLink.Headpic
m_ReturnJson.M_ReturnOBJ = m_UserInfo
m_ReturnModeCall.M_ReturnJson = m_ReturnJson
m_IMReturnData.M_COMData = m_ReturnModeCall
fmt.Println("发送数据:", m_IMReturnData)
if err = websocket.JSON.Send(ws, m_IMReturnData); err != nil {
}
go pushLeaveWord(res, req, m_OneIM, m_IMessage)
//ws.Close()
//return
}
} else {
ws.Close()
break
}
}
} else {
if m_IMSendData.M_COM == "CALLMODE" {
m_ModeCall := getModeCall(&m_IMSendData) //m_IMSendData.M_COMData.(*ModeCall)
if m_ModeCall.ClassFullName == "IMessage" && m_ModeCall.FunctionName == "RequestLink" {
continue
}
m_Parame := m_ModeCall.M_Parame.(map[string]interface{})
if m_Parame == nil {
m_Parame = make(map[string]interface{})
}
m_Parame["#ws#"] = ""
m_ReturnJson := m_IMessage.RunFunction(m_ModeCall.ClassFullName, m_ModeCall.FunctionName, res, req, m_Parame)
m_ReturnModeCall := new(ReturnModeCall)
m_ReturnModeCall.ClassFullName = m_ModeCall.ClassFullName
m_ReturnModeCall.FunctionName = m_ModeCall.FunctionName
m_ReturnModeCall.M_ReturnJson = m_ReturnJson
m_IMReturnData.M_COMData = m_ReturnModeCall
fmt.Println("发送数据:", m_IMReturnData)
if err = websocket.JSON.Send(ws, m_IMReturnData); err != nil {
}
} else {
switch m_IMSendData.M_COM {
case "TOUSER":
fmt.Println("TOUSER:", m_IMSendData.M_COMData)
//m_DataMap:=make(map[string]interface{})
m_DataMap := m_IMSendData.M_COMData.(map[string]interface{})
m_MineOBJ, _ := m_DataMap["mine"]
m_MineMAP := m_MineOBJ.(map[string]interface{})
m_ToOBJ, _ := m_DataMap["to"]
m_ToMAP := m_ToOBJ.(map[string]interface{})
fmt.Println("m_MineMAP:", m_MineMAP, ",m_ToMAP:", m_ToMAP)
toUserNameOBJ, ok := m_ToMAP["id"]
fmt.Println("toUserNameOBJ:", toUserNameOBJ)
fmt.Println("m_NameToIMUserMap:", m_NameToIMUserMap)
toUserName := toUserNameOBJ.(string)
m_IMessage.WriteLog("收到TOUSER消息to:" + toUserName)
m_IMUserLK.RLock()
m_TOneIM, ok := m_NameToIMUserMap[toUserName]
m_IMUserLK.RUnlock()
if ok && m_OneIM != nil {
websocket.JSON.Send(m_TOneIM.ws, m_IMSendData)
} else {
contentOBJ, _ := m_MineMAP["content"]
content := contentOBJ.(string)
go insertLeaveWord(res, req, toUserName, content, m_OneIM.m_SessionLink, m_IMessage)
}
case "TOGROUP":
}
}
}
//data.Data.转成指定对象处理
//var m_EventInterface map[string]interface{} = data.Data.(map[string]interface{})
/*
if err = websocket.JSON.Send(ws, m_WSPostData); err != nil {
fmt.Println("websocket 连接断开")
break
}
*/
}
}
}
func waitLG(ws *websocket.Conn, ch chan int) {
tNow := time.Now()
bExit := false
for {
select {
case v := <-ch:
fmt.Println(v)
bExit = true
default:
t := time.Now()
if t.Sub(tNow).Seconds() > 30 {
ws.Close()
bExit = true
}
time.Sleep(time.Millisecond * 200)
}
if bExit {
break
}
}
}
func OnIMRounterWebSocket(ws *websocket.Conn, m_WSClass interface{}) {
defer ws.Close()
var m_ToIMRountData ToIMRountData
m_IMessage := m_WSClass.(*IMessage)
bLinkOK := false
m_iChan := make(chan int)
go waitLG(ws, m_iChan)
for {
if err := websocket.JSON.Receive(ws, &m_ToIMRountData); err != nil {
break
}
if !bLinkOK {
if m_ToIMRountData.COM != "LG" {
m_iChan <- 0
ws.Close()
break
} else {
m_IMRounteLG := m_ToIMRountData.M_COMData.(*IMRounteLG)
if m_IMessage.lgIMRounteOK(m_IMRounteLG.Token) {
m_iChan <- 0
bLinkOK = true
}
}
} else {
switch m_ToIMRountData.COM {
case "IM2IM":
m_IM2IM := m_ToIMRountData.M_COMData.(*IM2IM)
fmt.Println(m_IM2IM)
}
}
}
}
func OnIMSubNotifyWebSocket(ws *websocket.Conn, m_WSClass interface{}) {
defer ws.Close()
}