Compare commits
155 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 77753a123f | |||
| 2c9d475a45 | |||
| 3540209b26 | |||
| 797681d76c | |||
| 0ec83f9a95 | |||
| ec798bd624 | |||
| 6b57201e59 | |||
| 4e35dfe6ed | |||
| 970bdb0157 | |||
| d656faf915 | |||
| 2ecc70288e | |||
| ce95cdc021 | |||
| 22130c7afe | |||
| d85c65faef | |||
| c9f33eefec | |||
| 1826e76a34 | |||
| b9a6b7af22 | |||
| 95bfea4feb | |||
| e4bb8ac94a | |||
| d7a49bf56d | |||
| 3d1a1670cc | |||
| 7de6a79611 | |||
| 83198b39cb | |||
| db0724f09b | |||
| c1b013c926 | |||
| 40bc84ea3d | |||
| e977a97013 | |||
| 9330f7f5ea | |||
| d20bcc162c | |||
| b48ad793da | |||
| 3754734130 | |||
| 918b88332b | |||
| 9ba182d65c | |||
| 8cf54ce25b | |||
| 22d00739ff | |||
| 3b2a317d2b | |||
| afa9b173ba | |||
| 53f24c033c | |||
| 1ffcaaef8e | |||
| 62ba00270a | |||
| fe31335cf5 | |||
| b709b58fef | |||
| 76b220aa5d | |||
| dbf8f91696 | |||
| 335e8730da | |||
| cbed318832 | |||
| 31a6568cbe | |||
| 2aa86361e1 | |||
| 2a21dad90a | |||
| bae9f60012 | |||
| 79d1189803 | |||
| c3d0c8921b | |||
| 1da98a058b | |||
| 152386c5a0 | |||
| 5e2845d3a1 | |||
| bab49c9a66 | |||
| 1d3bfcaee5 | |||
| a37a33321f | |||
| 48042ecce4 | |||
| 5d8227d8bb | |||
| 38d3d77c59 | |||
| fec195b3a1 | |||
| 5945ed64c6 | |||
| ce515d991a | |||
| cb04dc6c34 | |||
| 17905c2d21 | |||
| b7c243823a | |||
| ebea14c74f | |||
| d6ef790010 | |||
| 5c64580378 | |||
| e49164fa81 | |||
| 8265e24add | |||
| 283985df52 | |||
| 95adca04bd | |||
| 2e65138222 | |||
| 87039524a7 | |||
| 66cd21c35f | |||
| 7e64131931 | |||
| e30d40cfbb | |||
| 751ed0003d | |||
| 6d9f89a1d4 | |||
| bc329be03b | |||
| 4597a0a50d | |||
| 3dda86d170 | |||
| d847da7591 | |||
| e1eca90835 | |||
| 9283b8c284 | |||
| d8d9afa4d2 | |||
| 4d3829c345 | |||
| a23037a437 | |||
| 181295e54e | |||
| 8cc2499e21 | |||
| a2c49452b4 | |||
| ebf0df5ca8 | |||
| 73bf691ccc | |||
| b2e9701826 | |||
| 789b0a14d1 | |||
| 3ee64fcd8c | |||
| 527503b0d9 | |||
| a95b2fccd7 | |||
| 7e2abb43e3 | |||
| 48fd753a96 | |||
| 136232dd57 | |||
| 008f19355c | |||
| 1fc0a5bbbc | |||
| ce099b8fc8 | |||
| 9c00ac6ba1 | |||
| a5c002bbce | |||
| cf50a699a6 | |||
| 662003c0ca | |||
| f24de2562a | |||
| b84bd7e16f | |||
| 2fb6abf53a | |||
| 2eab29f428 | |||
| 84ee0d259f | |||
| eccab42fc8 | |||
| 1465ba36d3 | |||
| 8380b097b2 | |||
| 6b8f901163 | |||
| bb16f0a75b | |||
| 84dbc5d71e | |||
| 166eeee64c | |||
| 7a649fd652 | |||
| 94ae568526 | |||
| 9ec597f26c | |||
| 388bc5006d | |||
| 0e33c2ad9d | |||
| af726fbcfb | |||
| 1e82a5964d | |||
| d62ba8b0cd | |||
| 320ebe25ec | |||
| 68257d1742 | |||
| 80d167cb1b | |||
| cd911e8fa4 | |||
| faa6fcb00c | |||
| 836c1f461f | |||
| 97b2f54383 | |||
| 9d5f8438c5 | |||
| 3f7963e7cf | |||
| 269df85d27 | |||
| d28c6863e4 | |||
| bba4990ccc | |||
| c57afd6a5d | |||
| 25f355c8d0 | |||
| b1b0673e69 | |||
| 72c086d726 | |||
| 3810ba6c0b | |||
| 5c775b4539 | |||
| deb3e54cc3 | |||
| d1a8f6c668 | |||
| 2291ba7402 | |||
| 20390091f2 | |||
| 123d819b0f | |||
| 30e275a27d | |||
| 1a53f587e8 |
+2
-1
@@ -1,2 +1,3 @@
|
|||||||
/.idea/*
|
/.idea/*
|
||||||
.idea
|
.idea
|
||||||
|
/example/config/app.json
|
||||||
@@ -7,17 +7,17 @@ AND DISTRIBUTION
|
|||||||
|
|
||||||
1. Definitions.
|
1. Definitions.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction, and distribution
|
"License" shall mean the terms and conditions for use, reproduction, and distribution
|
||||||
as defined by Sections 1 through 9 of that document.
|
as defined by Sections 1 through 9 of that document.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
||||||
owner that is granting the License.
|
owner that is granting the License.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all other entities
|
"Legal Entity" shall mean the union of the acting entity and all other entities
|
||||||
that control, are controlled by, or are under common control with that entity.
|
that control, are controlled by, or are under common control with that entity.
|
||||||
@@ -26,31 +26,31 @@ or indirect, to cause the direction or management of such entity, whether
|
|||||||
by contract or otherwise, or (ii) ownership of fifty percent (50%) or more
|
by contract or otherwise, or (ii) ownership of fifty percent (50%) or more
|
||||||
of the outstanding shares, or (iii) beneficial ownership of such entity.
|
of the outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions
|
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions
|
||||||
granted by that License.
|
granted by that License.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications, including
|
"Source" form shall mean the preferred form for making modifications, including
|
||||||
but not limited to software source code, documentation source, and configuration
|
but not limited to software source code, documentation source, and configuration
|
||||||
files.
|
files.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical transformation
|
"Object" form shall mean any form resulting from mechanical transformation
|
||||||
or translation of a Source form, including but not limited to compiled object
|
or translation of a Source form, including but not limited to compiled object
|
||||||
code, generated documentation, and conversions to other media types.
|
code, generated documentation, and conversions to other media types.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or Object form,
|
"Work" shall mean the work of authorship, whether in Source or Object form,
|
||||||
made available under the License, as indicated by a copyright notice that
|
made available under the License, as indicated by a copyright notice that
|
||||||
is included in or attached to the work (an example is provided in the Appendix
|
is included in or attached to the work (an example is provided in the Appendix
|
||||||
below).
|
below).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object form,
|
"Derivative Works" shall mean any work, whether in Source or Object form,
|
||||||
that is based on (or derived from) the Work and for which the editorial revisions,
|
that is based on (or derived from) the Work and for which the editorial revisions,
|
||||||
@@ -59,7 +59,7 @@ original work of authorship. For the purposes of that License, Derivative
|
|||||||
Works shall not include works that remain separable from, or merely link (or
|
Works shall not include works that remain separable from, or merely link (or
|
||||||
bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including the original version
|
"Contribution" shall mean any work of authorship, including the original version
|
||||||
of the Work and any modifications or additions to that Work or Derivative
|
of the Work and any modifications or additions to that Work or Derivative
|
||||||
@@ -74,7 +74,7 @@ for the purpose of discussing and improving the Work, but excluding communicatio
|
|||||||
that is conspicuously marked or otherwise designated in writing by the copyright
|
that is conspicuously marked or otherwise designated in writing by the copyright
|
||||||
owner as "Not a Contribution."
|
owner as "Not a Contribution."
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
||||||
of whom a Contribution has been received by Licensor and subsequently incorporated
|
of whom a Contribution has been received by Licensor and subsequently incorporated
|
||||||
@@ -142,7 +142,7 @@ any additional terms or conditions. Notwithstanding the above, nothing herein
|
|||||||
shall supersede or modify the terms of any separate license agreement you
|
shall supersede or modify the terms of any separate license agreement you
|
||||||
may have executed with Licensor regarding such Contributions.
|
may have executed with Licensor regarding such Contributions.
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade names,
|
6. Trademarks. that License does not grant permission to use the trade names,
|
||||||
trademarks, service marks, or product names of the Licensor, except as required
|
trademarks, service marks, or product names of the Licensor, except as required
|
||||||
for reasonable and customary use in describing the origin of the Work and
|
for reasonable and customary use in describing the origin of the Work and
|
||||||
reproducing the content of the NOTICE file.
|
reproducing the content of the NOTICE file.
|
||||||
|
|||||||
+308
-58
@@ -1,13 +1,14 @@
|
|||||||
package hotime
|
package hotime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "./cache"
|
. "code.hoteas.com/golang/hotime/cache"
|
||||||
"./code"
|
"code.hoteas.com/golang/hotime/code"
|
||||||
. "./common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
. "./db"
|
. "code.hoteas.com/golang/hotime/db"
|
||||||
. "./log"
|
. "code.hoteas.com/golang/hotime/log"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -15,10 +16,11 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Application struct {
|
type Application struct {
|
||||||
*code.MakeCode
|
MakeCodeRouter map[string]*code.MakeCode
|
||||||
MethodRouter
|
MethodRouter
|
||||||
Router
|
Router
|
||||||
ContextBase
|
ContextBase
|
||||||
@@ -27,7 +29,7 @@ type Application struct {
|
|||||||
WebConnectLog *logrus.Logger
|
WebConnectLog *logrus.Logger
|
||||||
Port string //端口号
|
Port string //端口号
|
||||||
TLSPort string //ssl访问端口号
|
TLSPort string //ssl访问端口号
|
||||||
connectListener []func(this *Context) bool //所有的访问监听,true按原计划继续使用,false表示有监听器处理
|
connectListener []func(that *Context) bool //所有的访问监听,true按原计划继续使用,false表示有监听器处理
|
||||||
connectDbFunc func(err ...*Error) (master, slave *sql.DB)
|
connectDbFunc func(err ...*Error) (master, slave *sql.DB)
|
||||||
configPath string
|
configPath string
|
||||||
Config Map
|
Config Map
|
||||||
@@ -63,15 +65,27 @@ func (that *Application) Run(router Router) {
|
|||||||
//
|
//
|
||||||
//}
|
//}
|
||||||
|
|
||||||
that.Router = router
|
//that.Router = router
|
||||||
|
if that.Router == nil {
|
||||||
|
that.Router = Router{}
|
||||||
|
}
|
||||||
|
for k, v := range router {
|
||||||
|
if that.Router[k] == nil {
|
||||||
|
that.Router[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
for k1, v1 := range v {
|
||||||
|
that.Router[k][k1] = v1
|
||||||
|
}
|
||||||
|
}
|
||||||
//重新设置MethodRouter//直达路由
|
//重新设置MethodRouter//直达路由
|
||||||
that.MethodRouter = MethodRouter{}
|
that.MethodRouter = MethodRouter{}
|
||||||
modeRouterStrict := true
|
modeRouterStrict := true
|
||||||
if that.Config.GetBool("modeRouterStrict") == false {
|
if that.Config.GetBool("modeRouterStrict") == false {
|
||||||
modeRouterStrict = false
|
modeRouterStrict = false
|
||||||
}
|
}
|
||||||
if router != nil {
|
if that.Router != nil {
|
||||||
for pk, pv := range router {
|
for pk, pv := range that.Router {
|
||||||
if !modeRouterStrict {
|
if !modeRouterStrict {
|
||||||
pk = strings.ToLower(pk)
|
pk = strings.ToLower(pk)
|
||||||
}
|
}
|
||||||
@@ -248,13 +262,13 @@ func (that *Application) SetConfig(configPath ...string) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetConnectListener 连接判断,返回true继续传输至控制层,false则停止传输
|
// SetConnectListener 连接判断,返回false继续传输至控制层,true则停止传输
|
||||||
func (that *Application) SetConnectListener(lis func(this *Context) bool) {
|
func (that *Application) SetConnectListener(lis func(that *Context) (isFinished bool)) {
|
||||||
that.connectListener = append(that.connectListener, lis)
|
that.connectListener = append(that.connectListener, lis)
|
||||||
}
|
}
|
||||||
|
|
||||||
//网络错误
|
//网络错误
|
||||||
//func (this *Application) session(w http.ResponseWriter, req *http.Request) {
|
//func (that *Application) session(w http.ResponseWriter, req *http.Request) {
|
||||||
//
|
//
|
||||||
//}
|
//}
|
||||||
|
|
||||||
@@ -281,6 +295,7 @@ func (that *Application) urlSer(url string) (string, []string) {
|
|||||||
//访问
|
//访问
|
||||||
|
|
||||||
func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
|
func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
|
||||||
|
nowUnixTime := time.Now()
|
||||||
|
|
||||||
_, s := that.urlSer(req.RequestURI)
|
_, s := that.urlSer(req.RequestURI)
|
||||||
//获取cookie
|
//获取cookie
|
||||||
@@ -292,21 +307,22 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
|
|||||||
// 没有保存就生成随机的session
|
// 没有保存就生成随机的session
|
||||||
cookie, err := req.Cookie(that.Config.GetString("sessionName"))
|
cookie, err := req.Cookie(that.Config.GetString("sessionName"))
|
||||||
sessionId := Md5(strconv.Itoa(Rand(10)))
|
sessionId := Md5(strconv.Itoa(Rand(10)))
|
||||||
token := req.FormValue("token")
|
needSetCookie := ""
|
||||||
|
token := req.Header.Get("Authorization")
|
||||||
|
if len(token) != 32 {
|
||||||
|
|
||||||
if err != nil || (len(token) == 32 && cookie.Value != token) {
|
token = req.FormValue("token")
|
||||||
if len(token) == 32 {
|
}
|
||||||
sessionId = token
|
//没有cookie或者cookie不等于token
|
||||||
}
|
//有token优先token
|
||||||
//没有跨域设置
|
if len(token) == 32 {
|
||||||
if that.Config.GetString("crossDomain") == "" {
|
sessionId = token
|
||||||
http.SetCookie(w, &http.Cookie{Name: that.Config.GetString("sessionName"), Value: sessionId, Path: "/"})
|
//没有token,则查阅session
|
||||||
} else {
|
} else if err == nil && cookie.Value != "" {
|
||||||
//跨域允许需要设置cookie的允许跨域https才有效果
|
|
||||||
w.Header().Set("Set-Cookie", that.Config.GetString("sessionName")+"="+sessionId+"; SameSite=None; Secure")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sessionId = cookie.Value
|
sessionId = cookie.Value
|
||||||
|
//session也没有则判断是否创建cookie
|
||||||
|
} else {
|
||||||
|
needSetCookie = sessionId
|
||||||
}
|
}
|
||||||
|
|
||||||
unescapeUrl, err := url.QueryUnescape(req.RequestURI)
|
unescapeUrl, err := url.QueryUnescape(req.RequestURI)
|
||||||
@@ -325,22 +341,36 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
|
|||||||
context.HandlerStr, context.RouterString = that.urlSer(context.HandlerStr)
|
context.HandlerStr, context.RouterString = that.urlSer(context.HandlerStr)
|
||||||
|
|
||||||
//跨域设置
|
//跨域设置
|
||||||
that.crossDomain(&context)
|
that.crossDomain(&context, needSetCookie)
|
||||||
//是否展示日志
|
|
||||||
if that.WebConnectLog != nil {
|
defer func() {
|
||||||
that.WebConnectLog.Infoln(Substr(context.Req.RemoteAddr, 0, strings.Index(context.Req.RemoteAddr, ":")), context.Req.Method, context.HandlerStr)
|
//是否展示日志
|
||||||
}
|
if that.WebConnectLog != nil {
|
||||||
|
ipStr := Substr(context.Req.RemoteAddr, 0, strings.Index(context.Req.RemoteAddr, ":"))
|
||||||
|
//负载均衡优化
|
||||||
|
if ipStr == "127.0.0.1" {
|
||||||
|
if req.Header.Get("X-Forwarded-For") != "" {
|
||||||
|
ipStr = req.Header.Get("X-Forwarded-For")
|
||||||
|
} else if req.Header.Get("X-Real-IP") != "" {
|
||||||
|
ipStr = req.Header.Get("X-Real-IP")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
that.WebConnectLog.Infoln(ipStr, context.Req.Method,
|
||||||
|
"time cost:", ObjToFloat64(time.Now().UnixNano()-nowUnixTime.UnixNano())/1000000.00, "ms",
|
||||||
|
"data length:", ObjToFloat64(context.DataSize)/1000.00, "KB", context.HandlerStr)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
//访问拦截true继续false暂停
|
//访问拦截true继续false暂停
|
||||||
connectListenerLen := len(that.connectListener)
|
connectListenerLen := len(that.connectListener)
|
||||||
if connectListenerLen != 0 {
|
|
||||||
for i := 0; i < connectListenerLen; i++ {
|
|
||||||
|
|
||||||
if !that.connectListener[i](&context) {
|
for i := connectListenerLen - 1; i >= 0; i-- {
|
||||||
|
|
||||||
context.View()
|
if that.connectListener[i](&context) {
|
||||||
return
|
|
||||||
}
|
context.View()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -394,8 +424,14 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
|
|||||||
header.Set("Cache-Control", "no-cache")
|
header.Set("Cache-Control", "no-cache")
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.Index(path, ".m3u8") != -1 {
|
t := strings.LastIndex(path, ".")
|
||||||
header.Add("Content-Type", "audio/mpegurl")
|
if t != -1 {
|
||||||
|
tt := path[t:]
|
||||||
|
|
||||||
|
if MimeMaps[tt] != "" {
|
||||||
|
|
||||||
|
header.Add("Content-Type", MimeMaps[tt])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//w.Write(data)
|
//w.Write(data)
|
||||||
@@ -403,35 +439,66 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (that *Application) crossDomain(context *Context) {
|
func (that *Application) crossDomain(context *Context, sessionId string) {
|
||||||
|
|
||||||
//没有跨域设置
|
//没有跨域设置
|
||||||
if context.Config.GetString("crossDomain") == "" {
|
if context.Config.GetString("crossDomain") == "" {
|
||||||
|
if sessionId != "" {
|
||||||
|
http.SetCookie(context.Resp, &http.Cookie{Name: that.Config.GetString("sessionName"), Value: sessionId, Path: "/"})
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
header := context.Resp.Header()
|
header := context.Resp.Header()
|
||||||
//header.Set("Access-Control-Allow-Origin", "*")
|
|
||||||
header.Set("Access-Control-Allow-Methods", "GET,POST,OPTIONS,PUT,DELETE")
|
|
||||||
header.Set("Access-Control-Allow-Credentials", "true")
|
|
||||||
header.Set("Access-Control-Expose-Headers", "*")
|
|
||||||
header.Set("Access-Control-Allow-Headers", "X-Requested-With,Content-Type,Access-Token")
|
|
||||||
|
|
||||||
|
//不跨域,则不设置
|
||||||
|
remoteHost := context.Req.Host
|
||||||
|
if context.Config.GetString("port") == "80" || context.Config.GetString("port") == "443" {
|
||||||
|
remoteHost = remoteHost + ":" + context.Config.GetString("port")
|
||||||
|
}
|
||||||
if context.Config.GetString("crossDomain") != "auto" {
|
if context.Config.GetString("crossDomain") != "auto" {
|
||||||
|
//不跨域,则不设置
|
||||||
|
if strings.Contains(context.Config.GetString("crossDomain"), remoteHost) {
|
||||||
|
|
||||||
|
if sessionId != "" {
|
||||||
|
http.SetCookie(context.Resp, &http.Cookie{Name: that.Config.GetString("sessionName"), Value: sessionId, Path: "/"})
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
header.Set("Access-Control-Allow-Origin", that.Config.GetString("crossDomain"))
|
header.Set("Access-Control-Allow-Origin", that.Config.GetString("crossDomain"))
|
||||||
// 后端设置,2592000单位秒,这里是30天
|
// 后端设置,2592000单位秒,这里是30天
|
||||||
header.Set("Access-Control-Max-Age", "2592000")
|
header.Set("Access-Control-Max-Age", "2592000")
|
||||||
|
|
||||||
|
//header.Set("Access-Control-Allow-Origin", "*")
|
||||||
|
header.Set("Access-Control-Allow-Methods", "GET,POST,OPTIONS,PUT,DELETE")
|
||||||
|
header.Set("Access-Control-Allow-Credentials", "true")
|
||||||
|
header.Set("Access-Control-Expose-Headers", "*")
|
||||||
|
header.Set("Access-Control-Allow-Headers", "X-Requested-With,Content-Type,Access-Token")
|
||||||
|
|
||||||
|
if sessionId != "" {
|
||||||
|
//跨域允许需要设置cookie的允许跨域https才有效果
|
||||||
|
context.Resp.Header().Set("Set-Cookie", that.Config.GetString("sessionName")+"="+sessionId+"; Path=/; SameSite=None; Secure")
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
origin := context.Req.Header.Get("Origin")
|
origin := context.Req.Header.Get("Origin")
|
||||||
if origin != "" {
|
|
||||||
header.Set("Access-Control-Allow-Origin", origin)
|
refer := context.Req.Header.Get("Referer")
|
||||||
|
if (origin != "" && strings.Contains(origin, remoteHost)) || strings.Contains(refer, remoteHost) {
|
||||||
|
|
||||||
|
if sessionId != "" {
|
||||||
|
http.SetCookie(context.Resp, &http.Cookie{Name: that.Config.GetString("sessionName"), Value: sessionId, Path: "/"})
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
refer := context.Req.Header.Get("Referer")
|
if origin != "" {
|
||||||
if refer != "" {
|
header.Set("Access-Control-Allow-Origin", origin)
|
||||||
|
//return
|
||||||
|
} else if refer != "" {
|
||||||
tempInt := 0
|
tempInt := 0
|
||||||
lastInt := strings.IndexFunc(refer, func(r rune) bool {
|
lastInt := strings.IndexFunc(refer, func(r rune) bool {
|
||||||
if r == '/' && tempInt > 8 {
|
if r == '/' && tempInt > 8 {
|
||||||
@@ -446,31 +513,82 @@ func (that *Application) crossDomain(context *Context) {
|
|||||||
}
|
}
|
||||||
refer = Substr(refer, 0, lastInt)
|
refer = Substr(refer, 0, lastInt)
|
||||||
header.Set("Access-Control-Allow-Origin", refer)
|
header.Set("Access-Control-Allow-Origin", refer)
|
||||||
|
//header.Set("Access-Control-Allow-Origin", "*")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
header.Set("Access-Control-Allow-Methods", "GET,POST,OPTIONS,PUT,DELETE")
|
||||||
|
header.Set("Access-Control-Allow-Credentials", "true")
|
||||||
|
header.Set("Access-Control-Expose-Headers", "*")
|
||||||
|
header.Set("Access-Control-Allow-Headers", "X-Requested-With,Content-Type,Access-Token")
|
||||||
|
|
||||||
|
if sessionId != "" {
|
||||||
|
//跨域允许需要设置cookie的允许跨域https才有效果
|
||||||
|
context.Resp.Header().Set("Set-Cookie", that.Config.GetString("sessionName")+"="+sessionId+"; Path=/; SameSite=None; Secure")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Init 初始化application
|
//Init 初始化application
|
||||||
func Init(config string) Application {
|
func Init(config string) *Application {
|
||||||
appIns := Application{}
|
appIns := Application{}
|
||||||
//手动模式,
|
//手动模式,
|
||||||
appIns.SetConfig(config)
|
appIns.SetConfig(config)
|
||||||
|
|
||||||
SetDB(&appIns)
|
SetDB(&appIns)
|
||||||
appIns.SetCache()
|
appIns.SetCache()
|
||||||
appIns.MakeCode = &code.MakeCode{}
|
codeConfig := appIns.Config.GetSlice("codeConfig")
|
||||||
codeConfig := appIns.Config.GetMap("codeConfig")
|
|
||||||
if codeConfig != nil {
|
if codeConfig != nil {
|
||||||
|
|
||||||
for k, _ := range codeConfig {
|
for k, _ := range codeConfig {
|
||||||
if appIns.Config.GetInt("mode") == 2{
|
codeMake := codeConfig.GetMap(k)
|
||||||
appIns.MakeCode.Db2JSON(k, codeConfig.GetString(k), &appIns.Db)
|
if codeMake == nil {
|
||||||
}else{
|
continue
|
||||||
appIns.MakeCode.Db2JSON(k, codeConfig.GetString(k), nil)
|
|
||||||
}
|
}
|
||||||
|
//codeMake["table"] = k
|
||||||
|
if appIns.MakeCodeRouter == nil {
|
||||||
|
appIns.MakeCodeRouter = map[string]*code.MakeCode{}
|
||||||
|
}
|
||||||
|
|
||||||
|
if codeMake.GetString("name") == "" {
|
||||||
|
codeMake["name"] = codeMake.GetString("table")
|
||||||
|
}
|
||||||
|
|
||||||
|
if appIns.Config.GetInt("mode") > 0 {
|
||||||
|
appIns.MakeCodeRouter[codeMake.GetString("name")] = &code.MakeCode{}
|
||||||
|
appIns.MakeCodeRouter[codeMake.GetString("name")].Db2JSON(&appIns.Db, codeMake)
|
||||||
|
} else {
|
||||||
|
appIns.MakeCodeRouter[codeMake.GetString("name")] = &code.MakeCode{}
|
||||||
|
appIns.MakeCodeRouter[codeMake.GetString("name")].Db2JSON(nil, codeMake)
|
||||||
|
}
|
||||||
|
//接入动态代码层
|
||||||
|
if appIns.Router == nil {
|
||||||
|
appIns.Router = Router{}
|
||||||
|
}
|
||||||
|
|
||||||
|
//appIns.Router[codeMake.GetString("name")] = TptProject
|
||||||
|
appIns.Router[codeMake.GetString("name")] = Proj{}
|
||||||
|
for k2, _ := range TptProject {
|
||||||
|
appIns.Router[codeMake.GetString("name")][k2] = Ctr{}
|
||||||
|
for k3, v3 := range TptProject[k2] {
|
||||||
|
appIns.Router[codeMake.GetString("name")][k2][k3] = v3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for k1, _ := range appIns.MakeCodeRouter[codeMake.GetString("name")].TableColumns {
|
||||||
|
appIns.Router[codeMake.GetString("name")][k1] = appIns.Router[codeMake.GetString("name")]["hotimeCommon"]
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
setMakeCodeLintener(codeMake.GetString("name"), &appIns)
|
||||||
|
}()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return appIns
|
return &appIns
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDB 智能数据库设置
|
// SetDB 智能数据库设置
|
||||||
@@ -529,3 +647,135 @@ func SetSqliteDB(appIns *Application, config Map) {
|
|||||||
return master, slave
|
return master, slave
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setMakeCodeLintener(name string, appIns *Application) {
|
||||||
|
appIns.SetConnectListener(func(context *Context) (isFinished bool) {
|
||||||
|
|
||||||
|
codeIns := appIns.MakeCodeRouter[name]
|
||||||
|
//文件上传接口
|
||||||
|
if len(context.RouterString) == 1 && context.RouterString[0] == "file" && context.Req.Method == "POST" {
|
||||||
|
if context.Session(codeIns.FileConfig.GetString("table")+"_id").Data == nil {
|
||||||
|
context.Display(2, "你还没有登录")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
//读取网络文件
|
||||||
|
fi, fheader, err := context.Req.FormFile("file")
|
||||||
|
if err != nil {
|
||||||
|
context.Display(3, err)
|
||||||
|
return true
|
||||||
|
|
||||||
|
}
|
||||||
|
filePath := context.Config.GetString("filePath")
|
||||||
|
if filePath == "" {
|
||||||
|
filePath = "/file/2006/01/02/"
|
||||||
|
}
|
||||||
|
|
||||||
|
path := time.Now().Format(filePath)
|
||||||
|
e := os.MkdirAll(context.Config.GetString("tpt")+path, os.ModeDir)
|
||||||
|
if e != nil {
|
||||||
|
context.Display(3, e)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
filePath = path + Md5(ObjToStr(RandX(100000, 9999999))) + fheader.Filename[strings.LastIndex(fheader.Filename, "."):]
|
||||||
|
newFile, e := os.Create(context.Config.GetString("tpt") + filePath)
|
||||||
|
|
||||||
|
if e != nil {
|
||||||
|
context.Display(3, e)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
_, e = io.Copy(newFile, fi)
|
||||||
|
|
||||||
|
if e != nil {
|
||||||
|
context.Display(3, e)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
context.Display(0, filePath)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(context.RouterString) < 2 || appIns.MakeCodeRouter[context.RouterString[0]] == nil {
|
||||||
|
return isFinished
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(context.RouterString) > 1 && context.RouterString[0] == name {
|
||||||
|
if context.RouterString[1] == "hotime" && context.RouterString[2] == "login" {
|
||||||
|
return isFinished
|
||||||
|
}
|
||||||
|
if context.RouterString[1] == "hotime" && context.RouterString[2] == "logout" {
|
||||||
|
return isFinished
|
||||||
|
}
|
||||||
|
|
||||||
|
if context.Session(codeIns.FileConfig.GetString("table")+"_id").Data == nil {
|
||||||
|
context.Display(2, "你还没有登录")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(context.RouterString) < 2 || len(context.RouterString) > 3 ||
|
||||||
|
!(context.Router[context.RouterString[0]] != nil &&
|
||||||
|
context.Router[context.RouterString[0]][context.RouterString[1]] != nil) {
|
||||||
|
return isFinished
|
||||||
|
}
|
||||||
|
//排除无效操作
|
||||||
|
if len(context.RouterString) == 2 &&
|
||||||
|
context.Req.Method != "GET" &&
|
||||||
|
context.Req.Method != "POST" {
|
||||||
|
return isFinished
|
||||||
|
}
|
||||||
|
//列表检索
|
||||||
|
if len(context.RouterString) == 2 &&
|
||||||
|
context.Req.Method == "GET" {
|
||||||
|
if context.Router[context.RouterString[0]][context.RouterString[1]]["search"] == nil {
|
||||||
|
return isFinished
|
||||||
|
}
|
||||||
|
context.Router[context.RouterString[0]][context.RouterString[1]]["search"](context)
|
||||||
|
}
|
||||||
|
//新建
|
||||||
|
if len(context.RouterString) == 2 &&
|
||||||
|
context.Req.Method == "POST" {
|
||||||
|
if context.Router[context.RouterString[0]][context.RouterString[1]]["add"] == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
context.Router[context.RouterString[0]][context.RouterString[1]]["add"](context)
|
||||||
|
}
|
||||||
|
if len(context.RouterString) == 3 &&
|
||||||
|
context.Req.Method == "POST" {
|
||||||
|
return isFinished
|
||||||
|
}
|
||||||
|
//查询单条
|
||||||
|
if len(context.RouterString) == 3 &&
|
||||||
|
context.Req.Method == "GET" {
|
||||||
|
|
||||||
|
if context.Router[context.RouterString[0]][context.RouterString[1]]["info"] == nil {
|
||||||
|
return isFinished
|
||||||
|
}
|
||||||
|
|
||||||
|
context.Router[context.RouterString[0]][context.RouterString[1]]["info"](context)
|
||||||
|
}
|
||||||
|
//更新
|
||||||
|
if len(context.RouterString) == 3 &&
|
||||||
|
context.Req.Method == "PUT" {
|
||||||
|
|
||||||
|
if context.Router[context.RouterString[0]][context.RouterString[1]]["update"] == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
context.Router[context.RouterString[0]][context.RouterString[1]]["update"](context)
|
||||||
|
}
|
||||||
|
//移除
|
||||||
|
if len(context.RouterString) == 3 &&
|
||||||
|
context.Req.Method == "DELETE" {
|
||||||
|
|
||||||
|
if context.Router[context.RouterString[0]][context.RouterString[1]]["remove"] == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
context.Router[context.RouterString[0]][context.RouterString[1]]["remove"](context)
|
||||||
|
}
|
||||||
|
|
||||||
|
context.View()
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
Vendored
+18
-18
@@ -1,7 +1,7 @@
|
|||||||
package cache
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "../common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
"errors"
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ func (that *HoTimeCache) Session(key string, data ...interface{}) *Obj {
|
|||||||
//内存缓存有
|
//内存缓存有
|
||||||
if that.memoryCache != nil && that.memoryCache.SessionSet {
|
if that.memoryCache != nil && that.memoryCache.SessionSet {
|
||||||
reData = that.memoryCache.Cache(key, data...)
|
reData = that.memoryCache.Cache(key, data...)
|
||||||
if reData != nil {
|
if reData.Data != nil {
|
||||||
return reData
|
return reData
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -29,9 +29,9 @@ func (that *HoTimeCache) Session(key string, data ...interface{}) *Obj {
|
|||||||
//redis缓存有
|
//redis缓存有
|
||||||
if that.redisCache != nil && that.redisCache.SessionSet {
|
if that.redisCache != nil && that.redisCache.SessionSet {
|
||||||
reData = that.redisCache.Cache(key, data...)
|
reData = that.redisCache.Cache(key, data...)
|
||||||
if reData != nil {
|
if reData.Data != nil {
|
||||||
if that.memoryCache != nil && that.memoryCache.SessionSet {
|
if that.memoryCache != nil && that.memoryCache.SessionSet {
|
||||||
that.memoryCache.Cache(key, reData)
|
that.memoryCache.Cache(key, reData.Data)
|
||||||
}
|
}
|
||||||
return reData
|
return reData
|
||||||
}
|
}
|
||||||
@@ -40,12 +40,12 @@ func (that *HoTimeCache) Session(key string, data ...interface{}) *Obj {
|
|||||||
//db缓存有
|
//db缓存有
|
||||||
if that.dbCache != nil && that.dbCache.SessionSet {
|
if that.dbCache != nil && that.dbCache.SessionSet {
|
||||||
reData = that.dbCache.Cache(key, data...)
|
reData = that.dbCache.Cache(key, data...)
|
||||||
if reData != nil {
|
if reData.Data != nil {
|
||||||
if that.memoryCache != nil && that.memoryCache.SessionSet {
|
if that.memoryCache != nil && that.memoryCache.SessionSet {
|
||||||
that.memoryCache.Cache(key, reData)
|
that.memoryCache.Cache(key, reData.Data)
|
||||||
}
|
}
|
||||||
if that.redisCache != nil && that.redisCache.SessionSet {
|
if that.redisCache != nil && that.redisCache.SessionSet {
|
||||||
that.redisCache.Cache(key, reData)
|
that.redisCache.Cache(key, reData.Data)
|
||||||
}
|
}
|
||||||
|
|
||||||
return reData
|
return reData
|
||||||
@@ -76,7 +76,7 @@ func (that *HoTimeCache) Db(key string, data ...interface{}) *Obj {
|
|||||||
//内存缓存有
|
//内存缓存有
|
||||||
if that.memoryCache != nil && that.memoryCache.DbSet {
|
if that.memoryCache != nil && that.memoryCache.DbSet {
|
||||||
reData = that.memoryCache.Cache(key, data...)
|
reData = that.memoryCache.Cache(key, data...)
|
||||||
if reData != nil {
|
if reData.Data != nil {
|
||||||
return reData
|
return reData
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -84,9 +84,9 @@ func (that *HoTimeCache) Db(key string, data ...interface{}) *Obj {
|
|||||||
//redis缓存有
|
//redis缓存有
|
||||||
if that.redisCache != nil && that.redisCache.DbSet {
|
if that.redisCache != nil && that.redisCache.DbSet {
|
||||||
reData = that.redisCache.Cache(key, data...)
|
reData = that.redisCache.Cache(key, data...)
|
||||||
if reData != nil {
|
if reData.Data != nil {
|
||||||
if that.memoryCache != nil && that.memoryCache.DbSet {
|
if that.memoryCache != nil && that.memoryCache.DbSet {
|
||||||
that.memoryCache.Cache(key, reData)
|
that.memoryCache.Cache(key, reData.Data)
|
||||||
}
|
}
|
||||||
return reData
|
return reData
|
||||||
}
|
}
|
||||||
@@ -95,13 +95,13 @@ func (that *HoTimeCache) Db(key string, data ...interface{}) *Obj {
|
|||||||
//redis缓存有
|
//redis缓存有
|
||||||
if that.dbCache != nil && that.dbCache.DbSet {
|
if that.dbCache != nil && that.dbCache.DbSet {
|
||||||
reData = that.dbCache.Cache(key, data...)
|
reData = that.dbCache.Cache(key, data...)
|
||||||
if reData != nil {
|
if reData.Data != nil {
|
||||||
if that.memoryCache != nil && that.memoryCache.DbSet {
|
if that.memoryCache != nil && that.memoryCache.DbSet {
|
||||||
that.memoryCache.Cache(key, reData)
|
that.memoryCache.Cache(key, reData.Data)
|
||||||
}
|
}
|
||||||
|
|
||||||
if that.redisCache != nil && that.redisCache.DbSet {
|
if that.redisCache != nil && that.redisCache.DbSet {
|
||||||
that.redisCache.Cache(key, reData)
|
that.redisCache.Cache(key, reData.Data)
|
||||||
}
|
}
|
||||||
|
|
||||||
return reData
|
return reData
|
||||||
@@ -140,10 +140,10 @@ func (that *HoTimeCache) Cache(key string, data ...interface{}) *Obj {
|
|||||||
//redis缓存有
|
//redis缓存有
|
||||||
if that.redisCache != nil {
|
if that.redisCache != nil {
|
||||||
reData = that.redisCache.Cache(key, data...)
|
reData = that.redisCache.Cache(key, data...)
|
||||||
if reData != nil {
|
if reData.Data != nil {
|
||||||
|
|
||||||
if that.memoryCache != nil {
|
if that.memoryCache != nil {
|
||||||
that.memoryCache.Cache(key, reData)
|
that.memoryCache.Cache(key, reData.Data)
|
||||||
}
|
}
|
||||||
return reData
|
return reData
|
||||||
}
|
}
|
||||||
@@ -152,12 +152,12 @@ func (that *HoTimeCache) Cache(key string, data ...interface{}) *Obj {
|
|||||||
//redis缓存有
|
//redis缓存有
|
||||||
if that.dbCache != nil {
|
if that.dbCache != nil {
|
||||||
reData = that.dbCache.Cache(key, data...)
|
reData = that.dbCache.Cache(key, data...)
|
||||||
if reData != nil {
|
if reData.Data != nil {
|
||||||
if that.memoryCache != nil {
|
if that.memoryCache != nil {
|
||||||
that.memoryCache.Cache(key, reData)
|
that.memoryCache.Cache(key, reData.Data)
|
||||||
}
|
}
|
||||||
if that.redisCache != nil {
|
if that.redisCache != nil {
|
||||||
that.redisCache.Cache(key, reData)
|
that.redisCache.Cache(key, reData.Data)
|
||||||
}
|
}
|
||||||
return reData
|
return reData
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+14
-14
@@ -1,7 +1,7 @@
|
|||||||
package cache
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "../common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -30,14 +30,14 @@ type CacheDb struct {
|
|||||||
isInit bool
|
isInit bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CacheDb) GetError() *Error {
|
func (that *CacheDb) GetError() *Error {
|
||||||
|
|
||||||
return this.Error
|
return that.Error
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CacheDb) SetError(err *Error) {
|
func (that *CacheDb) SetError(err *Error) {
|
||||||
this.Error = err
|
that.Error = err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (that *CacheDb) initDbTable() {
|
func (that *CacheDb) initDbTable() {
|
||||||
@@ -58,7 +58,7 @@ func (that *CacheDb) initDbTable() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, e := that.Db.Exec("CREATE TABLE `" + that.Db.GetPrefix() + "cached` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `ckey` varchar(60) DEFAULT NULL, `cvalue` varchar(2000) DEFAULT NULL, `time` bigint(20) DEFAULT NULL, `endtime` bigint(20) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=198740 DEFAULT CHARSET=utf8")
|
_, e := that.Db.Exec("CREATE TABLE `" + that.Db.GetPrefix() + "cached` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `key` varchar(60) DEFAULT NULL, `value` varchar(2000) DEFAULT NULL, `time` bigint(20) DEFAULT NULL, `endtime` bigint(20) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=198740 DEFAULT CHARSET=utf8")
|
||||||
if e.GetError() == nil {
|
if e.GetError() == nil {
|
||||||
that.isInit = true
|
that.isInit = true
|
||||||
}
|
}
|
||||||
@@ -74,8 +74,8 @@ func (that *CacheDb) initDbTable() {
|
|||||||
}
|
}
|
||||||
_, e := that.Db.Exec(`CREATE TABLE "` + that.Db.GetPrefix() + `cached" (
|
_, e := that.Db.Exec(`CREATE TABLE "` + that.Db.GetPrefix() + `cached" (
|
||||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
"ckey" TEXT(60),
|
"key" TEXT(60),
|
||||||
"cvalue" TEXT(2000),
|
"value" TEXT(2000),
|
||||||
"time" integer,
|
"time" integer,
|
||||||
"endtime" integer
|
"endtime" integer
|
||||||
);`)
|
);`)
|
||||||
@@ -90,7 +90,7 @@ func (that *CacheDb) initDbTable() {
|
|||||||
//获取Cache键只能为string类型
|
//获取Cache键只能为string类型
|
||||||
func (that *CacheDb) get(key string) interface{} {
|
func (that *CacheDb) get(key string) interface{} {
|
||||||
|
|
||||||
cached := that.Db.Get("cached", "*", Map{"ckey": key})
|
cached := that.Db.Get("cached", "*", Map{"key": key})
|
||||||
|
|
||||||
if cached == nil {
|
if cached == nil {
|
||||||
return nil
|
return nil
|
||||||
@@ -103,7 +103,7 @@ func (that *CacheDb) get(key string) interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data := Map{}
|
data := Map{}
|
||||||
data.JsonToMap(cached.GetString("cvalue"))
|
data.JsonToMap(cached.GetString("value"))
|
||||||
|
|
||||||
return data.Get("data")
|
return data.Get("data")
|
||||||
}
|
}
|
||||||
@@ -113,9 +113,9 @@ func (that *CacheDb) set(key string, value interface{}, tim int64) {
|
|||||||
|
|
||||||
bte, _ := json.Marshal(Map{"data": value})
|
bte, _ := json.Marshal(Map{"data": value})
|
||||||
|
|
||||||
num := that.Db.Update("cached", Map{"cvalue": string(bte), "time": time.Now().UnixNano(), "endtime": tim}, Map{"ckey": key})
|
num := that.Db.Update("cached", Map{"value": string(bte), "time": time.Now().UnixNano(), "endtime": tim}, Map{"key": key})
|
||||||
if num == int64(0) {
|
if num == int64(0) {
|
||||||
that.Db.Insert("cached", Map{"cvalue": string(bte), "time": time.Now().UnixNano(), "endtime": tim, "ckey": key})
|
that.Db.Insert("cached", Map{"value": string(bte), "time": time.Now().UnixNano(), "endtime": tim, "key": key})
|
||||||
}
|
}
|
||||||
|
|
||||||
//随机执行删除命令
|
//随机执行删除命令
|
||||||
@@ -130,10 +130,10 @@ func (that *CacheDb) delete(key string) {
|
|||||||
//如果通配删除
|
//如果通配删除
|
||||||
if del != -1 {
|
if del != -1 {
|
||||||
key = Substr(key, 0, del)
|
key = Substr(key, 0, del)
|
||||||
that.Db.Delete("cached", Map{"ckey": key + "%"})
|
that.Db.Delete("cached", Map{"key": key + "%"})
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
that.Db.Delete("cached", Map{"ckey": key})
|
that.Db.Delete("cached", Map{"key": key})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Vendored
+45
-45
@@ -1,7 +1,7 @@
|
|||||||
package cache
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "../common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -17,47 +17,47 @@ type CacheMemory struct {
|
|||||||
mutex *sync.RWMutex
|
mutex *sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CacheMemory) GetError() *Error {
|
func (that *CacheMemory) GetError() *Error {
|
||||||
|
|
||||||
return this.Error
|
return that.Error
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CacheMemory) SetError(err *Error) {
|
func (that *CacheMemory) SetError(err *Error) {
|
||||||
this.Error = err
|
that.Error = err
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取Cache键只能为string类型
|
//获取Cache键只能为string类型
|
||||||
func (this *CacheMemory) get(key string) interface{} {
|
func (that *CacheMemory) get(key string) interface{} {
|
||||||
this.Error.SetError(nil)
|
that.Error.SetError(nil)
|
||||||
if this.Map == nil {
|
if that.Map == nil {
|
||||||
this.Map = Map{}
|
that.Map = Map{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if this.Map[key] == nil {
|
if that.Map[key] == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
data := this.Map.Get(key, this.Error).(cacheData)
|
data := that.Map.Get(key, that.Error).(cacheData)
|
||||||
if this.Error.GetError() != nil {
|
if that.Error.GetError() != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.time < time.Now().Unix() {
|
if data.time < time.Now().Unix() {
|
||||||
delete(this.Map, key)
|
delete(that.Map, key)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return data.data
|
return data.data
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CacheMemory) refreshMap() {
|
func (that *CacheMemory) refreshMap() {
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
this.mutex.Lock()
|
that.mutex.Lock()
|
||||||
defer this.mutex.Unlock()
|
defer that.mutex.Unlock()
|
||||||
for key, v := range this.Map {
|
for key, v := range that.Map {
|
||||||
data := v.(cacheData)
|
data := v.(cacheData)
|
||||||
if data.time <= time.Now().Unix() {
|
if data.time <= time.Now().Unix() {
|
||||||
delete(this.Map, key)
|
delete(that.Map, key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,15 +66,15 @@ func (this *CacheMemory) refreshMap() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//key value ,时间为时间戳
|
//key value ,时间为时间戳
|
||||||
func (this *CacheMemory) set(key string, value interface{}, time int64) {
|
func (that *CacheMemory) set(key string, value interface{}, time int64) {
|
||||||
this.Error.SetError(nil)
|
that.Error.SetError(nil)
|
||||||
var data cacheData
|
var data cacheData
|
||||||
|
|
||||||
if this.Map == nil {
|
if that.Map == nil {
|
||||||
this.Map = Map{}
|
that.Map = Map{}
|
||||||
}
|
}
|
||||||
|
|
||||||
dd := this.Map[key]
|
dd := that.Map[key]
|
||||||
|
|
||||||
if dd == nil {
|
if dd == nil {
|
||||||
data = cacheData{}
|
data = cacheData{}
|
||||||
@@ -85,74 +85,74 @@ func (this *CacheMemory) set(key string, value interface{}, time int64) {
|
|||||||
data.time = time
|
data.time = time
|
||||||
data.data = value
|
data.data = value
|
||||||
|
|
||||||
this.Map.Put(key, data)
|
that.Map.Put(key, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CacheMemory) delete(key string) {
|
func (that *CacheMemory) delete(key string) {
|
||||||
del := strings.Index(key, "*")
|
del := strings.Index(key, "*")
|
||||||
//如果通配删除
|
//如果通配删除
|
||||||
if del != -1 {
|
if del != -1 {
|
||||||
key = Substr(key, 0, del)
|
key = Substr(key, 0, del)
|
||||||
for k, _ := range this.Map {
|
for k, _ := range that.Map {
|
||||||
if strings.Index(k, key) != -1 {
|
if strings.Index(k, key) != -1 {
|
||||||
delete(this.Map, k)
|
delete(that.Map, k)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
delete(this.Map, key)
|
delete(that.Map, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CacheMemory) Cache(key string, data ...interface{}) *Obj {
|
func (that *CacheMemory) Cache(key string, data ...interface{}) *Obj {
|
||||||
|
|
||||||
x := RandX(1, 100000)
|
x := RandX(1, 100000)
|
||||||
if x > 99950 {
|
if x > 99950 {
|
||||||
this.refreshMap()
|
that.refreshMap()
|
||||||
}
|
}
|
||||||
if this.mutex == nil {
|
if that.mutex == nil {
|
||||||
this.mutex = &sync.RWMutex{}
|
that.mutex = &sync.RWMutex{}
|
||||||
}
|
}
|
||||||
|
|
||||||
reData := &Obj{Data: nil}
|
reData := &Obj{Data: nil}
|
||||||
|
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
this.mutex.RLock()
|
that.mutex.RLock()
|
||||||
reData.Data = this.get(key)
|
reData.Data = that.get(key)
|
||||||
this.mutex.RUnlock()
|
that.mutex.RUnlock()
|
||||||
return reData
|
return reData
|
||||||
}
|
}
|
||||||
tim := time.Now().Unix()
|
tim := time.Now().Unix()
|
||||||
|
|
||||||
if len(data) == 1 && data[0] == nil {
|
if len(data) == 1 && data[0] == nil {
|
||||||
this.mutex.Lock()
|
that.mutex.Lock()
|
||||||
this.delete(key)
|
that.delete(key)
|
||||||
this.mutex.Unlock()
|
that.mutex.Unlock()
|
||||||
return reData
|
return reData
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(data) == 1 {
|
if len(data) == 1 {
|
||||||
|
|
||||||
tim = tim + this.TimeOut
|
tim = tim + that.TimeOut
|
||||||
|
|
||||||
}
|
}
|
||||||
if len(data) == 2 {
|
if len(data) == 2 {
|
||||||
this.Error.SetError(nil)
|
that.Error.SetError(nil)
|
||||||
tempt := ObjToInt64(data[1], this.Error)
|
tempt := ObjToInt64(data[1], that.Error)
|
||||||
|
|
||||||
if tempt > tim {
|
if tempt > tim {
|
||||||
|
|
||||||
tim = tempt
|
tim = tempt
|
||||||
} else if this.Error.GetError() == nil {
|
} else if that.Error.GetError() == nil {
|
||||||
|
|
||||||
tim = tim + tempt
|
tim = tim + tempt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.mutex.Lock()
|
that.mutex.Lock()
|
||||||
this.set(key, data[0], tim)
|
that.set(key, data[0], tim)
|
||||||
this.mutex.Unlock()
|
that.mutex.Unlock()
|
||||||
return reData
|
return reData
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+51
-51
@@ -1,7 +1,7 @@
|
|||||||
package cache
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "../common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
"github.com/garyburd/redigo/redis"
|
"github.com/garyburd/redigo/redis"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -20,65 +20,65 @@ type CacheRedis struct {
|
|||||||
*Error
|
*Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CacheRedis) GetError() *Error {
|
func (that *CacheRedis) GetError() *Error {
|
||||||
|
|
||||||
return this.Error
|
return that.Error
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CacheRedis) SetError(err *Error) {
|
func (that *CacheRedis) SetError(err *Error) {
|
||||||
this.Error = err
|
that.Error = err
|
||||||
}
|
}
|
||||||
|
|
||||||
//唯一标志
|
//唯一标志
|
||||||
func (this *CacheRedis) GetTag() int64 {
|
func (that *CacheRedis) GetTag() int64 {
|
||||||
|
|
||||||
if this.tag == int64(0) {
|
if that.tag == int64(0) {
|
||||||
this.tag = time.Now().UnixNano()
|
that.tag = time.Now().UnixNano()
|
||||||
}
|
}
|
||||||
return this.tag
|
return that.tag
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CacheRedis) reCon() bool {
|
func (that *CacheRedis) reCon() bool {
|
||||||
var err error
|
var err error
|
||||||
this.conn, err = redis.Dial("tcp", this.Host+":"+ObjToStr(this.Port))
|
that.conn, err = redis.Dial("tcp", that.Host+":"+ObjToStr(that.Port))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.conn = nil
|
that.conn = nil
|
||||||
this.Error.SetError(err)
|
that.Error.SetError(err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if this.Pwd != "" {
|
if that.Pwd != "" {
|
||||||
_, err = this.conn.Do("AUTH", this.Pwd)
|
_, err = that.conn.Do("AUTH", that.Pwd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.conn = nil
|
that.conn = nil
|
||||||
this.Error.SetError(err)
|
that.Error.SetError(err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
func (this *CacheRedis) del(key string) {
|
func (that *CacheRedis) del(key string) {
|
||||||
del := strings.Index(key, "*")
|
del := strings.Index(key, "*")
|
||||||
if del != -1 {
|
if del != -1 {
|
||||||
val, err := redis.Strings(this.conn.Do("KEYS", key))
|
val, err := redis.Strings(that.conn.Do("KEYS", key))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.conn.Send("MULTI")
|
that.conn.Send("MULTI")
|
||||||
for i, _ := range val {
|
for i, _ := range val {
|
||||||
this.conn.Send("DEL", val[i])
|
that.conn.Send("DEL", val[i])
|
||||||
}
|
}
|
||||||
this.conn.Do("EXEC")
|
that.conn.Do("EXEC")
|
||||||
} else {
|
} else {
|
||||||
_, err := this.conn.Do("DEL", key)
|
_, err := that.conn.Do("DEL", key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.Error.SetError(err)
|
that.Error.SetError(err)
|
||||||
_, err = this.conn.Do("PING")
|
_, err = that.conn.Do("PING")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if this.reCon() {
|
if that.reCon() {
|
||||||
_, err = this.conn.Do("DEL", key)
|
_, err = that.conn.Do("DEL", key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,32 +86,32 @@ func (this *CacheRedis) del(key string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//key value ,时间为时间戳
|
//key value ,时间为时间戳
|
||||||
func (this *CacheRedis) set(key string, value string, time int64) {
|
func (that *CacheRedis) set(key string, value string, time int64) {
|
||||||
_, err := this.conn.Do("SET", key, value, "EX", ObjToStr(time))
|
_, err := that.conn.Do("SET", key, value, "EX", ObjToStr(time))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
this.Error.SetError(err)
|
that.Error.SetError(err)
|
||||||
_, err = this.conn.Do("PING")
|
_, err = that.conn.Do("PING")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if this.reCon() {
|
if that.reCon() {
|
||||||
_, err = this.conn.Do("SET", key, value, "EX", ObjToStr(time))
|
_, err = that.conn.Do("SET", key, value, "EX", ObjToStr(time))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CacheRedis) get(key string) *Obj {
|
func (that *CacheRedis) get(key string) *Obj {
|
||||||
reData := &Obj{}
|
reData := &Obj{}
|
||||||
var err error
|
var err error
|
||||||
reData.Data, err = redis.String(this.conn.Do("GET", key))
|
reData.Data, err = redis.String(that.conn.Do("GET", key))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
reData.Data = nil
|
reData.Data = nil
|
||||||
if !strings.Contains(err.Error(), "nil returned") {
|
if !strings.Contains(err.Error(), "nil returned") {
|
||||||
this.Error.SetError(err)
|
that.Error.SetError(err)
|
||||||
_, err = this.conn.Do("PING")
|
_, err = that.conn.Do("PING")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if this.reCon() {
|
if that.reCon() {
|
||||||
reData.Data, err = redis.String(this.conn.Do("GET", key))
|
reData.Data, err = redis.String(that.conn.Do("GET", key))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,10 +121,10 @@ func (this *CacheRedis) get(key string) *Obj {
|
|||||||
return reData
|
return reData
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CacheRedis) Cache(key string, data ...interface{}) *Obj {
|
func (that *CacheRedis) Cache(key string, data ...interface{}) *Obj {
|
||||||
reData := &Obj{}
|
reData := &Obj{}
|
||||||
if this.conn == nil {
|
if that.conn == nil {
|
||||||
re := this.reCon()
|
re := that.reCon()
|
||||||
if !re {
|
if !re {
|
||||||
return reData
|
return reData
|
||||||
}
|
}
|
||||||
@@ -132,38 +132,38 @@ func (this *CacheRedis) Cache(key string, data ...interface{}) *Obj {
|
|||||||
//查询缓存
|
//查询缓存
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
|
|
||||||
reData = this.get(key)
|
reData = that.get(key)
|
||||||
return reData
|
return reData
|
||||||
|
|
||||||
}
|
}
|
||||||
tim := int64(0)
|
tim := int64(0)
|
||||||
//删除缓存
|
//删除缓存
|
||||||
if len(data) == 1 && data[0] == nil {
|
if len(data) == 1 && data[0] == nil {
|
||||||
this.del(key)
|
that.del(key)
|
||||||
return reData
|
return reData
|
||||||
}
|
}
|
||||||
//添加缓存
|
//添加缓存
|
||||||
if len(data) == 1 {
|
if len(data) == 1 {
|
||||||
|
|
||||||
if this.TimeOut == 0 {
|
if that.TimeOut == 0 {
|
||||||
//this.Time = Config.GetInt64("cacheShortTime")
|
//that.Time = Config.GetInt64("cacheShortTime")
|
||||||
}
|
}
|
||||||
|
|
||||||
tim += this.TimeOut
|
tim += that.TimeOut
|
||||||
}
|
}
|
||||||
if len(data) == 2 {
|
if len(data) == 2 {
|
||||||
this.Error.SetError(nil)
|
that.Error.SetError(nil)
|
||||||
tempt := ObjToInt64(data[1], this.Error)
|
tempt := ObjToInt64(data[1], that.Error)
|
||||||
if tempt > tim {
|
if tempt > tim {
|
||||||
|
|
||||||
tim = tempt
|
tim = tempt
|
||||||
} else if this.GetError() == nil {
|
} else if that.GetError() == nil {
|
||||||
|
|
||||||
tim = tim + tempt
|
tim = tim + tempt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.set(key, ObjToStr(data[0]), tim)
|
that.set(key, ObjToStr(data[0]), tim)
|
||||||
|
|
||||||
return reData
|
return reData
|
||||||
|
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
package cache
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "../common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CacheIns interface {
|
type CacheIns interface {
|
||||||
|
|||||||
@@ -0,0 +1,301 @@
|
|||||||
|
package hotime
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Project 管理端项目
|
||||||
|
var TptProject = Proj{
|
||||||
|
//"user": UserCtr,
|
||||||
|
"hotimeCommon": Ctr{
|
||||||
|
"info": func(that *Context) {
|
||||||
|
hotimeName := that.RouterString[0]
|
||||||
|
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
|
||||||
|
data := that.Db.Get(fileConfig.GetString("table"), "*", Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()})
|
||||||
|
str, inData := that.MakeCodeRouter[hotimeName].Info(that.RouterString[1], data, that.Db)
|
||||||
|
where := Map{"id": that.RouterString[2]}
|
||||||
|
|
||||||
|
if len(inData) == 1 {
|
||||||
|
inData["id"] = where["id"]
|
||||||
|
where = Map{"AND": inData}
|
||||||
|
} else if len(inData) > 1 {
|
||||||
|
where["OR"] = inData
|
||||||
|
where = Map{"AND": where}
|
||||||
|
}
|
||||||
|
|
||||||
|
re := that.Db.Get(that.RouterString[1], str, where)
|
||||||
|
|
||||||
|
if re == nil {
|
||||||
|
that.Display(4, "找不到对应信息")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range re {
|
||||||
|
column := that.MakeCodeRouter[hotimeName].TableColumns[that.RouterString[1]][k]
|
||||||
|
if column == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" {
|
||||||
|
seStr := "id," + column.GetString("value")
|
||||||
|
if that.MakeCodeRouter[hotimeName].TableColumns[column.GetString("link")]["phone"] != nil {
|
||||||
|
seStr = seStr + ",phone"
|
||||||
|
}
|
||||||
|
|
||||||
|
link := strings.Replace(column.GetString("name"), "_id", "", -1)
|
||||||
|
if link == "parent" {
|
||||||
|
link = that.RouterString[1]
|
||||||
|
}
|
||||||
|
re[link] = that.Db.Get(column.GetString("link"), seStr, Map{"id": v})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//如果有table字段则代为link
|
||||||
|
if re["table"] != nil && re["table_id"] != nil {
|
||||||
|
|
||||||
|
column := that.MakeCodeRouter[hotimeName].TableColumns[that.RouterString[1]][re.GetString("table")]
|
||||||
|
v := re.GetCeilInt64("table_id")
|
||||||
|
|
||||||
|
seStr := "id," + column.GetString("value")
|
||||||
|
|
||||||
|
if that.MakeCodeRouter[hotimeName].TableColumns[column.GetString("link")]["phone"] != nil {
|
||||||
|
seStr = seStr + ",phone"
|
||||||
|
}
|
||||||
|
|
||||||
|
link := strings.Replace(column.GetString("name"), "_id", "", -1)
|
||||||
|
if link == "parent" {
|
||||||
|
link = that.RouterString[1]
|
||||||
|
}
|
||||||
|
re[link] = that.Db.Get(column.GetString("link"), seStr, Map{"id": v})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
that.Display(0, re)
|
||||||
|
},
|
||||||
|
"add": func(that *Context) {
|
||||||
|
that.Log = Map{"table": that.RouterString[1], "type": 1}
|
||||||
|
|
||||||
|
hotimeName := that.RouterString[0]
|
||||||
|
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
|
||||||
|
data := that.Db.Get(fileConfig.GetString("table"), "*", Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()})
|
||||||
|
inData := that.MakeCodeRouter[hotimeName].Add(that.RouterString[1], data, that.Req)
|
||||||
|
if inData == nil {
|
||||||
|
that.Display(3, "请求参数不足")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
re := that.Db.Insert(that.RouterString[1], inData)
|
||||||
|
|
||||||
|
if re == 0 {
|
||||||
|
that.Display(4, "无法插入对应数据")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
//索引管理,便于检索以及权限
|
||||||
|
if inData.Get("parent_id") != nil && inData.GetString("index") != "" {
|
||||||
|
index := that.Db.Get(that.RouterString[1], "`index`", Map{"id": inData.Get("parent_id")})
|
||||||
|
inData["index"] = index.GetString("index") + ObjToStr(re) + ","
|
||||||
|
that.Db.Update(that.RouterString[1], Map{"index": inData["index"]}, Map{"id": re})
|
||||||
|
} else if inData.GetString("index") != "" {
|
||||||
|
inData["index"] = "," + ObjToStr(re) + ","
|
||||||
|
that.Db.Update(that.RouterString[1], Map{"index": inData["index"]}, Map{"id": re})
|
||||||
|
}
|
||||||
|
that.Log["table_id"] = re
|
||||||
|
that.Display(0, re)
|
||||||
|
},
|
||||||
|
"update": func(that *Context) {
|
||||||
|
|
||||||
|
that.Log = Map{"table": that.RouterString[1], "type": 2, "table_id": that.RouterString[2]}
|
||||||
|
|
||||||
|
hotimeName := that.RouterString[0]
|
||||||
|
inData := that.MakeCodeRouter[hotimeName].Edit(that.RouterString[1], that.Req)
|
||||||
|
|
||||||
|
if inData == nil {
|
||||||
|
that.Display(3, "没有找到要更新的数据")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//索引管理,便于检索以及权限
|
||||||
|
if inData.GetString("index") != "" {
|
||||||
|
if inData.Get("parent_id") != nil {
|
||||||
|
Index := that.Db.Get(that.RouterString[1], "`index`", Map{"id": that.RouterString[2]})
|
||||||
|
parentIndex := that.Db.Get(that.RouterString[1], "`index`", Map{"id": inData.Get("parent_id")})
|
||||||
|
inData["index"] = parentIndex.GetString("index") + that.RouterString[2] + ","
|
||||||
|
|
||||||
|
childNodes := that.Db.Select(that.RouterString[1], "id,`index``", Map{"index[~]": "," + that.RouterString[2] + ","})
|
||||||
|
|
||||||
|
for _, v := range childNodes {
|
||||||
|
v["index"] = strings.Replace(v.GetString("index"), Index.GetString("index"), inData.GetString("index"), -1)
|
||||||
|
that.Db.Update(that.RouterString[1], Map{"index": v["index"]}, Map{"id": v.GetCeilInt("id")})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
delete(inData, "index")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
re := that.Db.Update(that.RouterString[1], inData, Map{"id": that.RouterString[2]})
|
||||||
|
|
||||||
|
if re == 0 {
|
||||||
|
that.Display(4, "更新数据失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
that.Display(0, re)
|
||||||
|
},
|
||||||
|
"remove": func(that *Context) {
|
||||||
|
that.Log = Map{"table": that.RouterString[1], "type": 3, "table_id": that.RouterString[2]}
|
||||||
|
hotimeName := that.RouterString[0]
|
||||||
|
inData := that.MakeCodeRouter[hotimeName].Delete(that.RouterString[1], that.Req)
|
||||||
|
if inData == nil {
|
||||||
|
that.Display(3, "请求参数不足")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
re := int64(0)
|
||||||
|
//索引管理,便于检索以及权限
|
||||||
|
if inData.Get("parent_id") != nil && inData.GetSlice("index") != nil {
|
||||||
|
re = that.Db.Delete(that.RouterString[1], Map{"index[~]": "," + that.RouterString[2] + ","})
|
||||||
|
} else {
|
||||||
|
re = that.Db.Delete(that.RouterString[1], Map{"id": that.RouterString[2]})
|
||||||
|
}
|
||||||
|
|
||||||
|
if re == 0 {
|
||||||
|
that.Display(4, "删除数据失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
that.Display(0, "删除成功")
|
||||||
|
},
|
||||||
|
|
||||||
|
"search": func(that *Context) {
|
||||||
|
hotimeName := that.RouterString[0]
|
||||||
|
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
|
||||||
|
|
||||||
|
data := that.Db.Get(fileConfig.GetString("table"), "*", Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()})
|
||||||
|
|
||||||
|
columnStr, leftJoin, where := that.MakeCodeRouter[hotimeName].Search(that.RouterString[1], data, that.Req, that.Db)
|
||||||
|
|
||||||
|
page := ObjToInt(that.Req.FormValue("page"))
|
||||||
|
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
|
||||||
|
|
||||||
|
if page < 1 {
|
||||||
|
page = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if pageSize <= 0 {
|
||||||
|
pageSize = 20
|
||||||
|
}
|
||||||
|
|
||||||
|
count := that.Db.Count(that.RouterString[1], leftJoin, where)
|
||||||
|
reData := that.Db.Page(page, pageSize).
|
||||||
|
PageSelect(that.RouterString[1], leftJoin, columnStr, where)
|
||||||
|
|
||||||
|
for _, v := range reData {
|
||||||
|
v.RangeSort(func(k string, v1 interface{}) (isEnd bool) {
|
||||||
|
|
||||||
|
//如果有table字段则代为link
|
||||||
|
if v["table"] != nil && v["table_id"] != nil {
|
||||||
|
|
||||||
|
id := v.GetCeilInt64("table_id")
|
||||||
|
tableName := that.MakeCodeRouter[hotimeName].TableConfig.GetMap(v.GetString("table")).GetString("label")
|
||||||
|
v["table_table_name"] = strings.Replace(tableName, "管理", "", -1)
|
||||||
|
parentC := that.Db.Get(v.GetString("table"), "name", Map{"id": id})
|
||||||
|
v["table_table_id_name"] = ""
|
||||||
|
if parentC != nil {
|
||||||
|
v["table_table_id_name"] = parentC.GetString("name")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
column := that.MakeCodeRouter[hotimeName].TableColumns[that.RouterString[1]][k]
|
||||||
|
|
||||||
|
if column == nil {
|
||||||
|
return isEnd
|
||||||
|
}
|
||||||
|
|
||||||
|
if (column["list"] == nil || column["list"] == true) && column["name"] == "parent_id" && column.GetString("link") != "" {
|
||||||
|
|
||||||
|
parentC := that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v.GetCeilInt(k)})
|
||||||
|
v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = ""
|
||||||
|
if parentC != nil {
|
||||||
|
v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = parentC.GetString(column.GetString("value"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return isEnd
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
that.Display(0, Map{"count": count, "data": reData})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"hotime": Ctr{
|
||||||
|
"login": func(that *Context) {
|
||||||
|
hotimeName := that.RouterString[0]
|
||||||
|
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
|
||||||
|
|
||||||
|
name := that.Req.FormValue("name")
|
||||||
|
password := that.Req.FormValue("password")
|
||||||
|
if name == "" || password == "" {
|
||||||
|
that.Display(3, "参数不足")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
user := that.Db.Get(fileConfig.GetString("table"), "*", Map{"AND": Map{"OR": Map{"name": name, "phone": name}, "password": Md5(password)}})
|
||||||
|
|
||||||
|
if user == nil {
|
||||||
|
that.Display(5, "登录失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
that.Session(fileConfig.GetString("table")+"_id", user.GetCeilInt("id"))
|
||||||
|
that.Session(fileConfig.GetString("table")+"_name", name)
|
||||||
|
delete(user, "password")
|
||||||
|
that.Display(0, user)
|
||||||
|
},
|
||||||
|
"logout": func(that *Context) {
|
||||||
|
hotimeName := that.RouterString[0]
|
||||||
|
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
|
||||||
|
that.Session(fileConfig.GetString("table")+"_id", nil)
|
||||||
|
that.Session(fileConfig.GetString("table")+"_name", nil)
|
||||||
|
that.Display(0, "退出登录成功")
|
||||||
|
},
|
||||||
|
"info": func(that *Context) {
|
||||||
|
hotimeName := that.RouterString[0]
|
||||||
|
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
|
||||||
|
|
||||||
|
data := that.Db.Get(fileConfig.GetString("table"), "*", Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()})
|
||||||
|
str, inData := that.MakeCodeRouter[hotimeName].Info(fileConfig.GetString("table"), data, that.Db)
|
||||||
|
where := Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()}
|
||||||
|
if len(inData) == 1 {
|
||||||
|
inData["id"] = where["id"]
|
||||||
|
where = Map{"AND": inData}
|
||||||
|
} else if len(inData) > 1 {
|
||||||
|
where["OR"] = inData
|
||||||
|
where = Map{"AND": where}
|
||||||
|
}
|
||||||
|
re := that.Db.Get(fileConfig.GetString("table"), str, where)
|
||||||
|
if re == nil {
|
||||||
|
that.Display(4, "找不到对应信息")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for k, v := range re {
|
||||||
|
column := that.MakeCodeRouter[hotimeName].TableColumns[fileConfig.GetString("table")][k]
|
||||||
|
if column == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" {
|
||||||
|
|
||||||
|
//是角色表则取下角色值
|
||||||
|
if column.GetString("link") == "role" {
|
||||||
|
|
||||||
|
re[column.GetString("link")] = that.Db.Get(column.GetString("link"), "id,auth,"+column.GetString("value"), Map{"id": v})
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
re[column.GetString("link")] = that.Db.Get(column.GetString("link"), "id,"+column.GetString("value"), Map{"id": v})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
that.Display(0, re)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
+24
-9
@@ -1,19 +1,26 @@
|
|||||||
package code
|
package code
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "../common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Config = Map{
|
var Config = Map{
|
||||||
"name": "HoTimeDashBoard",
|
"name": "HoTimeDashBoard",
|
||||||
"id": "2f92h3herh23rh2y8",
|
"id": "2f92h3herh23rh2y8",
|
||||||
"label": "HoTime管理平台",
|
"label": "HoTime管理平台",
|
||||||
|
|
||||||
"menus": []Map{
|
"menus": []Map{
|
||||||
{"label": "平台首页", "name": "HelloWorld", "icon": "el-icon-s-home"},
|
{"label": "平台首页", "name": "HelloWorld", "icon": "el-icon-s-home"},
|
||||||
//{"label": "测试表格", "table": "table", "icon": "el-icon-suitcase"},
|
//{"label": "测试表格", "table": "table", "icon": "el-icon-suitcase"},
|
||||||
//{"label": "系统管理", "name": "setting", "icon": "el-icon-setting",
|
//{"label": "系统管理", "name": "setting", "icon": "el-icon-setting",
|
||||||
// "menus": []Map{
|
// "menus": []Map{
|
||||||
// {"label": "用户管理", "table": "user"},
|
// {"label": "用户管理", "table": "user",
|
||||||
|
// "default": {
|
||||||
|
// "path": "info",
|
||||||
|
// "id": "1"
|
||||||
|
// },
|
||||||
|
// "auth": ["show","edit","info","add","delete"],
|
||||||
|
// },
|
||||||
// {"label": "组织管理", "table": "organization"},
|
// {"label": "组织管理", "table": "organization"},
|
||||||
// {"label": "地区管理", "table": "area"},
|
// {"label": "地区管理", "table": "area"},
|
||||||
// {"label": "角色管理", "table": "role"},
|
// {"label": "角色管理", "table": "role"},
|
||||||
@@ -56,9 +63,13 @@ var ColumnNameType = []ColumnShow{
|
|||||||
//通用
|
//通用
|
||||||
{"idcard", false, true, true, false, "", false},
|
{"idcard", false, true, true, false, "", false},
|
||||||
{"id", true, false, true, false, "", true},
|
{"id", true, false, true, false, "", true},
|
||||||
|
{"parent_id", true, true, true, false, "", true},
|
||||||
|
{"amount", true, true, true, false, "money", true},
|
||||||
|
{"content", false, false, false, false, "textArea", false},
|
||||||
|
{"info", false, true, true, false, "textArea", false},
|
||||||
//"sn"{true,true,true,""},
|
//"sn"{true,true,true,""},
|
||||||
{"status", true, true, true, false, "select", false},
|
{"status", true, true, true, false, "select", false},
|
||||||
{"state", false, true, true, false, "select", false},
|
{"state", true, true, true, false, "select", false},
|
||||||
{"sex", true, true, true, false, "select", false},
|
{"sex", true, true, true, false, "select", false},
|
||||||
{"delete", false, false, false, false, "", false},
|
{"delete", false, false, false, false, "", false},
|
||||||
|
|
||||||
@@ -67,10 +78,10 @@ var ColumnNameType = []ColumnShow{
|
|||||||
{"latitude", false, true, true, false, "", false},
|
{"latitude", false, true, true, false, "", false},
|
||||||
{"longitude", false, true, true, false, "", false},
|
{"longitude", false, true, true, false, "", false},
|
||||||
|
|
||||||
{"index", false, false, false, false, "", false},
|
{"index", false, false, false, false, "index", false},
|
||||||
{"password", false, true, false, false, "password", false},
|
{"password", false, true, false, false, "password", false},
|
||||||
{"pwd", false, true, false, false, "password", false},
|
{"pwd", false, true, false, false, "password", false},
|
||||||
{"info", false, true, true, false, "", false},
|
|
||||||
{"version", false, false, false, false, "", false},
|
{"version", false, false, false, false, "", false},
|
||||||
{"seq", false, true, true, false, "", false},
|
{"seq", false, true, true, false, "", false},
|
||||||
{"sort", false, true, true, false, "", false},
|
{"sort", false, true, true, false, "", false},
|
||||||
@@ -78,16 +89,20 @@ var ColumnNameType = []ColumnShow{
|
|||||||
{"description", false, true, true, false, "", false},
|
{"description", false, true, true, false, "", false},
|
||||||
{"abstract", false, true, true, false, "", false},
|
{"abstract", false, true, true, false, "", false},
|
||||||
{"content", false, true, true, false, "", false},
|
{"content", false, true, true, false, "", false},
|
||||||
{"address", false, true, true, false, "", false},
|
{"address", true, true, true, false, "", false},
|
||||||
{"full_name", false, true, true, false, "", false},
|
{"full_name", false, true, true, false, "", false},
|
||||||
{"create_time", false, false, true, false, "", false},
|
{"create_time", false, false, true, false, "time", true},
|
||||||
{"modify_time", false, false, true, false, "", false},
|
{"modify_time", true, false, true, false, "time", true},
|
||||||
{"image", false, true, true, false, "image", false},
|
{"image", false, true, true, false, "image", false},
|
||||||
{"img", false, true, true, false, "image", false},
|
{"img", false, true, true, false, "image", false},
|
||||||
|
{"icon", false, true, true, false, "image", false},
|
||||||
{"avatar", false, true, true, false, "image", false},
|
{"avatar", false, true, true, false, "image", false},
|
||||||
{"file", false, true, true, false, "file", false},
|
{"file", false, true, true, false, "file", false},
|
||||||
{"age", false, true, true, false, "", false},
|
{"age", false, true, true, false, "", false},
|
||||||
{"email", false, true, true, false, "", false},
|
{"email", false, true, true, false, "", false},
|
||||||
{"time", true, false, true, false, "", false},
|
{"time", true, true, true, false, "time", false},
|
||||||
{"level", false, false, true, false, "", false},
|
{"level", false, false, true, false, "", false},
|
||||||
|
{"rule", true, true, true, false, "form", false},
|
||||||
|
{"table", true, false, true, false, "table", false},
|
||||||
|
{"table_id", true, false, true, false, "table_id", false},
|
||||||
}
|
}
|
||||||
|
|||||||
+408
-126
@@ -1,30 +1,34 @@
|
|||||||
package code
|
package code
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "../common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
"../db"
|
"code.hoteas.com/golang/hotime/db"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MakeCode struct {
|
type MakeCode struct {
|
||||||
|
FileConfig Map
|
||||||
IndexMenus Map
|
IndexMenus Map
|
||||||
TableConfig Map
|
TableConfig Map
|
||||||
TableColumns map[string]map[string]Map
|
TableColumns map[string]map[string]Map
|
||||||
SearchColumns map[string]map[string]Map
|
SearchColumns map[string]map[string]Map
|
||||||
Config Map
|
Config Map
|
||||||
|
RuleConfig []Map
|
||||||
Error
|
Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||||
isMake := false
|
isMake := false
|
||||||
idSlice := Slice{}
|
idSlice := Slice{}
|
||||||
|
that.FileConfig = config
|
||||||
if that.TableColumns == nil {
|
if that.TableColumns == nil {
|
||||||
that.TableColumns = make(map[string]map[string]Map)
|
that.TableColumns = make(map[string]map[string]Map)
|
||||||
}
|
}
|
||||||
@@ -33,20 +37,48 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//加载配置文件
|
//加载配置文件
|
||||||
btes, err := ioutil.ReadFile(path)
|
btes, err := ioutil.ReadFile(config.GetString("config"))
|
||||||
Config["name"] = name
|
|
||||||
that.Config = DeepCopyMap(Config).(Map)
|
that.Config = DeepCopyMap(Config).(Map)
|
||||||
|
|
||||||
|
that.Config["name"] = config.GetString("table")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
cmap := Map{}
|
cmap := Map{}
|
||||||
//文件是否损坏
|
//文件是否损坏
|
||||||
cmap.JsonToMap(string(btes), &that.Error)
|
cmap.JsonToMap(string(btes), &that.Error)
|
||||||
for k, v := range cmap {
|
for k, v := range cmap {
|
||||||
that.Config[k] = v //程序配置
|
that.Config[k] = v //程序配置
|
||||||
Config[k] = v //系统配置
|
//Config[k] = v //系统配置
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
that.Error.SetError(errors.New("配置文件不存在,或者配置出错,使用缺省默认配置"))
|
that.Error.SetError(errors.New("config配置文件不存在,或者配置出错,使用缺省默认配置"))
|
||||||
}
|
}
|
||||||
|
//加载规则文件
|
||||||
|
btesRule, errRule := ioutil.ReadFile(config.GetString("rule"))
|
||||||
|
that.RuleConfig = []Map{}
|
||||||
|
if errRule == nil {
|
||||||
|
//cmap := Map{}
|
||||||
|
//文件是否损坏
|
||||||
|
ruleLis := ObjToSlice(string(btesRule), &that.Error)
|
||||||
|
//cmap.JSON()
|
||||||
|
for k, _ := range ruleLis {
|
||||||
|
that.RuleConfig = append(that.RuleConfig, ruleLis.GetMap(k))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for _, v := range ColumnNameType {
|
||||||
|
that.RuleConfig = append(that.RuleConfig, Map{"name": v.Name, "list": v.List, "edit": v.Edit, "info": v.Info, "must": v.Must, "strict": v.Strict, "type": v.Type})
|
||||||
|
}
|
||||||
|
if db != nil {
|
||||||
|
_ = os.MkdirAll(filepath.Dir(config.GetString("rule")), os.ModeDir)
|
||||||
|
err = ioutil.WriteFile(config.GetString("rule"), []byte(ObjToStr(that.RuleConfig)), os.ModePerm)
|
||||||
|
if err != nil {
|
||||||
|
that.Error.SetError(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
that.Error.SetError(errors.New("rule配置文件不存在,或者配置出错,使用缺省默认配置"))
|
||||||
|
}
|
||||||
|
|
||||||
that.IndexMenus = Map{}
|
that.IndexMenus = Map{}
|
||||||
menusConfig := that.Config.GetSlice("menus")
|
menusConfig := that.Config.GetSlice("menus")
|
||||||
//将配置写入到内存中仅作为判断用
|
//将配置写入到内存中仅作为判断用
|
||||||
@@ -112,13 +144,13 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if db==nil{
|
if db == nil {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//数据库反哺
|
//数据库反哺
|
||||||
myInit := strings.Replace(InitTpt, "{{name}}", name, -1)
|
myInit := strings.Replace(InitTpt, "{{name}}", config.GetString("table"), -1)
|
||||||
ctrList := ""
|
ctrList := ""
|
||||||
|
|
||||||
nowTables := make([]Map, 0)
|
nowTables := make([]Map, 0)
|
||||||
@@ -140,30 +172,17 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
|||||||
that.TableConfig[v.GetString("name")] = Map{
|
that.TableConfig[v.GetString("name")] = Map{
|
||||||
"label": v.GetString("label"),
|
"label": v.GetString("label"),
|
||||||
"table": v.GetString("name"),
|
"table": v.GetString("name"),
|
||||||
"auth": []string{"add", "delete", "edit", "info"},
|
"auth": []string{"show", "add", "delete", "edit", "info"},
|
||||||
"columns": []Map{},
|
"columns": []Map{},
|
||||||
"search": []Map{
|
"search": []Map{
|
||||||
//{"type": "tree", "name": "oid", "label": "组织", "table": "organization", "showName": "label", "children": "children"},
|
|
||||||
{"type": "search", "name": "keyword", "label": "请输入关键词", "value": nil},
|
{"type": "search", "name": "keyword", "label": "请输入关键词", "value": nil},
|
||||||
{"type": "search", "name": "daterange", "label": "时间段", "value": nil},
|
{"type": "search", "name": "daterange", "label": "时间段", "value": nil},
|
||||||
{"type": "search", "name": "sort", "label": "排序", "value": nil},
|
{"type": "search", "name": "sort", "label": "排序", "value": nil},
|
||||||
//{"type": "select", "name": "state", "label": "状态", "value": nil,
|
|
||||||
// "options": []Map{
|
|
||||||
// {"name": "正常", "value": 0},
|
|
||||||
// {"name": "异常", "value": 1},
|
|
||||||
// {"name": "全部", "value": nil},
|
|
||||||
// },
|
|
||||||
//},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//else {
|
|
||||||
// if !(that.TableConfig.GetMap(v.GetString("name")).GetString("label") != "备注" &&
|
|
||||||
// v.GetString("label") == "备注") {
|
|
||||||
// that.TableConfig.GetMap(v.GetString("name"))["label"] = v.GetString("label")
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
//初始化
|
//初始化
|
||||||
if that.TableColumns[v.GetString("name")] == nil {
|
if that.TableColumns[v.GetString("name")] == nil {
|
||||||
that.TableColumns[v.GetString("name")] = make(map[string]Map)
|
that.TableColumns[v.GetString("name")] = make(map[string]Map)
|
||||||
@@ -183,7 +202,8 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
idSlice = append(idSlice, tableInfo)
|
idSlice = append(idSlice, tableInfo)
|
||||||
for _, info := range tableInfo {
|
for _, info1 := range tableInfo {
|
||||||
|
info := DeepCopyMap(info1).(Map)
|
||||||
if info.GetString("label") == "" {
|
if info.GetString("label") == "" {
|
||||||
info["label"] = info.GetString("name")
|
info["label"] = info.GetString("name")
|
||||||
}
|
}
|
||||||
@@ -191,10 +211,9 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
|||||||
|
|
||||||
if coloum == nil {
|
if coloum == nil {
|
||||||
//根据类型判断真实类型
|
//根据类型判断真实类型
|
||||||
for k, v := range ColumnDataType {
|
for k, v1 := range ColumnDataType {
|
||||||
if strings.Contains(info.GetString("type"), k) || strings.Contains(info.GetString("name"), k) {
|
if strings.Contains(info.GetString("name"), k) || strings.Contains(info.GetString("type"), k) {
|
||||||
info["type"] = v
|
info["type"] = v1
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,36 +224,57 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
|||||||
//"add": false, "info": false, "edit": false, "list": true,
|
//"add": false, "info": false, "edit": false, "list": true,
|
||||||
//"must": false,
|
//"must": false,
|
||||||
}
|
}
|
||||||
|
|
||||||
//备注以空格隔开,空格后的是其他备注
|
//备注以空格隔开,空格后的是其他备注
|
||||||
indexNum := strings.Index(info.GetString("label"), ":")
|
indexNum := strings.Index(info.GetString("label"), " ")
|
||||||
if indexNum > 0 {
|
if indexNum > -1 {
|
||||||
coloum["label"] = info.GetString("label")[:indexNum]
|
coloum["label"] = info.GetString("label")[:indexNum]
|
||||||
}
|
}
|
||||||
|
//去除数据信息,是用:号分割的
|
||||||
|
indexNum = strings.Index(coloum.GetString("label"), ":")
|
||||||
|
if indexNum > -1 {
|
||||||
|
coloum["label"] = coloum.GetString("label")[:indexNum]
|
||||||
|
}
|
||||||
|
|
||||||
for _, v := range ColumnNameType {
|
for _, ColumnName := range that.RuleConfig {
|
||||||
if (v.Strict && coloum.GetString("name") == v.Name) || (!v.Strict && strings.Contains(coloum.GetString("name"), v.Name)) {
|
if (ColumnName.GetBool("strict") && coloum.GetString("name") == ColumnName.GetString("name")) ||
|
||||||
|
(!ColumnName.GetBool("strict") && strings.Contains(coloum.GetString("name"), ColumnName.GetString("name"))) {
|
||||||
//全部都不需要则不加入
|
//全部都不需要则不加入
|
||||||
if v.Edit == false && v.List == false && v.Info == false {
|
if ColumnName.GetBool("edit") == false && ColumnName.GetBool("list") == false && ColumnName.GetBool("info") == false {
|
||||||
coloum["notUse"] = true
|
coloum["notUse"] = true
|
||||||
|
//continue
|
||||||
|
}
|
||||||
|
coloum["info"] = ColumnName.GetBool("info")
|
||||||
|
coloum["edit"] = ColumnName.GetBool("edit")
|
||||||
|
coloum["add"] = ColumnName.GetBool("edit")
|
||||||
|
coloum["list"] = ColumnName.GetBool("list")
|
||||||
|
coloum["must"] = ColumnName.GetBool("must")
|
||||||
|
|
||||||
|
if ColumnName.GetBool("info") {
|
||||||
|
delete(coloum, "info")
|
||||||
|
}
|
||||||
|
if ColumnName.GetBool("edit") {
|
||||||
|
delete(coloum, "edit")
|
||||||
|
delete(coloum, "add")
|
||||||
|
}
|
||||||
|
if ColumnName.GetBool("list") {
|
||||||
|
delete(coloum, "list")
|
||||||
|
}
|
||||||
|
if !ColumnName.GetBool("must") {
|
||||||
|
delete(coloum, "must")
|
||||||
|
}
|
||||||
|
|
||||||
|
if ColumnName.GetString("type") != "" {
|
||||||
|
if ColumnName.GetString("type") == "time" && coloum["type"] == "number" {
|
||||||
|
coloum["type"] = "unixTime"
|
||||||
|
} else {
|
||||||
|
coloum["type"] = ColumnName.GetString("type")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ColumnName.GetBool("strict") && coloum.GetString("name") == ColumnName.GetString("name") {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if v.Info == false {
|
|
||||||
coloum["info"] = v.Info
|
|
||||||
}
|
|
||||||
if v.Edit == false {
|
|
||||||
coloum["edit"] = v.Edit
|
|
||||||
coloum["add"] = v.Edit
|
|
||||||
}
|
|
||||||
if v.List == false {
|
|
||||||
coloum["list"] = v.List
|
|
||||||
}
|
|
||||||
if v.Must == true {
|
|
||||||
coloum["must"] = v.Must
|
|
||||||
}
|
|
||||||
if v.Type != "" {
|
|
||||||
coloum["type"] = v.Type
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,9 +283,9 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
|||||||
coloum["sortable"] = true
|
coloum["sortable"] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if !coloum.GetBool("notUse") {
|
//if !coloum.GetBool("notUse") {
|
||||||
that.TableConfig.GetMap(v.GetString("name"))["columns"] = append(that.TableConfig.GetMap(v.GetString("name")).GetSlice("columns"), coloum)
|
that.TableConfig.GetMap(v.GetString("name"))["columns"] = append(that.TableConfig.GetMap(v.GetString("name")).GetSlice("columns"), coloum)
|
||||||
}
|
//}
|
||||||
//如果是select类型需要设置options
|
//如果是select类型需要设置options
|
||||||
//if coloum.GetString("type") == "select" {
|
//if coloum.GetString("type") == "select" {
|
||||||
|
|
||||||
@@ -262,10 +302,10 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if coloum.GetString("type") == "select" {
|
if coloum.GetString("type") == "select" {
|
||||||
coloum["must"] = true
|
//coloum["must"] = true
|
||||||
coloum["options"] = options
|
coloum["options"] = options
|
||||||
} else if len(options) > 0 {
|
} else if len(options) > 0 {
|
||||||
coloum["must"] = true
|
//coloum["must"] = true
|
||||||
coloum["options"] = options
|
coloum["options"] = options
|
||||||
coloum["type"] = "select"
|
coloum["type"] = "select"
|
||||||
|
|
||||||
@@ -286,22 +326,25 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//创建模块文件
|
if config.GetInt("mode") != 0 {
|
||||||
//判断文件是否存在
|
//创建模块文件
|
||||||
//_, err := os.OpenFile(name+"/"+v.GetString("name"), os.O_RDONLY, os.ModePerm)
|
//判断文件是否存在
|
||||||
_, err := os.Stat(name + "/" + v.GetString("name") + ".go")
|
//_, err := os.OpenFile(name+"/"+v.GetString("name"), os.O_RDONLY, os.ModePerm)
|
||||||
if err != nil { //文件不存在,则根据模板创建
|
_, err := os.Stat(config.GetString("name") + "/" + v.GetString("name") + ".go")
|
||||||
myCtr := strings.Replace(CtrTpt, "{{name}}", name, -1)
|
if err != nil { //文件不存在,则根据模板创建
|
||||||
myCtr = strings.Replace(myCtr, "{{table}}", v.GetString("name"), -1)
|
myCtr := strings.Replace(CtrTpt, "{{name}}", config.GetString("name"), -1)
|
||||||
_ = os.MkdirAll(name, os.ModeDir)
|
myCtr = strings.Replace(myCtr, "{{table}}", v.GetString("name"), -1)
|
||||||
err = ioutil.WriteFile(name+"/"+v.GetString("name")+".go", []byte(myCtr), os.ModePerm)
|
_ = os.MkdirAll(config.GetString("name"), os.ModeDir)
|
||||||
if err != nil {
|
err = ioutil.WriteFile(config.GetString("name")+"/"+v.GetString("name")+".go", []byte(myCtr), os.ModePerm)
|
||||||
that.Error.SetError(err)
|
if err != nil {
|
||||||
|
that.Error.SetError(err)
|
||||||
|
}
|
||||||
|
isMake = true
|
||||||
}
|
}
|
||||||
isMake = true
|
|
||||||
}
|
|
||||||
|
|
||||||
ctrList = ctrList + `"` + v.GetString("name") + `":` + v.GetString("name") + "Ctr,\r\n "
|
ctrList = ctrList + `"` + v.GetString("name") + `":` + v.GetString("name") + "Ctr,\r\n "
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,7 +352,6 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
|||||||
|
|
||||||
//生成id,判断数据库是否有改变,以保证数据库和配置文件匹配唯一
|
//生成id,判断数据库是否有改变,以保证数据库和配置文件匹配唯一
|
||||||
id := Md5(ObjToStr(idSlice))
|
id := Md5(ObjToStr(idSlice))
|
||||||
|
|
||||||
if id == that.Config.GetString("id") {
|
if id == that.Config.GetString("id") {
|
||||||
if isMake { //有生成包文件
|
if isMake { //有生成包文件
|
||||||
fmt.Println("有新的业务代码生成,请重新运行")
|
fmt.Println("有新的业务代码生成,请重新运行")
|
||||||
@@ -324,6 +366,10 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
|||||||
isMenusGet := false //判断是否被目录收录
|
isMenusGet := false //判断是否被目录收录
|
||||||
for indexKey, _ := range that.IndexMenus {
|
for indexKey, _ := range that.IndexMenus {
|
||||||
indexCode := strings.Index(indexKey, fk)
|
indexCode := strings.Index(indexKey, fk)
|
||||||
|
if indexCode == 0 || indexCode == 4 {
|
||||||
|
isMenusGet = false
|
||||||
|
continue
|
||||||
|
}
|
||||||
//如果相等或者表名在目录中已经设置(主要前一位是/并且他是最后一个字符串)
|
//如果相等或者表名在目录中已经设置(主要前一位是/并且他是最后一个字符串)
|
||||||
if indexKey == fk || (indexCode != -1 && indexKey[indexCode-1] == '/' && indexKey[indexCode:] == fk) {
|
if indexKey == fk || (indexCode != -1 && indexKey[indexCode-1] == '/' && indexKey[indexCode:] == fk) {
|
||||||
isMenusGet = true
|
isMenusGet = true
|
||||||
@@ -340,16 +386,21 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
|||||||
//并且代表有前缀,根据数据表分库设定使用
|
//并且代表有前缀,根据数据表分库设定使用
|
||||||
if tablePrefixCode != -1 {
|
if tablePrefixCode != -1 {
|
||||||
prefixName = fk[:tablePrefixCode]
|
prefixName = fk[:tablePrefixCode]
|
||||||
|
} else {
|
||||||
|
prefixName = fk
|
||||||
}
|
}
|
||||||
if tablePrefixCode != -1 {
|
//if tablePrefixCode != -1 {
|
||||||
for ck, _ := range that.TableColumns {
|
for ck, _ := range that.TableColumns {
|
||||||
//判断不止一个前缀相同
|
//判断不止一个前缀相同
|
||||||
if strings.Index(ck, prefixName) == 0 && ck != prefixName && ck != fk {
|
if (strings.Index(ck, prefixName) == 0 || strings.Index(prefixName, ck) == 4) && ck != fk {
|
||||||
isNewPrefix = true
|
isNewPrefix = true
|
||||||
break
|
break
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//}
|
||||||
|
|
||||||
|
prefixName = DefaultMenuParentName + ":" + prefixName
|
||||||
|
|
||||||
menuIns := Map{"label": that.TableConfig.GetMap(fk).GetString("label"), "table": fk}
|
menuIns := Map{"label": that.TableConfig.GetMap(fk).GetString("label"), "table": fk}
|
||||||
//多耗费一点内存
|
//多耗费一点内存
|
||||||
mMenu := Map{"menus": Slice{menuIns}, "label": that.TableConfig.GetMap(fk).GetString("label"), "name": prefixName, "icon": "el-icon-setting"}
|
mMenu := Map{"menus": Slice{menuIns}, "label": that.TableConfig.GetMap(fk).GetString("label"), "name": prefixName, "icon": "el-icon-setting"}
|
||||||
@@ -361,8 +412,15 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
|||||||
}
|
}
|
||||||
//没有新前缀
|
//没有新前缀
|
||||||
if that.IndexMenus[prefixName] != nil {
|
if that.IndexMenus[prefixName] != nil {
|
||||||
that.IndexMenus.GetMap(prefixName)["menus"] = append(that.IndexMenus.GetMap(prefixName).GetSlice("menus"), menuIns)
|
if that.IndexMenus[prefixName+"/"+fk] == nil {
|
||||||
that.IndexMenus[prefixName+"/"+fk] = menuIns
|
that.IndexMenus.GetMap(prefixName)["menus"] = append(that.IndexMenus.GetMap(prefixName).GetSlice("menus"), menuIns)
|
||||||
|
that.IndexMenus[prefixName+"/"+fk] = menuIns
|
||||||
|
} else {
|
||||||
|
for k, v := range menuIns {
|
||||||
|
that.IndexMenus.GetMap(prefixName + "/" + fk)[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
that.Config["menus"] = append(that.Config.GetSlice("menus"), mMenu) //注入配置
|
that.Config["menus"] = append(that.Config.GetSlice("menus"), mMenu) //注入配置
|
||||||
@@ -395,23 +453,29 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
|||||||
if oldTableName == "parent" {
|
if oldTableName == "parent" {
|
||||||
oldTableName = fk
|
oldTableName = fk
|
||||||
}
|
}
|
||||||
|
//如果本身匹配则不再继续精简匹配
|
||||||
|
if that.TableConfig[oldTableName] == nil {
|
||||||
|
|
||||||
//如果依然找不到则查询system_org是否存在
|
//如果依然找不到则查询system_org是否存在
|
||||||
if that.TableConfig[DefaultMenuParentName+"_"+oldTableName] != nil {
|
if that.TableConfig[DefaultMenuParentName+"_"+oldTableName] != nil {
|
||||||
oldTableName = DefaultMenuParentName + "_" + oldTableName
|
oldTableName = DefaultMenuParentName + "_" + oldTableName
|
||||||
}
|
}
|
||||||
|
|
||||||
//字段有动词前缀,自动进行解析
|
//字段有动词前缀,自动进行解析
|
||||||
prefixColumn := strings.Index(oldTableName, "_")
|
prefixColumn := strings.Index(oldTableName, "_")
|
||||||
|
|
||||||
//sys_org_id oldTableName即为sys此处判断为org表存在
|
//sys_org_id oldTableName即为sys此处判断为org表存在
|
||||||
|
|
||||||
if prefixColumn > -1 && that.TableConfig[oldTableName[prefixColumn+1:]] != nil {
|
if prefixColumn > -1 && that.TableConfig[oldTableName[prefixColumn+1:]] != nil {
|
||||||
oldTableName = oldTableName[prefixColumn+1:]
|
oldTableName = oldTableName[prefixColumn+1:]
|
||||||
}
|
}
|
||||||
//如果依然找不到则查询system_org是否存在
|
if prefixColumn >= len(oldTableName) {
|
||||||
if prefixColumn > -1 && that.TableConfig[DefaultMenuParentName+"_"+oldTableName[prefixColumn+1:]] != nil {
|
prefixColumn = -1
|
||||||
oldTableName = DefaultMenuParentName + "_" + oldTableName[prefixColumn+1:]
|
}
|
||||||
|
//如果依然找不到则查询system_org是否存在
|
||||||
|
if prefixColumn > -1 && that.TableConfig[DefaultMenuParentName+"_"+oldTableName[prefixColumn+1:]] != nil {
|
||||||
|
oldTableName = DefaultMenuParentName + "_" + oldTableName[prefixColumn+1:]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//普通方式查询不到,则转换为大型项目模块划分,暂时只支持一级模块划分,
|
//普通方式查询不到,则转换为大型项目模块划分,暂时只支持一级模块划分,
|
||||||
@@ -448,8 +512,17 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
|||||||
v["value"] = "label"
|
v["value"] = "label"
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
tempC := that.TableConfig.GetMap(tableName).GetSlice("columns")
|
||||||
|
isGet := true
|
||||||
|
for k2, _ := range tempC {
|
||||||
|
if strings.Contains(tempC.GetMap(k2).GetString("name"), "name") || strings.Contains(tempC.GetMap(k2).GetString("name"), "title") {
|
||||||
|
v["value"] = tempC.GetMap(k2).GetString("name")
|
||||||
|
isGet = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if len(that.TableConfig.GetMap(tableName).GetSlice("columns")) > 2 {
|
if isGet && len(that.TableConfig.GetMap(tableName).GetSlice("columns")) > 2 {
|
||||||
v["value"] = that.TableConfig.GetMap(tableName).GetSlice("columns").GetMap(1).GetString("name")
|
v["value"] = that.TableConfig.GetMap(tableName).GetSlice("columns").GetMap(1).GetString("name")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -476,33 +549,80 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
|||||||
|
|
||||||
fmt.Println(id, "---", that.Config.GetString("id"))
|
fmt.Println(id, "---", that.Config.GetString("id"))
|
||||||
that.Config["id"] = id
|
that.Config["id"] = id
|
||||||
//init文件初始化
|
|
||||||
myInit = strings.Replace(myInit, "{{id}}", id, -1)
|
|
||||||
myInit = strings.Replace(myInit, "{{tablesCtr}}", ctrList, -1)
|
|
||||||
_ = os.MkdirAll(name, os.ModeDir)
|
|
||||||
err = ioutil.WriteFile(name+"/init.go", []byte(myInit), os.ModePerm)
|
|
||||||
if err != nil {
|
|
||||||
that.Error.SetError(err)
|
|
||||||
}
|
|
||||||
//写入配置文件
|
|
||||||
//var configByte bytes.Buffer
|
|
||||||
|
|
||||||
|
if config.GetInt("mode") != 0 {
|
||||||
|
//init文件初始化
|
||||||
|
myInit = strings.Replace(myInit, "{{id}}", id, -1)
|
||||||
|
myInit = strings.Replace(myInit, "{{tablesCtr}}", ctrList, -1)
|
||||||
|
_ = os.MkdirAll(config.GetString("name"), os.ModeDir)
|
||||||
|
err = ioutil.WriteFile(config.GetString("name")+"/init.go", []byte(myInit), os.ModePerm)
|
||||||
|
if err != nil {
|
||||||
|
that.Error.SetError(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//写入配置文件
|
||||||
//err = json.Indent(&configByte, []byte(that.Config.ToJsonString()), "", "\t")
|
//err = json.Indent(&configByte, []byte(that.Config.ToJsonString()), "", "\t")
|
||||||
_ = os.MkdirAll(filepath.Dir(path), os.ModeDir)
|
_ = os.MkdirAll(filepath.Dir(config.GetString("config")), os.ModeDir)
|
||||||
err = ioutil.WriteFile(path, []byte(that.Config.ToJsonString()), os.ModePerm)
|
err = ioutil.WriteFile(config.GetString("config"), []byte(that.Config.ToJsonString()), os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
that.Error.SetError(err)
|
that.Error.SetError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("有新的代码生成,请重新运行")
|
fmt.Println("有新的代码生成,请重新运行")
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (that *MakeCode) Info(table string) string {
|
func (that *MakeCode) Info(table string, userData Map, db *db.HoTimeDB) (string, Map) {
|
||||||
reStr := ""
|
reStr := ""
|
||||||
for _, v := range that.TableColumns[table] {
|
data := Map{}
|
||||||
|
var ruleData Map
|
||||||
|
testQu := []string{}
|
||||||
|
testQuData := that.TableColumns[table]
|
||||||
|
for key, _ := range testQuData {
|
||||||
|
//fmt.Println(key, ":", value)
|
||||||
|
testQu = append(testQu, key)
|
||||||
|
}
|
||||||
|
sort.Strings(testQu)
|
||||||
|
|
||||||
|
for _, k := range testQu {
|
||||||
|
v := testQuData[k]
|
||||||
if v == nil {
|
if v == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
//准备加入索引权限
|
||||||
|
if v.GetString("link") != "" &&
|
||||||
|
userData != nil &&
|
||||||
|
that.TableColumns[v.GetString("link")]["parent_id"] != nil {
|
||||||
|
//初始化ruleData
|
||||||
|
if ruleData == nil {
|
||||||
|
ruleData = Map{}
|
||||||
|
for _, v := range that.TableColumns[that.FileConfig.GetString("table")] {
|
||||||
|
if v.GetString("link") != "" &&
|
||||||
|
v.GetString("name") != "parent_id" &&
|
||||||
|
userData.Get(v.GetString("name")) != nil {
|
||||||
|
ruleData[v.GetString("link")] = userData.Get(v.GetString("name"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ruleData[v.GetString("link")] != nil {
|
||||||
|
|
||||||
|
if v.GetString("name") == "parent_id" {
|
||||||
|
data["index[~]"] = "," + ruleData.GetString(v.GetString("link")) + ","
|
||||||
|
|
||||||
|
} else {
|
||||||
|
idMap := db.Select(v.GetString("link"), "id", Map{"index[~]": "," + ruleData.GetString(v.GetString("link")) + ","})
|
||||||
|
ids := Slice{ruleData.GetCeilInt(v.GetString("link"))}
|
||||||
|
for _, v := range idMap {
|
||||||
|
ids = append(ids, v.GetCeilInt("id"))
|
||||||
|
}
|
||||||
|
data[v.GetString("name")] = ids
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if v.Get("info") == nil || v.GetBool("info") {
|
if v.Get("info") == nil || v.GetBool("info") {
|
||||||
reStr += "`" + v.GetString("name") + "`,"
|
reStr += "`" + v.GetString("name") + "`,"
|
||||||
}
|
}
|
||||||
@@ -510,19 +630,39 @@ func (that *MakeCode) Info(table string) string {
|
|||||||
if len(reStr) != 0 {
|
if len(reStr) != 0 {
|
||||||
reStr = reStr[:len(reStr)-1]
|
reStr = reStr[:len(reStr)-1]
|
||||||
}
|
}
|
||||||
return reStr
|
return reStr, data
|
||||||
}
|
}
|
||||||
func (that *MakeCode) Add(table string, req *http.Request) Map {
|
func (that *MakeCode) Add(table string, user Map, req *http.Request) Map {
|
||||||
data := Map{}
|
data := Map{}
|
||||||
for _, v := range that.TableColumns[table] {
|
for _, v := range that.TableColumns[table] {
|
||||||
//不可使用,未在前端展示,但在内存中保持有
|
//不可使用,未在前端展示,但在内存中保持有
|
||||||
if v.GetBool("notUse") {
|
if v.GetBool("notUse") {
|
||||||
|
if v.GetString("type") == "index" && that.TableColumns[table]["parent_id"] != nil {
|
||||||
|
data[v.GetString("name")] = ","
|
||||||
|
}
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if v.Get("add") == nil || v.GetBool("add") {
|
if v.Get("add") == nil || v.GetBool("add") {
|
||||||
|
|
||||||
if len(req.Form[v.GetString("name")]) == 0 {
|
if len(req.Form[v.GetString("name")]) == 0 {
|
||||||
return nil
|
|
||||||
|
if user[v.GetString("name")] != nil {
|
||||||
|
data[v.GetString("name")] = user[v.GetString("name")]
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if that.FileConfig.GetString("table")+"_id" == v.GetString("name") {
|
||||||
|
data[v.GetString("name")] = user["id"]
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.GetBool("must") {
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
reqValue := req.FormValue(v.GetString("name"))
|
reqValue := req.FormValue(v.GetString("name"))
|
||||||
if (reqValue == "" || reqValue == "null") && strings.Contains(v.GetString("name"), "id") {
|
if (reqValue == "" || reqValue == "null") && strings.Contains(v.GetString("name"), "id") {
|
||||||
@@ -535,7 +675,25 @@ func (that *MakeCode) Add(table string, req *http.Request) Map {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.GetString("name") == "create_time" {
|
||||||
|
if v.GetString("type") == "unixTime" {
|
||||||
|
data[v.GetString("name")] = time.Now().Unix()
|
||||||
|
}
|
||||||
|
if v.GetString("type") == "time" {
|
||||||
|
data[v.GetString("name")] = time.Now().Format("2006-01-02 15-04-05")
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.GetString("name") == "modify_time" {
|
||||||
|
if v.GetString("type") == "unixTime" {
|
||||||
|
data[v.GetString("name")] = time.Now().Unix()
|
||||||
|
}
|
||||||
|
if v.GetString("type") == "time" {
|
||||||
|
data[v.GetString("name")] = time.Now().Format("2006-01-02 15-04-05")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
@@ -549,8 +707,12 @@ func (that *MakeCode) Edit(table string, req *http.Request) Map {
|
|||||||
for _, v := range that.TableColumns[table] {
|
for _, v := range that.TableColumns[table] {
|
||||||
//不可使用,未在前端展示,但在内存中保持有
|
//不可使用,未在前端展示,但在内存中保持有
|
||||||
if v.GetBool("notUse") {
|
if v.GetBool("notUse") {
|
||||||
|
if v.GetString("type") == "index" && that.TableColumns[table]["parent_id"] != nil {
|
||||||
|
data[v.GetString("name")] = ","
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.Get("edit") == nil || v.GetBool("edit") {
|
if v.Get("edit") == nil || v.GetBool("edit") {
|
||||||
reqValue := req.FormValue(v.GetString("name"))
|
reqValue := req.FormValue(v.GetString("name"))
|
||||||
if reqValue == "" || reqValue == "null" {
|
if reqValue == "" || reqValue == "null" {
|
||||||
@@ -562,6 +724,9 @@ func (that *MakeCode) Edit(table string, req *http.Request) Map {
|
|||||||
data[v.GetString("name")] = reqValue
|
data[v.GetString("name")] = reqValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if v.GetString("name") == "modify_time" {
|
||||||
|
data[v.GetString("name")] = time.Now().Unix()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
@@ -570,19 +735,46 @@ func (that *MakeCode) Edit(table string, req *http.Request) Map {
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
func (that *MakeCode) Delete(table string, req *http.Request) Map {
|
||||||
|
data := Map{}
|
||||||
|
for _, v := range that.TableColumns[table] {
|
||||||
|
//不可使用,未在前端展示,但在内存中保持有
|
||||||
|
if v.GetBool("notUse") {
|
||||||
|
if v.GetString("type") == "index" && that.TableColumns[table]["parent_id"] != nil {
|
||||||
|
data[v.GetString("name")] = ","
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (string, Map, Map) {
|
}
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *db.HoTimeDB) (string, Map, Map) {
|
||||||
reStr := ""
|
reStr := ""
|
||||||
leftJoin := Map{}
|
leftJoin := Map{}
|
||||||
data := Map{}
|
data := Map{}
|
||||||
keyword := Map{}
|
keyword := Map{}
|
||||||
daterange := Map{}
|
daterange := Map{}
|
||||||
sort := Map{}
|
sortMap := Map{}
|
||||||
|
var ruleData Map
|
||||||
|
hasUser := false
|
||||||
|
|
||||||
keywordStr := req.FormValue("keyword")
|
keywordStr := req.FormValue("keyword")
|
||||||
for _, v := range that.TableColumns[table] {
|
|
||||||
|
testQu := []string{}
|
||||||
|
testQuData := that.TableColumns[table]
|
||||||
|
for key, _ := range testQuData {
|
||||||
|
//fmt.Println(key, ":", value)
|
||||||
|
testQu = append(testQu, key)
|
||||||
|
}
|
||||||
|
sort.Strings(testQu)
|
||||||
|
|
||||||
|
for _, k := range testQu {
|
||||||
|
v := testQuData[k]
|
||||||
//不可使用,未在前端展示,但在内存中保持有
|
//不可使用,未在前端展示,但在内存中保持有
|
||||||
if v.GetBool("notUse") {
|
if v.GetBool("notUse") {
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if v["list"] != false {
|
if v["list"] != false {
|
||||||
@@ -590,17 +782,69 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (
|
|||||||
if v.GetString("link") != "" &&
|
if v.GetString("link") != "" &&
|
||||||
v.GetString("name") != "parent_id" {
|
v.GetString("name") != "parent_id" {
|
||||||
|
|
||||||
reStr += v.GetString("link") + "." +
|
reStr += table + "." + v.GetString("name") + "," +
|
||||||
v.GetString("value") + " AS " +
|
v.GetString("link") + "." + v.GetString("value") + " AS " +
|
||||||
v.GetString("link") + "_" + v.GetString("name") + "_" + v.GetString("value") + ","
|
v.GetString("link") + "_" + v.GetString("name") + "_" + v.GetString("value") + ","
|
||||||
|
|
||||||
|
if v.GetString("value") == "name" && that.TableColumns[v.GetString("link")]["nickname"] != nil {
|
||||||
|
reStr += v.GetString("link") + ".nickname AS " +
|
||||||
|
v.GetString("link") + "_" + v.GetString("name") + "_nickname,"
|
||||||
|
}
|
||||||
|
|
||||||
|
if that.TableColumns[v.GetString("link")]["phone"] != nil {
|
||||||
|
reStr += v.GetString("link") + ".phone AS " +
|
||||||
|
v.GetString("link") + "_" + v.GetString("name") + "_phone,"
|
||||||
|
}
|
||||||
|
|
||||||
leftJoin["[>]"+v.GetString("link")] =
|
leftJoin["[>]"+v.GetString("link")] =
|
||||||
table + "." + v.GetString("name") + "=" +
|
table + "." + v.GetString("name") + "=" +
|
||||||
v.GetString("link") + ".id"
|
v.GetString("link") + ".id"
|
||||||
|
if v.GetString("link") == "admin" {
|
||||||
|
hasUser = true
|
||||||
|
}
|
||||||
|
|
||||||
|
reqValue := req.FormValue(v.GetString("name"))
|
||||||
|
if reqValue != "" {
|
||||||
|
data[table+"."+v.GetString("name")] = reqValue
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
reStr += table + "." + v.GetString("name") + ","
|
reStr += table + "." + v.GetString("name") + ","
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//准备加入索引权限
|
||||||
|
if v.GetString("link") != "" &&
|
||||||
|
userData != nil &&
|
||||||
|
that.TableColumns[v.GetString("link")]["parent_id"] != nil {
|
||||||
|
//初始化ruleData
|
||||||
|
if ruleData == nil {
|
||||||
|
ruleData = Map{}
|
||||||
|
for _, v := range that.TableColumns[that.FileConfig.GetString("table")] {
|
||||||
|
if v.GetString("link") != "" &&
|
||||||
|
v.GetString("name") != "parent_id" &&
|
||||||
|
userData.Get(v.GetString("name")) != nil {
|
||||||
|
ruleData[v.GetString("link")] = userData.Get(v.GetString("name"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ruleData[v.GetString("link")] != nil {
|
||||||
|
|
||||||
|
if v.GetString("name") == "parent_id" {
|
||||||
|
data[table+".index[~]"] = "," + ruleData.GetString(v.GetString("link")) + ","
|
||||||
|
|
||||||
|
} else {
|
||||||
|
idMap := db.Select(v.GetString("link"), "id", Map{"index[~]": "," + ruleData.GetString(v.GetString("link")) + ","})
|
||||||
|
ids := Slice{ruleData.GetCeilInt(v.GetString("link"))}
|
||||||
|
for _, v := range idMap {
|
||||||
|
ids = append(ids, v.GetCeilInt("id"))
|
||||||
|
}
|
||||||
|
data[table+"."+v.GetString("name")] = ids
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if keywordStr != "" {
|
if keywordStr != "" {
|
||||||
if v.GetString("type") == "text" {
|
if v.GetString("type") == "text" {
|
||||||
keyword[table+"."+v.GetString("name")+"[~]"] = keywordStr
|
keyword[table+"."+v.GetString("name")+"[~]"] = keywordStr
|
||||||
@@ -646,14 +890,36 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
//日期类型
|
//日期类型
|
||||||
if searchItemName == "daterange" && v.GetString("type") == "time" {
|
if searchItemName == "daterange" {
|
||||||
fmt.Println(req.Form["daterange"])
|
if v.GetString("type") == "unixtime" {
|
||||||
daterange[table+"."+v.GetString("name")+"[<>]"] = ObjToSlice(req.Form["daterange"])
|
//fmt.Println(req.Form["daterange"])
|
||||||
|
if len(req.Form["daterange"]) == 1 {
|
||||||
|
daterange[table+"."+v.GetString("name")+"[<]"] = req.FormValue("daterange")
|
||||||
|
} else if len(req.Form["daterange"]) == 2 {
|
||||||
|
|
||||||
|
daterange[table+"."+v.GetString("name")+"[<>]"] = ObjToSlice(req.Form["daterange"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v.GetString("type") == "time" {
|
||||||
|
//fmt.Println(req.Form["daterange"])
|
||||||
|
|
||||||
|
if len(req.Form["daterange"]) == 1 {
|
||||||
|
t := time.Unix(ObjToCeilInt64(req.FormValue("daterange")), 0).Format("2006-01-02 15:04:05")
|
||||||
|
|
||||||
|
daterange[table+"."+v.GetString("name")+"[<]"] = t
|
||||||
|
|
||||||
|
} else if len(req.Form["daterange"]) == 2 {
|
||||||
|
t1 := time.Unix(ObjToCeilInt64(req.Form["daterange"][0]), 0).Format("2006-01-02 15:04:05")
|
||||||
|
t2 := time.Unix(ObjToCeilInt64(req.Form["daterange"][1]), 0).Format("2006-01-02 15:04:05")
|
||||||
|
daterange[table+"."+v.GetString("name")+"[<>]"] = Slice{t1, t2}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if searchItem.GetString("name") == "sort" {
|
if searchItem.GetString("name") == "sort" {
|
||||||
sort["ORDER"] = table + "." + reqValue
|
sortMap["ORDER"] = table + "." + reqValue
|
||||||
}
|
}
|
||||||
|
|
||||||
continue
|
continue
|
||||||
@@ -662,7 +928,8 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (
|
|||||||
if searchItemName == "parent_id" {
|
if searchItemName == "parent_id" {
|
||||||
parentID := ObjToInt(req.FormValue("parent_id"))
|
parentID := ObjToInt(req.FormValue("parent_id"))
|
||||||
if parentID == 0 {
|
if parentID == 0 {
|
||||||
data["OR"] = Map{table + ".parent_id[#]": 0, table + ".parent_id": nil}
|
parentID = userData.GetCeilInt(table + "_id")
|
||||||
|
data["OR"] = Map{table + ".id": parentID, table + ".parent_id": nil}
|
||||||
} else {
|
} else {
|
||||||
data[table+".parent_id"] = parentID
|
data[table+".parent_id"] = parentID
|
||||||
}
|
}
|
||||||
@@ -672,6 +939,9 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (
|
|||||||
data[table+"."+searchItemName] = reqValue
|
data[table+"."+searchItemName] = reqValue
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if sortMap["ORDER"] == nil {
|
||||||
|
sortMap["ORDER"] = table + ".id DESC"
|
||||||
|
}
|
||||||
|
|
||||||
where := Map{}
|
where := Map{}
|
||||||
|
|
||||||
@@ -696,7 +966,9 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(daterange) > 1 {
|
if len(daterange) > 1 {
|
||||||
if data["AND"] != nil {
|
if data == nil || len(data) == 0 {
|
||||||
|
data = Map{"OR": daterange}
|
||||||
|
} else {
|
||||||
data = Map{"AND": Map{"AND": data, "OR": daterange}}
|
data = Map{"AND": Map{"AND": data, "OR": daterange}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -709,11 +981,21 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (
|
|||||||
where = data
|
where = data
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(sort) != 0 {
|
if len(where) == 0 && hasUser {
|
||||||
for k, v := range sort {
|
|
||||||
|
//where["admin.id"] = userData["id"]
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(sortMap) != 0 {
|
||||||
|
for k, v := range sortMap {
|
||||||
where[k] = v
|
where[k] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return reStr, leftJoin, where
|
return reStr, leftJoin, where
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setListener() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
+134
-48
@@ -3,8 +3,8 @@ package code
|
|||||||
var InitTpt = `package {{name}}
|
var InitTpt = `package {{name}}
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "../../../hotime"
|
. "code.hoteas.com/golang/hotime"
|
||||||
. "../../../hotime/common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ID = "{{id}}"
|
var ID = "{{id}}"
|
||||||
@@ -14,39 +14,84 @@ var Project = Proj{
|
|||||||
//"user": UserCtr,
|
//"user": UserCtr,
|
||||||
{{tablesCtr}}
|
{{tablesCtr}}
|
||||||
"hotime":Ctr{
|
"hotime":Ctr{
|
||||||
"login": func(this *Context) {
|
"login": func(that *Context) {
|
||||||
name:=this.Req.FormValue("name")
|
|
||||||
password:=this.Req.FormValue("password")
|
name := that.Req.FormValue("name")
|
||||||
if name==""||password==""{
|
password := that.Req.FormValue("password")
|
||||||
this.Display(3,"参数不足")
|
if name == "" || password == "" {
|
||||||
|
that.Display(3, "参数不足")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
user:=this.Db.Get("{{name}}","*",Map{"AND":Map{"name":name,"password":Md5(password)}})
|
user := that.Db.Get("admin", "*", Map{"AND": Map{"OR":Map{"name": name,"phone":name}, "password": Md5(password)}})
|
||||||
if user==nil{
|
if user == nil {
|
||||||
this.Display(5,"登录失败")
|
that.Display(5, "登录失败")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.Session("id",user.GetCeilInt("id"))
|
that.Session("admin_id", user.GetCeilInt("id"))
|
||||||
this.Session("name",name)
|
that.Session("admin_name", name)
|
||||||
this.Display(0,"登录成功")
|
that.Display(0, that.SessionId)
|
||||||
},
|
},
|
||||||
"logout": func(this *Context) {
|
"logout": func(that *Context) {
|
||||||
this.Session("id",nil)
|
that.Session("admin_id", nil)
|
||||||
this.Session("name",nil)
|
that.Session("admin_name", nil)
|
||||||
this.Display(0,"退出登录成功")
|
that.Display(0, "退出登录成功")
|
||||||
},
|
},
|
||||||
|
"info": func(that *Context) {
|
||||||
|
hotimeName := that.RouterString[0]
|
||||||
|
data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()})
|
||||||
|
str, inData := that.MakeCodeRouter[hotimeName].Info("admin", data, that.Db)
|
||||||
|
where := Map{"id": that.Session("admin_id").ToCeilInt()}
|
||||||
|
if len(inData) ==1 {
|
||||||
|
inData["id"] =where["id"]
|
||||||
|
where = Map{"AND": inData}
|
||||||
|
}else if len(inData) >1 {
|
||||||
|
where["OR"]=inData
|
||||||
|
where = Map{"AND": where}
|
||||||
|
}
|
||||||
|
re := that.Db.Get("admin", str, where)
|
||||||
|
if re == nil {
|
||||||
|
that.Display(4, "找不到对应信息")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for k, v := range re {
|
||||||
|
column := that.MakeCodeRouter[hotimeName].TableColumns["admin"][k]
|
||||||
|
if column == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" {
|
||||||
|
re[column.GetString("link")] = that.Db.Get(column.GetString("link"),"id," +column.GetString("value"), Map{"id": v})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
that.Display(0, re)
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
var CtrTpt = `package {{name}}
|
var CtrTpt = `package {{name}}
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "../../../hotime"
|
. "code.hoteas.com/golang/hotime"
|
||||||
. "../../../hotime/common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var {{table}}Ctr = Ctr{
|
var {{table}}Ctr = Ctr{
|
||||||
"info": func(that *Context) {
|
"info": func(that *Context) {
|
||||||
re := that.Db.Get(that.RouterString[1], that.MakeCode.Info(that.RouterString[1]), Map{"id": that.RouterString[2]})
|
hotimeName := that.RouterString[0]
|
||||||
|
data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()})
|
||||||
|
str, inData := that.MakeCodeRouter[hotimeName].Info(that.RouterString[1], data, that.Db)
|
||||||
|
where := Map{"id": that.RouterString[2]}
|
||||||
|
|
||||||
|
if len(inData) ==1 {
|
||||||
|
inData["id"] =where["id"]
|
||||||
|
where = Map{"AND": inData}
|
||||||
|
}else if len(inData) >1 {
|
||||||
|
where["OR"]=inData
|
||||||
|
where = Map{"AND": where}
|
||||||
|
}
|
||||||
|
|
||||||
|
re := that.Db.Get(that.RouterString[1], str, where)
|
||||||
|
|
||||||
if re == nil {
|
if re == nil {
|
||||||
that.Display(4, "找不到对应信息")
|
that.Display(4, "找不到对应信息")
|
||||||
@@ -54,39 +99,67 @@ var {{table}}Ctr = Ctr{
|
|||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range re {
|
for k, v := range re {
|
||||||
|
column := that.MakeCodeRouter[hotimeName].TableColumns[that.RouterString[1]][k]
|
||||||
column:=that.MakeCode.TableColumns[that.RouterString[1]][k]
|
if column == nil {
|
||||||
if column==nil{
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if (column["list"]==nil||column.GetBool("list"))&&column.GetString("link")!=""{
|
if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" {
|
||||||
re[column.GetString("link")] = that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v})
|
re[column.GetString("link")] = that.Db.Get(column.GetString("link"), "id,"+column.GetString("value"), Map{"id": v})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
that.Display(0, re)
|
that.Display(0, re)
|
||||||
},
|
},
|
||||||
"add": func(that *Context) {
|
"add": func(that *Context) {
|
||||||
inData := that.MakeCode.Add(that.RouterString[1], that.Req)
|
hotimeName := that.RouterString[0]
|
||||||
|
inData := that.MakeCodeRouter[hotimeName].Add(that.RouterString[1], that.Req)
|
||||||
if inData == nil {
|
if inData == nil {
|
||||||
that.Display(3, "请求参数不足")
|
that.Display(3, "请求参数不足")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
re := that.Db.Insert(that.RouterString[1], inData)
|
re := that.Db.Insert(that.RouterString[1], inData)
|
||||||
|
|
||||||
if re == 0 {
|
if re == 0 {
|
||||||
that.Display(4, "无法插入对应数据")
|
that.Display(4, "无法插入对应数据")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
//索引管理,便于检索以及权限
|
||||||
|
if inData.Get("parent_id") != nil && inData.GetString("index") != "" {
|
||||||
|
index := that.Db.Get(that.RouterString[1], "` + "`index`" + `", Map{"id": inData.Get("parent_id")})
|
||||||
|
inData["index"] = index.GetString("index")+ObjToStr(re)+","
|
||||||
|
that.Db.Update(that.RouterString[1],Map{"index":inData["index"]},Map{"id":re})
|
||||||
|
}else if inData.GetString("index") != ""{
|
||||||
|
inData["index"] = "," + ObjToStr(re) + ","
|
||||||
|
that.Db.Update(that.RouterString[1], Map{"index": inData["index"]}, Map{"id": re})
|
||||||
|
}
|
||||||
|
|
||||||
that.Display(0, re)
|
that.Display(0, re)
|
||||||
},
|
},
|
||||||
"update": func(that *Context) {
|
"update": func(that *Context) {
|
||||||
inData := that.MakeCode.Edit(that.RouterString[1], that.Req)
|
hotimeName := that.RouterString[0]
|
||||||
|
inData := that.MakeCodeRouter[hotimeName].Edit(that.RouterString[1], that.Req)
|
||||||
if inData == nil {
|
if inData == nil {
|
||||||
that.Display(3, "没有找到要更新的数据")
|
that.Display(3, "没有找到要更新的数据")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//索引管理,便于检索以及权限
|
||||||
|
if inData.Get("parent_id") != nil && inData.GetString("index") != "" {
|
||||||
|
Index := that.Db.Get(that.RouterString[1], "` + "`index`" + `", Map{"id": that.RouterString[2]})
|
||||||
|
parentIndex := that.Db.Get(that.RouterString[1], "` + "`index`" + `", Map{"id": inData.Get("parent_id")})
|
||||||
|
inData["index"] = parentIndex.GetString("index") + that.RouterString[2] + ","
|
||||||
|
|
||||||
|
childNodes := that.Db.Select(that.RouterString[1], "id,` + "`index`" + `", Map{"index[~]": "," + that.RouterString[2] + ","})
|
||||||
|
|
||||||
|
for _, v := range childNodes {
|
||||||
|
v["index"] = strings.Replace(v.GetString("index"), Index.GetString("index"), inData.GetString("index"), -1)
|
||||||
|
that.Db.Update(that.RouterString[1], Map{"index": v["index"]}, Map{"id": v.GetCeilInt("id")})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
re := that.Db.Update(that.RouterString[1], inData, Map{"id": that.RouterString[2]})
|
re := that.Db.Update(that.RouterString[1], inData, Map{"id": that.RouterString[2]})
|
||||||
|
|
||||||
if re == 0 {
|
if re == 0 {
|
||||||
@@ -97,54 +170,67 @@ var {{table}}Ctr = Ctr{
|
|||||||
that.Display(0, re)
|
that.Display(0, re)
|
||||||
},
|
},
|
||||||
"remove": func(that *Context) {
|
"remove": func(that *Context) {
|
||||||
re := that.Db.Delete(that.RouterString[1], Map{"id": that.RouterString[2]})
|
hotimeName := that.RouterString[0]
|
||||||
|
inData := that.MakeCodeRouter[hotimeName].Delete(that.RouterString[1], that.Req)
|
||||||
|
if inData == nil {
|
||||||
|
that.Display(3, "请求参数不足")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
re :=int64(0)
|
||||||
|
//索引管理,便于检索以及权限
|
||||||
|
if inData.Get("parent_id") != nil && inData.GetSlice("index") != nil {
|
||||||
|
re=that.Db.Delete(that.RouterString[1], Map{"index[~]": "," + that.RouterString[2] + ","})
|
||||||
|
}else {
|
||||||
|
re=that.Db.Delete(that.RouterString[1], Map{"id": that.RouterString[2]})
|
||||||
|
}
|
||||||
|
|
||||||
if re == 0 {
|
if re == 0 {
|
||||||
that.Display(4, "删除数据失败")
|
that.Display(4, "删除数据失败")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
that.Display(0, re)
|
that.Display(0, "删除成功")
|
||||||
},
|
},
|
||||||
|
|
||||||
"search": func(that *Context) {
|
"search": func(that *Context) {
|
||||||
|
hotimeName := that.RouterString[0]
|
||||||
|
data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()})
|
||||||
|
|
||||||
|
columnStr, leftJoin, where := that.MakeCodeRouter[hotimeName].Search(that.RouterString[1], data, that.Req, that.Db)
|
||||||
|
|
||||||
columnStr,leftJoin,where := that.MakeCode.Search(that.RouterString[1], that.Req,that.Db)
|
page := ObjToInt(that.Req.FormValue("page"))
|
||||||
page:=ObjToInt(that.Req.FormValue("page"))
|
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
|
||||||
pageSize:=ObjToInt(that.Req.FormValue("pageSize"))
|
|
||||||
|
|
||||||
if page<1{
|
if page < 1 {
|
||||||
page=1
|
page = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if pageSize<=0{
|
if pageSize <= 0 {
|
||||||
pageSize=20
|
pageSize = 20
|
||||||
}
|
}
|
||||||
|
|
||||||
count:=that.Db.Count(that.RouterString[1],leftJoin,where)
|
count := that.Db.Count(that.RouterString[1], leftJoin, where)
|
||||||
reData := that.Db.Page(page, pageSize).
|
reData := that.Db.Page(page, pageSize).
|
||||||
PageSelect(that.RouterString[1],leftJoin,columnStr, where)
|
PageSelect(that.RouterString[1], leftJoin, columnStr, where)
|
||||||
|
|
||||||
|
|
||||||
for _, v := range reData {
|
for _, v := range reData {
|
||||||
for k, _ := range v {
|
for k, _ := range v {
|
||||||
column:=that.MakeCode.TableColumns[that.RouterString[1]][k]
|
column := that.MakeCodeRouter[hotimeName].TableColumns[that.RouterString[1]][k]
|
||||||
if column==nil{
|
if column == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if column["list"]!=false&&column["name"]=="parent_id"&&column.GetString("link")!=""{
|
if column["list"] != false && column["name"] == "parent_id" && column.GetString("link") != "" {
|
||||||
parentC := that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v.GetCeilInt(k)})
|
parentC := that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v.GetCeilInt(k)})
|
||||||
v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")]=""
|
v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = ""
|
||||||
if parentC!=nil{
|
if parentC != nil {
|
||||||
v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")]=parentC.GetString(column.GetString("value"))
|
v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = parentC.GetString(column.GetString("value"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
that.Display(0, Map{"count":count,"data":reData})
|
that.Display(0, Map{"count": count, "data": reData})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ type ContextBase struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//唯一标志
|
//唯一标志
|
||||||
func (this *ContextBase) GetTag() string {
|
func (that *ContextBase) GetTag() string {
|
||||||
|
|
||||||
if this.tag == "" {
|
if that.tag == "" {
|
||||||
this.tag = ObjToStr(time.Now().Unix()) + ":" + ObjToStr(Random())
|
that.tag = ObjToStr(time.Now().Unix()) + ":" + ObjToStr(Random())
|
||||||
}
|
}
|
||||||
return this.tag
|
return that.tag
|
||||||
}
|
}
|
||||||
|
|||||||
+40
-4
@@ -36,6 +36,42 @@ func StrFirstToUpper(str string) string {
|
|||||||
return strings.ToUpper(first) + other
|
return strings.ToUpper(first) + other
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StrLd 相似度计算 ld compares two strings and returns the levenshtein distance between them.
|
||||||
|
func StrLd(s, t string, ignoreCase bool) int {
|
||||||
|
if ignoreCase {
|
||||||
|
s = strings.ToLower(s)
|
||||||
|
t = strings.ToLower(t)
|
||||||
|
}
|
||||||
|
d := make([][]int, len(s)+1)
|
||||||
|
for i := range d {
|
||||||
|
d[i] = make([]int, len(t)+1)
|
||||||
|
}
|
||||||
|
for i := range d {
|
||||||
|
d[i][0] = i
|
||||||
|
}
|
||||||
|
for j := range d[0] {
|
||||||
|
d[0][j] = j
|
||||||
|
}
|
||||||
|
for j := 1; j <= len(t); j++ {
|
||||||
|
for i := 1; i <= len(s); i++ {
|
||||||
|
if s[i-1] == t[j-1] {
|
||||||
|
d[i][j] = d[i-1][j-1]
|
||||||
|
} else {
|
||||||
|
min := d[i-1][j]
|
||||||
|
if d[i][j-1] < min {
|
||||||
|
min = d[i][j-1]
|
||||||
|
}
|
||||||
|
if d[i-1][j-1] < min {
|
||||||
|
min = d[i-1][j-1]
|
||||||
|
}
|
||||||
|
d[i][j] = min + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return d[len(s)][len(t)]
|
||||||
|
}
|
||||||
|
|
||||||
// Substr 字符串截取
|
// Substr 字符串截取
|
||||||
func Substr(str string, start int, length int) string {
|
func Substr(str string, start int, length int) string {
|
||||||
rs := []rune(str)
|
rs := []rune(str)
|
||||||
@@ -106,7 +142,7 @@ func Md5(req string) string {
|
|||||||
return hex.EncodeToString(cipherStr)
|
return hex.EncodeToString(cipherStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
//随机数
|
// Rand 随机数
|
||||||
func Rand(count int) int {
|
func Rand(count int) int {
|
||||||
res := Random()
|
res := Random()
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
@@ -131,7 +167,7 @@ func Random() float64 {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//随机数范围
|
// RandX 随机数范围
|
||||||
func RandX(small int, max int) int {
|
func RandX(small int, max int) int {
|
||||||
res := 0
|
res := 0
|
||||||
//随机对象
|
//随机对象
|
||||||
@@ -183,7 +219,7 @@ func RandX(small int, max int) int {
|
|||||||
// GetDb()
|
// GetDb()
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//复制返回数组
|
// DeepCopyMap 复制返回数组
|
||||||
func DeepCopyMap(value interface{}) interface{} {
|
func DeepCopyMap(value interface{}) interface{} {
|
||||||
if valueMap, ok := value.(Map); ok {
|
if valueMap, ok := value.(Map); ok {
|
||||||
newMap := make(Map)
|
newMap := make(Map)
|
||||||
@@ -242,7 +278,7 @@ func DeepCopyMap(value interface{}) interface{} {
|
|||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//浮点数四舍五入保留小数
|
// Round 浮点数四舍五入保留小数
|
||||||
func Round(f float64, n int) float64 {
|
func Round(f float64, n int) float64 {
|
||||||
pow10_n := math.Pow10(n)
|
pow10_n := math.Pow10(n)
|
||||||
return math.Trunc((f+0.5/pow10_n)*pow10_n) / pow10_n
|
return math.Trunc((f+0.5/pow10_n)*pow10_n) / pow10_n
|
||||||
|
|||||||
+66
-40
@@ -4,114 +4,140 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"sort"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
//hotime的常用map
|
//hotime的常用map
|
||||||
type Map map[string]interface{}
|
type Map map[string]interface{}
|
||||||
|
|
||||||
//获取string
|
//获取string
|
||||||
func (this Map) GetString(key string, err ...*Error) string {
|
func (that Map) GetString(key string, err ...*Error) string {
|
||||||
|
|
||||||
if len(err) != 0 {
|
if len(err) != 0 {
|
||||||
err[0].SetError(nil)
|
err[0].SetError(nil)
|
||||||
}
|
}
|
||||||
return ObjToStr((this)[key])
|
return ObjToStr((that)[key])
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Map) Pointer() *Map {
|
func (that *Map) Pointer() *Map {
|
||||||
|
|
||||||
return this
|
return that
|
||||||
}
|
}
|
||||||
|
|
||||||
//增加接口
|
//增加接口
|
||||||
func (this Map) Put(key string, value interface{}) {
|
func (that Map) Put(key string, value interface{}) {
|
||||||
//if this==nil{
|
//if that==nil{
|
||||||
// this=Map{}
|
// that=Map{}
|
||||||
//}
|
//}
|
||||||
this[key] = value
|
that[key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
//删除接口
|
//删除接口
|
||||||
func (this Map) Delete(key string) {
|
func (that Map) Delete(key string) {
|
||||||
delete(this, key)
|
delete(that, key)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取Int
|
//获取Int
|
||||||
func (this Map) GetInt(key string, err ...*Error) int {
|
func (that Map) GetInt(key string, err ...*Error) int {
|
||||||
v := ObjToInt((this)[key], err...)
|
v := ObjToInt((that)[key], err...)
|
||||||
|
|
||||||
return v
|
return v
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取Int
|
//获取Int
|
||||||
func (this Map) GetInt64(key string, err ...*Error) int64 {
|
func (that Map) GetInt64(key string, err ...*Error) int64 {
|
||||||
v := ObjToInt64((this)[key], err...)
|
v := ObjToInt64((that)[key], err...)
|
||||||
return v
|
return v
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取向上取整Int64
|
//获取向上取整Int64
|
||||||
func (this Map) GetCeilInt64(key string, err ...*Error) int64 {
|
func (that Map) GetCeilInt64(key string, err ...*Error) int64 {
|
||||||
v := ObjToCeilInt64((this)[key], err...)
|
v := ObjToCeilInt64((that)[key], err...)
|
||||||
return v
|
return v
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取向上取整Int
|
//获取向上取整Int
|
||||||
func (this Map) GetCeilInt(key string, err ...*Error) int {
|
func (that Map) GetCeilInt(key string, err ...*Error) int {
|
||||||
v := ObjToCeilInt((this)[key], err...)
|
v := ObjToCeilInt((that)[key], err...)
|
||||||
return v
|
return v
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取向上取整float64
|
//获取向上取整float64
|
||||||
func (this Map) GetCeilFloat64(key string, err ...*Error) float64 {
|
func (that Map) GetCeilFloat64(key string, err ...*Error) float64 {
|
||||||
v := ObjToCeilFloat64((this)[key], err...)
|
v := ObjToCeilFloat64((that)[key], err...)
|
||||||
return v
|
return v
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取Float64
|
//获取Float64
|
||||||
func (this Map) GetFloat64(key string, err ...*Error) float64 {
|
func (that Map) GetFloat64(key string, err ...*Error) float64 {
|
||||||
|
|
||||||
v := ObjToFloat64((this)[key], err...)
|
v := ObjToFloat64((that)[key], err...)
|
||||||
|
|
||||||
return v
|
return v
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this Map) GetSlice(key string, err ...*Error) Slice {
|
func (that Map) GetSlice(key string, err ...*Error) Slice {
|
||||||
|
|
||||||
//var v Slice
|
//var v Slice
|
||||||
v := ObjToSlice((this)[key], err...)
|
v := ObjToSlice((that)[key], err...)
|
||||||
|
|
||||||
return v
|
return v
|
||||||
|
|
||||||
}
|
}
|
||||||
func (this Map) GetBool(key string, err ...*Error) bool {
|
func (that Map) GetBool(key string, err ...*Error) bool {
|
||||||
|
|
||||||
//var v Slice
|
//var v Slice
|
||||||
v := ObjToBool((this)[key], err...)
|
v := ObjToBool((that)[key], err...)
|
||||||
|
|
||||||
return v
|
return v
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this Map) GetMap(key string, err ...*Error) Map {
|
func (that Map) GetTime(key string, err ...*Error) time.Time {
|
||||||
|
|
||||||
|
v := ObjToTime((that)[key], err...)
|
||||||
|
return v
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (that Map) RangeSort(callback func(k string, v interface{}) (isEnd bool)) {
|
||||||
|
testQu := []string{}
|
||||||
|
//testQuData:= qu[0].(Map)
|
||||||
|
for key, _ := range that {
|
||||||
|
//fmt.Println(key, ":", value)
|
||||||
|
testQu = append(testQu, key)
|
||||||
|
}
|
||||||
|
sort.Strings(testQu)
|
||||||
|
for _, k := range testQu {
|
||||||
|
re := callback(k, that[k])
|
||||||
|
if re {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (that Map) GetMap(key string, err ...*Error) Map {
|
||||||
//var data Slice
|
//var data Slice
|
||||||
|
|
||||||
v := ObjToMap((this)[key], err...)
|
v := ObjToMap((that)[key], err...)
|
||||||
|
|
||||||
return v
|
return v
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this Map) Get(key string, err ...*Error) interface{} {
|
func (that Map) Get(key string, err ...*Error) interface{} {
|
||||||
|
|
||||||
if v, ok := (this)[key]; ok {
|
if v, ok := (that)[key]; ok {
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
e := errors.New("没有存储key及对应的数据")
|
e := errors.New("没有存储key及对应的数据")
|
||||||
@@ -124,10 +150,10 @@ func (this Map) Get(key string, err ...*Error) interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//请传递指针过来
|
//请传递指针过来
|
||||||
func (this Map) ToStruct(stct interface{}) {
|
func (that Map) ToStruct(stct interface{}) {
|
||||||
|
|
||||||
data := reflect.ValueOf(stct).Elem()
|
data := reflect.ValueOf(stct).Elem()
|
||||||
for k, v := range this {
|
for k, v := range that {
|
||||||
ks := StrFirstToUpper(k)
|
ks := StrFirstToUpper(k)
|
||||||
dkey := data.FieldByName(ks)
|
dkey := data.FieldByName(ks)
|
||||||
if !dkey.IsValid() {
|
if !dkey.IsValid() {
|
||||||
@@ -135,13 +161,13 @@ func (this Map) ToStruct(stct interface{}) {
|
|||||||
}
|
}
|
||||||
switch dkey.Type().String() {
|
switch dkey.Type().String() {
|
||||||
case "int":
|
case "int":
|
||||||
dkey.SetInt(this.GetInt64(k))
|
dkey.SetInt(that.GetInt64(k))
|
||||||
case "int64":
|
case "int64":
|
||||||
dkey.Set(reflect.ValueOf(this.GetInt64(k)))
|
dkey.Set(reflect.ValueOf(that.GetInt64(k)))
|
||||||
case "float64":
|
case "float64":
|
||||||
dkey.Set(reflect.ValueOf(this.GetFloat64(k)))
|
dkey.Set(reflect.ValueOf(that.GetFloat64(k)))
|
||||||
case "string":
|
case "string":
|
||||||
dkey.Set(reflect.ValueOf(this.GetString(k)))
|
dkey.Set(reflect.ValueOf(that.GetString(k)))
|
||||||
case "interface{}":
|
case "interface{}":
|
||||||
dkey.Set(reflect.ValueOf(v))
|
dkey.Set(reflect.ValueOf(v))
|
||||||
}
|
}
|
||||||
@@ -149,13 +175,13 @@ func (this Map) ToStruct(stct interface{}) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this Map) ToJsonString() string {
|
func (that Map) ToJsonString() string {
|
||||||
return ObjToStr(this)
|
return ObjToStr(that)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this Map) JsonToMap(jsonStr string, err ...*Error) {
|
func (that Map) JsonToMap(jsonStr string, err ...*Error) {
|
||||||
e := json.Unmarshal([]byte(jsonStr), &this)
|
e := json.Unmarshal([]byte(jsonStr), &that)
|
||||||
if e != nil && len(err) != 0 {
|
if e != nil && len(err) != 0 {
|
||||||
err[0].SetError(e)
|
err[0].SetError(e)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
//对象封装方便取用
|
//对象封装方便取用
|
||||||
type Obj struct {
|
type Obj struct {
|
||||||
Data interface{}
|
Data interface{}
|
||||||
@@ -18,6 +20,13 @@ func (that *Obj) ToInt(err ...Error) int {
|
|||||||
return ObjToInt(that.Data, &that.Error)
|
return ObjToInt(that.Data, &that.Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (that *Obj) ToTime(err ...Error) time.Time {
|
||||||
|
if len(err) != 0 {
|
||||||
|
that.Error = err[0]
|
||||||
|
}
|
||||||
|
return ObjToTime(that.Data, &that.Error)
|
||||||
|
}
|
||||||
|
|
||||||
func (that *Obj) ToInt64(err ...Error) int64 {
|
func (that *Obj) ToInt64(err ...Error) int64 {
|
||||||
if len(err) != 0 {
|
if len(err) != 0 {
|
||||||
that.Error = err[0]
|
that.Error = err[0]
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"math"
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
//仅限于hotime.Slice
|
//仅限于hotime.Slice
|
||||||
@@ -96,6 +97,65 @@ func ObjToSlice(obj interface{}, e ...*Error) Slice {
|
|||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ObjToTime(obj interface{}, e ...*Error) time.Time {
|
||||||
|
|
||||||
|
tInt := ObjToInt64(obj)
|
||||||
|
//字符串类型,只支持标准mysql datetime格式
|
||||||
|
if tInt == 0 {
|
||||||
|
tStr := ObjToStr(obj)
|
||||||
|
|
||||||
|
if len(tStr) > 18 {
|
||||||
|
t, e := time.Parse("2006-01-02 15:04:05", tStr)
|
||||||
|
if e == nil {
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
} else if len(tStr) > 15 {
|
||||||
|
t, e := time.Parse("2006-01-02 15:04", tStr)
|
||||||
|
if e == nil {
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
} else if len(tStr) > 12 {
|
||||||
|
t, e := time.Parse("2006-01-02 15", tStr)
|
||||||
|
if e == nil {
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
} else if len(tStr) > 9 {
|
||||||
|
t, e := time.Parse("2006-01-02", tStr)
|
||||||
|
if e == nil {
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
} else if len(tStr) > 6 {
|
||||||
|
t, e := time.Parse("2006-01", tStr)
|
||||||
|
if e == nil {
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//纳秒级别
|
||||||
|
if len(ObjToStr(tInt)) > 16 {
|
||||||
|
|
||||||
|
return time.Time{}.Add(time.Nanosecond * time.Duration(tInt))
|
||||||
|
//微秒级别
|
||||||
|
} else if len(ObjToStr(tInt)) > 13 {
|
||||||
|
return time.Time{}.Add(time.Microsecond * time.Duration(tInt))
|
||||||
|
//毫秒级别
|
||||||
|
} else if len(ObjToStr(tInt)) > 10 {
|
||||||
|
return time.Time{}.Add(time.Millisecond * time.Duration(tInt))
|
||||||
|
//秒级别
|
||||||
|
} else if len(ObjToStr(tInt)) > 9 {
|
||||||
|
return time.Time{}.Add(time.Second * time.Duration(tInt))
|
||||||
|
} else if len(ObjToStr(tInt)) > 3 {
|
||||||
|
t, e := time.Parse("2006", ObjToStr(tInt))
|
||||||
|
if e == nil {
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return time.Time{}
|
||||||
|
}
|
||||||
|
|
||||||
func ObjToFloat64(obj interface{}, e ...*Error) float64 {
|
func ObjToFloat64(obj interface{}, e ...*Error) float64 {
|
||||||
var err error
|
var err error
|
||||||
v := float64(0)
|
v := float64(0)
|
||||||
@@ -135,6 +195,15 @@ func ObjToFloat64(obj interface{}, e ...*Error) float64 {
|
|||||||
err = errors.New("没有合适的转换对象!")
|
err = errors.New("没有合适的转换对象!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if math.IsNaN(v) {
|
||||||
|
err = errors.New("float64 is NaN")
|
||||||
|
v = 0
|
||||||
|
}
|
||||||
|
if math.IsInf(v, 0) {
|
||||||
|
err = errors.New("float64 is Inf")
|
||||||
|
v = 0
|
||||||
|
}
|
||||||
if len(e) != 0 {
|
if len(e) != 0 {
|
||||||
e[0].SetError(err)
|
e[0].SetError(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package common
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Slice []interface{}
|
type Slice []interface{}
|
||||||
@@ -14,6 +15,13 @@ func (that Slice) GetString(key int, err ...*Error) string {
|
|||||||
return ObjToStr((that)[key])
|
return ObjToStr((that)[key])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (that Slice) GetTime(key int, err ...*Error) time.Time {
|
||||||
|
|
||||||
|
v := ObjToTime((that)[key], err...)
|
||||||
|
return v
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// GetInt 获取Int
|
// GetInt 获取Int
|
||||||
func (that Slice) GetInt(key int, err ...*Error) int {
|
func (that Slice) GetInt(key int, err ...*Error) int {
|
||||||
v := ObjToInt((that)[key], err...)
|
v := ObjToInt((that)[key], err...)
|
||||||
|
|||||||
+26
-3
@@ -1,23 +1,27 @@
|
|||||||
package hotime
|
package hotime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "./cache"
|
. "code.hoteas.com/golang/hotime/cache"
|
||||||
. "./common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
. "./db"
|
. "code.hoteas.com/golang/hotime/db"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Context struct {
|
type Context struct {
|
||||||
*Application
|
*Application
|
||||||
Resp http.ResponseWriter
|
Resp http.ResponseWriter
|
||||||
Req *http.Request
|
Req *http.Request
|
||||||
|
Log Map //日志有则创建
|
||||||
RouterString []string
|
RouterString []string
|
||||||
Config Map
|
Config Map
|
||||||
Db *HoTimeDB
|
Db *HoTimeDB
|
||||||
RespData Map
|
RespData Map
|
||||||
|
RespFunc func()
|
||||||
CacheIns
|
CacheIns
|
||||||
SessionIns
|
SessionIns
|
||||||
|
DataSize int
|
||||||
HandlerStr string //复写请求url
|
HandlerStr string //复写请求url
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,13 +60,32 @@ func (that *Context) Display(statu int, data interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (that *Context) View() {
|
func (that *Context) View() {
|
||||||
|
if that.RespFunc != nil {
|
||||||
|
that.RespFunc()
|
||||||
|
}
|
||||||
if that.RespData == nil {
|
if that.RespData == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
//创建日志
|
||||||
|
if that.Log != nil {
|
||||||
|
that.Log["time"] = time.Now().Unix()
|
||||||
|
if that.Session("admin_id").Data != nil {
|
||||||
|
that.Log["admin_id"] = that.Session("admin_id").ToCeilInt()
|
||||||
|
}
|
||||||
|
if that.Session("user_id").Data != nil {
|
||||||
|
that.Log["user_id"] = that.Session("user_id").ToCeilInt()
|
||||||
|
}
|
||||||
|
that.Db.Insert("logs", that.Log)
|
||||||
|
}
|
||||||
|
|
||||||
d, err := json.Marshal(that.RespData)
|
d, err := json.Marshal(that.RespData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
that.Display(1, err.Error())
|
||||||
|
that.View()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
that.DataSize = len(d)
|
||||||
that.RespData = nil
|
that.RespData = nil
|
||||||
that.Resp.Write(d)
|
that.Resp.Write(d)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
+82
-33
@@ -1,8 +1,8 @@
|
|||||||
package db
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"../cache"
|
"code.hoteas.com/golang/hotime/cache"
|
||||||
. "../common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -42,32 +43,32 @@ func (that *HoTimeDB) GetType() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Action 事务,如果action返回true则执行成功;false则回滚
|
// Action 事务,如果action返回true则执行成功;false则回滚
|
||||||
func (that *HoTimeDB) Action(action func(db HoTimeDB) bool) bool {
|
func (that *HoTimeDB) Action(action func(db HoTimeDB) (isSuccess bool)) (isSuccess bool) {
|
||||||
db := HoTimeDB{DB: that.DB, HoTimeCache: that.HoTimeCache, Prefix: that.Prefix}
|
db := HoTimeDB{DB: that.DB, HoTimeCache: that.HoTimeCache, Prefix: that.Prefix}
|
||||||
tx, err := db.Begin()
|
tx, err := db.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
that.LastErr.SetError(err)
|
that.LastErr.SetError(err)
|
||||||
return false
|
return isSuccess
|
||||||
}
|
}
|
||||||
|
|
||||||
db.Tx = tx
|
db.Tx = tx
|
||||||
|
|
||||||
result := action(db)
|
isSuccess = action(db)
|
||||||
|
|
||||||
if !result {
|
if !isSuccess {
|
||||||
err = db.Tx.Rollback()
|
err = db.Tx.Rollback()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
that.LastErr.SetError(err)
|
that.LastErr.SetError(err)
|
||||||
return false
|
return isSuccess
|
||||||
}
|
}
|
||||||
return result
|
return isSuccess
|
||||||
}
|
}
|
||||||
err = db.Tx.Commit()
|
err = db.Tx.Commit()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
that.LastErr.SetError(err)
|
that.LastErr.SetError(err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return result
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (that *HoTimeDB) InitDb(err ...*Error) *Error {
|
func (that *HoTimeDB) InitDb(err ...*Error) *Error {
|
||||||
@@ -165,7 +166,7 @@ func (that *HoTimeDB) Row(resl *sql.Rows) []Map {
|
|||||||
|
|
||||||
//
|
//
|
||||||
////code=0,1,2 0 backup all,1 backup data,2 backup ddl
|
////code=0,1,2 0 backup all,1 backup data,2 backup ddl
|
||||||
//func (this *HoTimeDB) Backup(path string, code int) {
|
//func (that *HoTimeDB) Backup(path string, code int) {
|
||||||
// var cmd *exec.Cmd
|
// var cmd *exec.Cmd
|
||||||
// switch code {
|
// switch code {
|
||||||
// case 0:cmd= exec.Command("mysqldump","-h"+ObjToStr(Config["dbHost"]), "-P"+ObjToStr(Config["dbPort"]),"-u"+ObjToStr(Config["dbUser"]), "-p"+ObjToStr(Config["dbPwd"]),ObjToStr(Config["dbName"]))
|
// case 0:cmd= exec.Command("mysqldump","-h"+ObjToStr(Config["dbHost"]), "-P"+ObjToStr(Config["dbPort"]),"-u"+ObjToStr(Config["dbUser"]), "-p"+ObjToStr(Config["dbPwd"]),ObjToStr(Config["dbName"]))
|
||||||
@@ -197,7 +198,7 @@ func (that *HoTimeDB) Row(resl *sql.Rows) []Map {
|
|||||||
// //db := ``
|
// //db := ``
|
||||||
// //fmt.Println(db)
|
// //fmt.Println(db)
|
||||||
// //
|
// //
|
||||||
// //tables := this.Query("show tables")
|
// //tables := that.Query("show tables")
|
||||||
// //lth := len(tables)
|
// //lth := len(tables)
|
||||||
// //if lth == 0 {
|
// //if lth == 0 {
|
||||||
// // return
|
// // return
|
||||||
@@ -212,7 +213,7 @@ func (that *HoTimeDB) Row(resl *sql.Rows) []Map {
|
|||||||
// //
|
// //
|
||||||
// //for i := 0; i < lth; i++ {
|
// //for i := 0; i < lth; i++ {
|
||||||
// // tt := tables[i]["Tables_in_"+db].(string)
|
// // tt := tables[i]["Tables_in_"+db].(string)
|
||||||
// // this.backupSave(path, tt, code)
|
// // that.backupSave(path, tt, code)
|
||||||
// // debug.FreeOSMemory()
|
// // debug.FreeOSMemory()
|
||||||
// //}
|
// //}
|
||||||
//
|
//
|
||||||
@@ -383,7 +384,7 @@ func (that *HoTimeDB) Exec(query string, args ...interface{}) (sql.Result, *Erro
|
|||||||
return resl, that.LastErr
|
return resl, that.LastErr
|
||||||
}
|
}
|
||||||
|
|
||||||
//func (this *HoTimeDB)copy(data []Map)[]Map{
|
//func (that *HoTimeDB)copy(data []Map)[]Map{
|
||||||
// if data==nil{
|
// if data==nil{
|
||||||
// return nil
|
// return nil
|
||||||
// }
|
// }
|
||||||
@@ -447,18 +448,27 @@ func (that *HoTimeDB) Select(table string, qu ...interface{}) []Map {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if join {
|
if join {
|
||||||
for k, v := range qu[0].(Map) {
|
var testQu = []string{}
|
||||||
|
testQuData := qu[0].(Map)
|
||||||
|
for key, _ := range testQuData {
|
||||||
|
//fmt.Println(key, ":", value)
|
||||||
|
testQu = append(testQu, key)
|
||||||
|
}
|
||||||
|
sort.Strings(testQu)
|
||||||
|
|
||||||
|
for _, k := range testQu {
|
||||||
|
v := testQuData[k]
|
||||||
switch Substr(k, 0, 3) {
|
switch Substr(k, 0, 3) {
|
||||||
case "[>]":
|
case "[>]":
|
||||||
query += " LEFT JOIN " + Substr(k, 3, len(k)-3) + " ON " + v.(string)
|
query += " LEFT JOIN `" + Substr(k, 3, len(k)-3) + "` ON " + v.(string)
|
||||||
case "[<]":
|
case "[<]":
|
||||||
query += " RIGHT JOIN " + Substr(k, 3, len(k)-3) + " ON " + v.(string)
|
query += " RIGHT JOIN `" + Substr(k, 3, len(k)-3) + "` ON " + v.(string)
|
||||||
}
|
}
|
||||||
switch Substr(k, 0, 4) {
|
switch Substr(k, 0, 4) {
|
||||||
case "[<>]":
|
case "[<>]":
|
||||||
query += " FULL JOIN " + Substr(k, 4, len(k)-4) + " ON " + v.(string)
|
query += " FULL JOIN `" + Substr(k, 4, len(k)-4) + "` ON " + v.(string)
|
||||||
case "[><]":
|
case "[><]":
|
||||||
query += " INNER JOIN " + Substr(k, 4, len(k)-4) + " ON " + v.(string)
|
query += " INNER JOIN `" + Substr(k, 4, len(k)-4) + "` ON " + v.(string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -560,7 +570,15 @@ func (that *HoTimeDB) where(data Map) (string, []interface{}) {
|
|||||||
|
|
||||||
res := make([]interface{}, 0)
|
res := make([]interface{}, 0)
|
||||||
//AND OR判断
|
//AND OR判断
|
||||||
for k, v := range data {
|
testQu := []string{}
|
||||||
|
//testQuData:= qu[0].(Map)
|
||||||
|
for key, _ := range data {
|
||||||
|
//fmt.Println(key, ":", value)
|
||||||
|
testQu = append(testQu, key)
|
||||||
|
}
|
||||||
|
sort.Strings(testQu)
|
||||||
|
for _, k := range testQu {
|
||||||
|
v := data[k]
|
||||||
x := 0
|
x := 0
|
||||||
for i := 0; i < len(condition); i++ {
|
for i := 0; i < len(condition); i++ {
|
||||||
|
|
||||||
@@ -607,7 +625,15 @@ func (that *HoTimeDB) where(data Map) (string, []interface{}) {
|
|||||||
|
|
||||||
//特殊字符
|
//特殊字符
|
||||||
for j := 0; j < len(vcond); j++ {
|
for j := 0; j < len(vcond); j++ {
|
||||||
for k, v := range data {
|
testQu := []string{}
|
||||||
|
//testQuData:= qu[0].(Map)
|
||||||
|
for key, _ := range data {
|
||||||
|
//fmt.Println(key, ":", value)
|
||||||
|
testQu = append(testQu, key)
|
||||||
|
}
|
||||||
|
sort.Strings(testQu)
|
||||||
|
for _, k := range testQu {
|
||||||
|
v := data[k]
|
||||||
if vcond[j] == k {
|
if vcond[j] == k {
|
||||||
if k == "ORDER" {
|
if k == "ORDER" {
|
||||||
where += " " + k + " BY "
|
where += " " + k + " BY "
|
||||||
@@ -652,8 +678,10 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
|
|||||||
where := ""
|
where := ""
|
||||||
res := make([]interface{}, 0)
|
res := make([]interface{}, 0)
|
||||||
length := len(k)
|
length := len(k)
|
||||||
|
if k == "[#]" {
|
||||||
if length > 0 && strings.Contains(k, "[") && k[length-1] == ']' {
|
k = strings.Replace(k, "[#]", "", -1)
|
||||||
|
where += " " + ObjToStr(v) + " "
|
||||||
|
} else if length > 0 && strings.Contains(k, "[") && k[length-1] == ']' {
|
||||||
def := false
|
def := false
|
||||||
|
|
||||||
switch Substr(k, length-3, 3) {
|
switch Substr(k, length-3, 3) {
|
||||||
@@ -791,9 +819,6 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if k == "[#]" {
|
|
||||||
k = strings.Replace(k, "[#]", "", -1)
|
|
||||||
where += " " + ObjToStr(v) + " "
|
|
||||||
} else {
|
} else {
|
||||||
//fmt.Println(reflect.ValueOf(v).Type().String())
|
//fmt.Println(reflect.ValueOf(v).Type().String())
|
||||||
if !strings.Contains(k, ".") {
|
if !strings.Contains(k, ".") {
|
||||||
@@ -837,7 +862,7 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
|
|||||||
return where, res
|
return where, res
|
||||||
}
|
}
|
||||||
|
|
||||||
// this.Db.Update("user",hotime.Map{"ustate":"1"},hotime.Map{"AND":hotime.Map{"OR":hotime.Map{"uid":4,"uname":"dasda"}},"ustate":1})
|
// that.Db.Update("user",hotime.Map{"ustate":"1"},hotime.Map{"AND":hotime.Map{"OR":hotime.Map{"uid":4,"uname":"dasda"}},"ustate":1})
|
||||||
func (that *HoTimeDB) notIn(k string, v interface{}, where string, res []interface{}) (string, []interface{}) {
|
func (that *HoTimeDB) notIn(k string, v interface{}, where string, res []interface{}) (string, []interface{}) {
|
||||||
//where:=""
|
//where:=""
|
||||||
//fmt.Println(reflect.ValueOf(v).Type().String())
|
//fmt.Println(reflect.ValueOf(v).Type().String())
|
||||||
@@ -882,7 +907,15 @@ func (that *HoTimeDB) cond(tag string, data Map) (string, []interface{}) {
|
|||||||
res := make([]interface{}, 0)
|
res := make([]interface{}, 0)
|
||||||
lens := len(data)
|
lens := len(data)
|
||||||
//fmt.Println(lens)
|
//fmt.Println(lens)
|
||||||
for k, v := range data {
|
testQu := []string{}
|
||||||
|
//testQuData:= qu[0].(Map)
|
||||||
|
for key, _ := range data {
|
||||||
|
//fmt.Println(key, ":", value)
|
||||||
|
testQu = append(testQu, key)
|
||||||
|
}
|
||||||
|
sort.Strings(testQu)
|
||||||
|
for _, k := range testQu {
|
||||||
|
v := data[k]
|
||||||
x := 0
|
x := 0
|
||||||
for i := 0; i < len(condition); i++ {
|
for i := 0; i < len(condition); i++ {
|
||||||
|
|
||||||
@@ -1000,13 +1033,29 @@ func (that *HoTimeDB) Insert(table string, data map[string]interface{}) int64 {
|
|||||||
tempLen := 0
|
tempLen := 0
|
||||||
for k, v := range data {
|
for k, v := range data {
|
||||||
tempLen++
|
tempLen++
|
||||||
values = append(values, v)
|
|
||||||
if tempLen < lens {
|
vstr := "?"
|
||||||
queryString += "`" + k + "`,"
|
if Substr(k, len(k)-3, 3) == "[#]" {
|
||||||
valueString += "?,"
|
k = strings.Replace(k, "[#]", "", -1)
|
||||||
|
|
||||||
|
vstr = ObjToStr(v)
|
||||||
|
if tempLen < lens {
|
||||||
|
queryString += "`" + k + "`,"
|
||||||
|
valueString += vstr + ","
|
||||||
|
} else {
|
||||||
|
queryString += "`" + k + "`) "
|
||||||
|
valueString += vstr + ");"
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
queryString += "`" + k + "`) "
|
|
||||||
valueString += "?);"
|
values = append(values, v)
|
||||||
|
if tempLen < lens {
|
||||||
|
queryString += "`" + k + "`,"
|
||||||
|
valueString += "?,"
|
||||||
|
} else {
|
||||||
|
queryString += "`" + k + "`) "
|
||||||
|
valueString += "?);"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,142 @@
|
|||||||
|
package aliyun
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
//"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
type company struct {
|
||||||
|
ApiCode string
|
||||||
|
Url string
|
||||||
|
}
|
||||||
|
|
||||||
|
var Company = company{}
|
||||||
|
|
||||||
|
func (that *company) Init(apiCode string) {
|
||||||
|
//"06c6a07e89dd45c88de040ee1489eef7"
|
||||||
|
that.ApiCode = apiCode
|
||||||
|
that.Url = "http://api.81api.com"
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCompanyOtherAll 获取企业基础信息
|
||||||
|
func (that *company) GetCompanyOtherAll(name string) Map {
|
||||||
|
|
||||||
|
res := Map{}
|
||||||
|
data, e := that.GetCompanyPatentsInfo(name) //获取专利信息
|
||||||
|
if e != nil {
|
||||||
|
fmt.Println(e)
|
||||||
|
} else {
|
||||||
|
res["PatentsInfo"] = data.GetMap("data")
|
||||||
|
}
|
||||||
|
data, e = that.GetCompanyOtherCopyrightsInfo(name) //获取其他专利
|
||||||
|
if e != nil {
|
||||||
|
fmt.Println(e)
|
||||||
|
} else {
|
||||||
|
res["OtherCopyrightsInfo"] = data.GetMap("data")
|
||||||
|
}
|
||||||
|
data, e = that.GetCompanyTrademarksInfo(name) //获取商标
|
||||||
|
if e != nil {
|
||||||
|
fmt.Println(e)
|
||||||
|
} else {
|
||||||
|
res["TrademarksInfo"] = data.GetMap("data")
|
||||||
|
}
|
||||||
|
data, e = that.GetCompanySoftwareCopyrightsInfo(name) //获取软著
|
||||||
|
if e != nil {
|
||||||
|
fmt.Println(e)
|
||||||
|
} else {
|
||||||
|
res["SoftwareCopyrightsInfo"] = data.GetMap("data")
|
||||||
|
}
|
||||||
|
data, e = that.GetCompanyProfileTags(name) //获取大数据标签
|
||||||
|
if e != nil {
|
||||||
|
fmt.Println(e)
|
||||||
|
} else {
|
||||||
|
res["ProfileTags"] = data.GetSlice("data")
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCompanyBaseInfo 获取企业基础信息
|
||||||
|
func (that *company) GetCompanyList(name string) (Map, error) {
|
||||||
|
url := "/fuzzyQueryCompanyInfo/"
|
||||||
|
|
||||||
|
body, err := that.basePost(url, name)
|
||||||
|
return ObjToMap(body), err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCompanyBaseInfo 获取企业基础信息
|
||||||
|
func (that *company) GetCompanyBaseInfo(name string) (Map, error) {
|
||||||
|
url := "/getCompanyBaseInfo/"
|
||||||
|
|
||||||
|
body, err := that.basePost(url, name)
|
||||||
|
return ObjToMap(body), err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCompanyPatentsInfo 获取专利信息
|
||||||
|
func (that *company) GetCompanyPatentsInfo(name string) (Map, error) {
|
||||||
|
url := "/getCompanyPatentsInfo/"
|
||||||
|
|
||||||
|
body, err := that.basePost(url, name)
|
||||||
|
return ObjToMap(body), err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCompanyTrademarksInfo 获取商标信息
|
||||||
|
func (that *company) GetCompanyTrademarksInfo(name string) (Map, error) {
|
||||||
|
url := "/getCompanyTrademarksInfo/"
|
||||||
|
|
||||||
|
body, err := that.basePost(url, name)
|
||||||
|
return ObjToMap(body), err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCompanySoftwareCopyrightsInfo 获取软著信息
|
||||||
|
func (that *company) GetCompanySoftwareCopyrightsInfo(name string) (Map, error) {
|
||||||
|
url := "/getCompanySoftwareCopyrightsInfo/"
|
||||||
|
|
||||||
|
body, err := that.basePost(url, name)
|
||||||
|
return ObjToMap(body), err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCompanyOtherCopyrightsInfo 获取其他著作信息
|
||||||
|
func (that *company) GetCompanyOtherCopyrightsInfo(name string) (Map, error) {
|
||||||
|
url := "/getCompanyOtherCopyrightsInfo/"
|
||||||
|
|
||||||
|
body, err := that.basePost(url, name)
|
||||||
|
return ObjToMap(body), err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCompanyProfileTags 获取大数据标签
|
||||||
|
func (that *company) GetCompanyProfileTags(name string) (Map, error) {
|
||||||
|
url := "/getCompanyProfileTags/"
|
||||||
|
body, err := that.basePost(url, name)
|
||||||
|
return ObjToMap(body), err
|
||||||
|
}
|
||||||
|
func (that *company) basePost(url string, name string) (string, error) {
|
||||||
|
|
||||||
|
client := &http.Client{}
|
||||||
|
|
||||||
|
reqest, err := http.NewRequest("GET", that.Url+url+name+"/?isRaiseErrorCode=1", nil)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Fatal error ", err.Error())
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
reqest.Header.Add("Authorization", "APPCODE "+that.ApiCode)
|
||||||
|
response, err := client.Do(reqest)
|
||||||
|
defer response.Body.Close()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Fatal error ", err.Error())
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
body, err := ioutil.ReadAll(response.Body)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
res := string(body)
|
||||||
|
fmt.Println(res)
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package baidu
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
)
|
||||||
|
|
||||||
|
type baiduMap struct {
|
||||||
|
Ak string
|
||||||
|
Url string
|
||||||
|
}
|
||||||
|
|
||||||
|
var BaiDuMap = baiduMap{}
|
||||||
|
|
||||||
|
func (that *baiduMap) Init(Ak string) {
|
||||||
|
//"ak=ZeT902EZvVgIoGVWEFK3osUm"
|
||||||
|
that.Ak = Ak
|
||||||
|
that.Url = "https://api.map.baidu.com/place/v2/suggestion?output=json" + "&ak=" + Ak
|
||||||
|
//query
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPosition 获取定位列表
|
||||||
|
func (that *baiduMap) GetPosition(name string, region string) (string, error) {
|
||||||
|
|
||||||
|
client := &http.Client{}
|
||||||
|
if region == "" {
|
||||||
|
region = "全国"
|
||||||
|
}
|
||||||
|
reqest, err := http.NewRequest("GET", that.Url+"&query="+url.PathEscape(name)+"®ion="+url.PathEscape(region), nil)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Fatal error ", err.Error())
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
response, err := client.Do(reqest)
|
||||||
|
defer response.Body.Close()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Fatal error ", err.Error())
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
body, err := ioutil.ReadAll(response.Body)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
//fmt.Println(string(body))
|
||||||
|
|
||||||
|
return string(body), err
|
||||||
|
|
||||||
|
}
|
||||||
+18
-16
@@ -10,31 +10,33 @@ import (
|
|||||||
//"fmt"
|
//"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DDY struct {
|
type dingdongyun struct {
|
||||||
ApiKey string
|
ApiKey string
|
||||||
YzmUrl string
|
YzmUrl string
|
||||||
TzUrl string
|
TzUrl string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *DDY) Init(apikey string) {
|
var DDY = dingdongyun{}
|
||||||
this.ApiKey = apikey
|
|
||||||
this.YzmUrl = "https://api.dingdongcloud.com/v2/sms/single_send"
|
func (that *dingdongyun) Init(apikey string) {
|
||||||
this.TzUrl = "https://api.dingdongcloud.com/v1/sms/notice/multi_send"
|
that.ApiKey = apikey
|
||||||
|
that.YzmUrl = "https://api.dingdongcloud.com/v2/sms/captcha/send.json"
|
||||||
|
that.TzUrl = "https://api.dingdongcloud.com/v2/sms/notice/send.json"
|
||||||
}
|
}
|
||||||
|
|
||||||
//发送短信验证码 code验证码如:123456 返回true表示发送成功flase表示发送失败
|
// SendYZM 发送短信验证码 code验证码如:123456 返回true表示发送成功flase表示发送失败
|
||||||
func (this *DDY) SendYZM(umoblie string, tpt string, data map[string]string) (bool, error) {
|
func (that *dingdongyun) SendYZM(umoblie string, tpt string, data map[string]string) (bool, error) {
|
||||||
for k, v := range data {
|
for k, v := range data {
|
||||||
tpt = strings.Replace(tpt, "{"+k+"}", v, -1)
|
tpt = strings.Replace(tpt, "{"+k+"}", v, -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.send(this.YzmUrl, umoblie, tpt)
|
return that.send(that.YzmUrl, umoblie, tpt)
|
||||||
}
|
}
|
||||||
|
|
||||||
//发送通知
|
// SendTz 发送通知
|
||||||
func (this *DDY) SendTz(umoblie []string, tpt string, data map[string]string) (bool, error) {
|
func (that *dingdongyun) SendTz(umoblie []string, tpt string, data map[string]string) (bool, error) {
|
||||||
for k, v := range data {
|
for k, v := range data {
|
||||||
tpt = strings.Replace(tpt, "["+k+"]", v, -1)
|
tpt = strings.Replace(tpt, "{"+k+"}", v, -1)
|
||||||
}
|
}
|
||||||
umobleStr := ""
|
umobleStr := ""
|
||||||
for i, v := range umoblie {
|
for i, v := range umoblie {
|
||||||
@@ -44,14 +46,14 @@ func (this *DDY) SendTz(umoblie []string, tpt string, data map[string]string) (b
|
|||||||
}
|
}
|
||||||
umobleStr += "," + v
|
umobleStr += "," + v
|
||||||
}
|
}
|
||||||
return this.send(this.TzUrl, umobleStr, tpt)
|
return that.send(that.TzUrl, umobleStr, tpt)
|
||||||
}
|
}
|
||||||
|
|
||||||
//发送短信
|
//发送短信
|
||||||
func (this *DDY) send(mUrl string, umoblie string, content string) (bool, error) {
|
func (that *dingdongyun) send(mUrl string, umoblie string, content string) (bool, error) {
|
||||||
|
|
||||||
data_send_sms_yzm := url.Values{"apikey": {this.ApiKey}, "mobile": {umoblie}, "content": {content}}
|
data_send_sms_yzm := url.Values{"apikey": {that.ApiKey}, "mobile": {umoblie}, "content": {content}}
|
||||||
res, err := this.httpsPostForm(mUrl, data_send_sms_yzm)
|
res, err := that.httpsPostForm(mUrl, data_send_sms_yzm)
|
||||||
if err != nil && res == "" {
|
if err != nil && res == "" {
|
||||||
return false, errors.New("连接错误")
|
return false, errors.New("连接错误")
|
||||||
}
|
}
|
||||||
@@ -73,7 +75,7 @@ func (this *DDY) send(mUrl string, umoblie string, content string) (bool, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//调用url发送短信的连接
|
//调用url发送短信的连接
|
||||||
func (this *DDY) httpsPostForm(url string, data url.Values) (string, error) {
|
func (that *dingdongyun) httpsPostForm(url string, data url.Values) (string, error) {
|
||||||
resp, err := http.PostForm(url, data)
|
resp, err := http.PostForm(url, data)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
package download
|
package download
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "../../common"
|
|
||||||
"bytes"
|
"bytes"
|
||||||
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
//下载文件
|
// Down 下载文件
|
||||||
func Down(url, path, name string, e ...*Error) bool {
|
func Down(url, path, name string, e ...*Error) bool {
|
||||||
|
|
||||||
os.MkdirAll(path, os.ModeDir)
|
os.MkdirAll(path, os.ModeDir)
|
||||||
|
|||||||
@@ -0,0 +1,143 @@
|
|||||||
|
package rsa
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/rand"
|
||||||
|
"crypto/rsa"
|
||||||
|
"crypto/x509"
|
||||||
|
"encoding/asn1"
|
||||||
|
"encoding/pem"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func FileGet(path string) []byte {
|
||||||
|
file, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
//读取文件的内容
|
||||||
|
info, _ := file.Stat()
|
||||||
|
buf := make([]byte, info.Size())
|
||||||
|
file.Read(buf)
|
||||||
|
return buf
|
||||||
|
}
|
||||||
|
|
||||||
|
// RSA_Encrypt RSA加密
|
||||||
|
// plainText 要加密的数据
|
||||||
|
// path 公钥匙文件地址
|
||||||
|
func RSA_Encrypt(plainText []byte, buf []byte) []byte {
|
||||||
|
//pem解码
|
||||||
|
block, _ := pem.Decode(buf)
|
||||||
|
//x509解码
|
||||||
|
|
||||||
|
publicKeyInterface, err := x509.ParsePKIXPublicKey(block.Bytes)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
//类型断言
|
||||||
|
publicKey := publicKeyInterface.(*rsa.PublicKey)
|
||||||
|
//对明文进行加密
|
||||||
|
cipherText, err := rsa.EncryptPKCS1v15(rand.Reader, publicKey, plainText)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
//返回密文
|
||||||
|
return cipherText
|
||||||
|
}
|
||||||
|
|
||||||
|
// RSA_Decrypt RSA解密
|
||||||
|
// cipherText 需要解密的byte数据
|
||||||
|
// path 私钥文件路径
|
||||||
|
func RSA_Decrypt(cipherText []byte, buf []byte) []byte {
|
||||||
|
|
||||||
|
//pem解码
|
||||||
|
block, _ := pem.Decode(buf)
|
||||||
|
//X509解码
|
||||||
|
private, err := x509.ParsePKCS8PrivateKey(block.Bytes)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
//对密文进行解密
|
||||||
|
//plainText,_:=rsa.DecryptPKCS1v15(rand.Reader,privateKey,cipherText)
|
||||||
|
|
||||||
|
v, err := rsa.DecryptPKCS1v15(rand.Reader, private.(*rsa.PrivateKey), cipherText)
|
||||||
|
//返回明文
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
func MarshalPKCS8PrivateKey(key *rsa.PrivateKey) []byte {
|
||||||
|
info := struct {
|
||||||
|
Version int
|
||||||
|
PrivateKeyAlgorithm []asn1.ObjectIdentifier
|
||||||
|
PrivateKey []byte
|
||||||
|
}{}
|
||||||
|
info.Version = 0
|
||||||
|
info.PrivateKeyAlgorithm = make([]asn1.ObjectIdentifier, 1)
|
||||||
|
info.PrivateKeyAlgorithm[0] = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 1, 1}
|
||||||
|
info.PrivateKey = x509.MarshalPKCS1PrivateKey(key)
|
||||||
|
|
||||||
|
k, err := asn1.Marshal(info)
|
||||||
|
if err != nil {
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
|
return k
|
||||||
|
}
|
||||||
|
|
||||||
|
func Demo() {
|
||||||
|
//生成密钥对,保存到文件
|
||||||
|
GenerateRSAKey(2048, "./")
|
||||||
|
//加密
|
||||||
|
data := []byte("hello world")
|
||||||
|
encrypt := RSA_Encrypt(data, FileGet("public.pem"))
|
||||||
|
fmt.Println(string(encrypt))
|
||||||
|
|
||||||
|
// 解密
|
||||||
|
decrypt := RSA_Decrypt(encrypt, FileGet("private.pem"))
|
||||||
|
fmt.Println(string(decrypt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenerateRSAKey 生成RSA私钥和公钥,保存到文件中
|
||||||
|
// bits 证书大小
|
||||||
|
func GenerateRSAKey(bits int, path string) {
|
||||||
|
//GenerateKey函数使用随机数据生成器random生成一对具有指定字位数的RSA密钥
|
||||||
|
//Reader是一个全局、共享的密码用强随机数生成器
|
||||||
|
privateKey, err := rsa.GenerateKey(rand.Reader, bits)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
//保存私钥
|
||||||
|
//通过x509标准将得到的ras私钥序列化为ASN.1 的 DER编码字符串
|
||||||
|
X509PrivateKey := x509.MarshalPKCS1PrivateKey(privateKey)
|
||||||
|
//使用pem格式对x509输出的内容进行编码
|
||||||
|
//创建文件保存私钥
|
||||||
|
privateFile, err := os.Create(path + "private.pem")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer privateFile.Close()
|
||||||
|
//构建一个pem.Block结构体对象
|
||||||
|
privateBlock := pem.Block{Type: "RSA Private Key", Bytes: X509PrivateKey}
|
||||||
|
//将数据保存到文件
|
||||||
|
pem.Encode(privateFile, &privateBlock)
|
||||||
|
|
||||||
|
//保存公钥
|
||||||
|
//获取公钥的数据
|
||||||
|
publicKey := privateKey.PublicKey
|
||||||
|
//X509对公钥编码
|
||||||
|
X509PublicKey, err := x509.MarshalPKIXPublicKey(&publicKey)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
//pem格式编码
|
||||||
|
//创建用于保存公钥的文件
|
||||||
|
publicFile, err := os.Create(path + "public.pem")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer publicFile.Close()
|
||||||
|
//创建一个pem.Block结构体对象
|
||||||
|
publicBlock := pem.Block{Type: "RSA Public Key", Bytes: X509PublicKey}
|
||||||
|
//保存到文件
|
||||||
|
pem.Encode(publicFile, &publicBlock)
|
||||||
|
}
|
||||||
@@ -0,0 +1,119 @@
|
|||||||
|
package tencent
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
|
"crypto/hmac"
|
||||||
|
"crypto/sha1"
|
||||||
|
"encoding/base64"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
gourl "net/url"
|
||||||
|
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type company struct {
|
||||||
|
secretId string
|
||||||
|
secretKey string
|
||||||
|
}
|
||||||
|
|
||||||
|
var Company = company{}
|
||||||
|
|
||||||
|
func (that *company) Init(secretId, secretKey string) {
|
||||||
|
// 云市场分配的密钥Id
|
||||||
|
//secretId := "xxxx"
|
||||||
|
//// 云市场分配的密钥Key
|
||||||
|
//secretKey := "xxxx"
|
||||||
|
that.secretId = secretId
|
||||||
|
that.secretKey = secretKey
|
||||||
|
}
|
||||||
|
|
||||||
|
func (that *company) calcAuthorization(source string) (auth string, datetime string, err error) {
|
||||||
|
|
||||||
|
timeLocation, _ := time.LoadLocation("Etc/GMT")
|
||||||
|
datetime = time.Now().In(timeLocation).Format("Mon, 02 Jan 2006 15:04:05 GMT")
|
||||||
|
signStr := fmt.Sprintf("x-date: %s\nx-source: %s", datetime, source)
|
||||||
|
|
||||||
|
// hmac-sha1
|
||||||
|
mac := hmac.New(sha1.New, []byte(that.secretKey))
|
||||||
|
mac.Write([]byte(signStr))
|
||||||
|
sign := base64.StdEncoding.EncodeToString(mac.Sum(nil))
|
||||||
|
|
||||||
|
auth = fmt.Sprintf("hmac id=\"%s\", algorithm=\"hmac-sha1\", headers=\"x-date x-source\", signature=\"%s\"",
|
||||||
|
that.secretId, sign)
|
||||||
|
|
||||||
|
return auth, datetime, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (that *company) urlencode(params map[string]string) string {
|
||||||
|
var p = gourl.Values{}
|
||||||
|
for k, v := range params {
|
||||||
|
p.Add(k, v)
|
||||||
|
}
|
||||||
|
return p.Encode()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (that *company) GetCompany(name string) Map {
|
||||||
|
// 云市场分配的密钥Id
|
||||||
|
//secretId := "xxxx"
|
||||||
|
//// 云市场分配的密钥Key
|
||||||
|
//secretKey := "xxxx"
|
||||||
|
source := "market"
|
||||||
|
|
||||||
|
// 签名
|
||||||
|
auth, datetime, _ := that.calcAuthorization(source)
|
||||||
|
|
||||||
|
// 请求方法
|
||||||
|
method := "GET"
|
||||||
|
// 请求头
|
||||||
|
headers := map[string]string{"X-Source": source, "X-Date": datetime, "Authorization": auth}
|
||||||
|
|
||||||
|
// 查询参数
|
||||||
|
queryParams := make(map[string]string)
|
||||||
|
queryParams["keyword"] = name
|
||||||
|
// body参数
|
||||||
|
bodyParams := make(map[string]string)
|
||||||
|
|
||||||
|
// url参数拼接
|
||||||
|
url := "https://service-3jnh3ku8-1256140209.gz.apigw.tencentcs.com/release/business4/geet"
|
||||||
|
if len(queryParams) > 0 {
|
||||||
|
url = fmt.Sprintf("%s?%s", url, that.urlencode(queryParams))
|
||||||
|
}
|
||||||
|
|
||||||
|
bodyMethods := map[string]bool{"POST": true, "PUT": true, "PATCH": true}
|
||||||
|
var body io.Reader = nil
|
||||||
|
if bodyMethods[method] {
|
||||||
|
body = strings.NewReader(that.urlencode(bodyParams))
|
||||||
|
headers["Content-Type"] = "application/x-www-form-urlencoded"
|
||||||
|
}
|
||||||
|
|
||||||
|
client := &http.Client{
|
||||||
|
Timeout: 5 * time.Second,
|
||||||
|
}
|
||||||
|
request, err := http.NewRequest(method, url, body)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
for k, v := range headers {
|
||||||
|
request.Header.Set(k, v)
|
||||||
|
}
|
||||||
|
response, err := client.Do(request)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
defer response.Body.Close()
|
||||||
|
|
||||||
|
bodyBytes, err := ioutil.ReadAll(response.Body)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
res := string(bodyBytes)
|
||||||
|
fmt.Println(res)
|
||||||
|
return ObjToMap(res)
|
||||||
|
}
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
package tencent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||||
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
|
||||||
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||||
|
ocr "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr/v20181119"
|
||||||
|
)
|
||||||
|
|
||||||
|
type tencent struct {
|
||||||
|
secretId string
|
||||||
|
secretKey string
|
||||||
|
credential *common.Credential
|
||||||
|
}
|
||||||
|
|
||||||
|
var Tencent = tencent{}
|
||||||
|
|
||||||
|
func (that *tencent) Init(secretId, secretKey string) {
|
||||||
|
// 云市场分配的密钥Id
|
||||||
|
//secretId := "xxxx"
|
||||||
|
//// 云市场分配的密钥Key
|
||||||
|
//secretKey := "xxxx"
|
||||||
|
that.secretId = secretId
|
||||||
|
that.secretKey = secretKey
|
||||||
|
that.credential = common.NewCredential(
|
||||||
|
that.secretId,
|
||||||
|
that.secretKey,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (that *tencent) OCRCOMPANY(base64Str string) string {
|
||||||
|
|
||||||
|
cpf := profile.NewClientProfile()
|
||||||
|
cpf.HttpProfile.Endpoint = "ocr.tencentcloudapi.com"
|
||||||
|
client, _ := ocr.NewClient(that.credential, "ap-guangzhou", cpf)
|
||||||
|
|
||||||
|
request := ocr.NewBizLicenseOCRRequest()
|
||||||
|
|
||||||
|
//request.ImageUrl = common.StringPtr("https://img0.baidu.com/it/u=2041013181,3227632688&fm=26&fmt=auto")
|
||||||
|
request.ImageBase64 = common.StringPtr(base64Str)
|
||||||
|
|
||||||
|
response, err := client.BizLicenseOCR(request)
|
||||||
|
if _, ok := err.(*errors.TencentCloudSDKError); ok {
|
||||||
|
fmt.Println("An API error has returned: %s", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("An API error has returned: %s", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
//fmt.Printf("%s", response.ToJsonString())
|
||||||
|
|
||||||
|
return response.ToJsonString()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (that *tencent) OCR(base64Str string) string {
|
||||||
|
|
||||||
|
cpf := profile.NewClientProfile()
|
||||||
|
cpf.HttpProfile.Endpoint = "ocr.tencentcloudapi.com"
|
||||||
|
client, _ := ocr.NewClient(that.credential, "ap-guangzhou", cpf)
|
||||||
|
|
||||||
|
request := ocr.NewGeneralAccurateOCRRequest()
|
||||||
|
|
||||||
|
//request.ImageUrl = common.StringPtr("https://img0.baidu.com/it/u=2041013181,3227632688&fm=26&fmt=auto")
|
||||||
|
request.ImageBase64 = common.StringPtr(base64Str)
|
||||||
|
|
||||||
|
response, err := client.GeneralAccurateOCR(request)
|
||||||
|
if _, ok := err.(*errors.TencentCloudSDKError); ok {
|
||||||
|
fmt.Println("An API error has returned: %s", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("An API error has returned: %s", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
//fmt.Printf("%s", response.ToJsonString())
|
||||||
|
|
||||||
|
return response.ToJsonString()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (that *tencent) Qrcode(base64Str string) string {
|
||||||
|
|
||||||
|
cpf := profile.NewClientProfile()
|
||||||
|
cpf.HttpProfile.Endpoint = "ocr.tencentcloudapi.com"
|
||||||
|
client, _ := ocr.NewClient(that.credential, "ap-guangzhou", cpf)
|
||||||
|
|
||||||
|
request := ocr.NewQrcodeOCRRequest()
|
||||||
|
|
||||||
|
request.ImageBase64 = common.StringPtr(base64Str)
|
||||||
|
|
||||||
|
response, err := client.QrcodeOCR(request)
|
||||||
|
if _, ok := err.(*errors.TencentCloudSDKError); ok {
|
||||||
|
fmt.Println("An API error has returned: %s", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("An API error has returned: %s", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
//fmt.Printf("%s", response.ToJsonString())
|
||||||
|
|
||||||
|
return response.ToJsonString()
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package upload
|
package upload
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "../../common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
@@ -15,7 +15,7 @@ type Upload struct {
|
|||||||
Path string
|
Path string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Upload) UpFile(Request *http.Request, fieldName, savefilepath, savePath string) (string, error) {
|
func (that *Upload) UpFile(Request *http.Request, fieldName, savefilepath, savePath string) (string, error) {
|
||||||
Request.ParseMultipartForm(32 << 20)
|
Request.ParseMultipartForm(32 << 20)
|
||||||
var filePath string
|
var filePath string
|
||||||
files := Request.MultipartForm.File
|
files := Request.MultipartForm.File
|
||||||
@@ -36,7 +36,7 @@ func (this *Upload) UpFile(Request *http.Request, fieldName, savefilepath, saveP
|
|||||||
data := time.Unix(int64(t), 0).Format("2006-01")
|
data := time.Unix(int64(t), 0).Format("2006-01")
|
||||||
path := ""
|
path := ""
|
||||||
if strings.EqualFold(savefilepath, "") {
|
if strings.EqualFold(savefilepath, "") {
|
||||||
path = this.Path + data
|
path = that.Path + data
|
||||||
} else {
|
} else {
|
||||||
path = savefilepath + data
|
path = savefilepath + data
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ func (this *Upload) UpFile(Request *http.Request, fieldName, savefilepath, saveP
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
filename := time.Unix(int64(t), 0).Format("2006-01-02-15-22-25") + ObjToStr(Rand(6))
|
filename := time.Unix(int64(t), 0).Format("2006-01-02-15-22-25") + ObjToStr(Rand(6))
|
||||||
filePath = path + "/" + filename + this.Path
|
filePath = path + "/" + filename + that.Path
|
||||||
} else {
|
} else {
|
||||||
filePath = savePath
|
filePath = savePath
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package wechat
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/silenceper/wechat/v2"
|
||||||
|
"github.com/silenceper/wechat/v2/cache"
|
||||||
|
"github.com/silenceper/wechat/v2/officialaccount"
|
||||||
|
h5config "github.com/silenceper/wechat/v2/officialaccount/config"
|
||||||
|
"github.com/silenceper/wechat/v2/officialaccount/js"
|
||||||
|
"github.com/silenceper/wechat/v2/officialaccount/oauth"
|
||||||
|
)
|
||||||
|
|
||||||
|
//基于此文档开发
|
||||||
|
//https://github.com/silenceper/wechat/blob/v2/doc/api/officialaccount.md
|
||||||
|
type h5Program struct {
|
||||||
|
Memory *cache.Memory
|
||||||
|
Config *h5config.Config
|
||||||
|
*officialaccount.OfficialAccount
|
||||||
|
weixin *wechat.Wechat //微信登录实例
|
||||||
|
}
|
||||||
|
|
||||||
|
var H5Program = h5Program{}
|
||||||
|
|
||||||
|
// Init 初始化
|
||||||
|
func (that *h5Program) Init(appid string, appsecret string) {
|
||||||
|
that.weixin = wechat.NewWechat()
|
||||||
|
that.Memory = cache.NewMemory()
|
||||||
|
that.Config = &h5config.Config{
|
||||||
|
AppID: appid,
|
||||||
|
AppSecret: appsecret,
|
||||||
|
//Token: "xxx",
|
||||||
|
//EncodingAESKey: "xxxx",
|
||||||
|
Cache: that.Memory,
|
||||||
|
}
|
||||||
|
that.OfficialAccount = that.weixin.GetOfficialAccount(that.Config)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetUserInfo 获取用户信息
|
||||||
|
func (that *h5Program) GetUserInfo(code string) (appid string, resToken oauth.ResAccessToken, userInfo oauth.UserInfo, err error) {
|
||||||
|
auth := that.GetOauth()
|
||||||
|
//weixin.GetOpenPlatform()
|
||||||
|
resToken, err = auth.GetUserAccessToken(code)
|
||||||
|
if err != nil {
|
||||||
|
|
||||||
|
return auth.AppID, resToken, userInfo, err
|
||||||
|
}
|
||||||
|
|
||||||
|
//getUserInfo
|
||||||
|
userInfo, err = auth.GetUserInfo(resToken.AccessToken, resToken.OpenID, "")
|
||||||
|
if err != nil {
|
||||||
|
return auth.AppID, resToken, userInfo, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return auth.AppID, resToken, userInfo, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSignUrl js url签名
|
||||||
|
func (that *h5Program) GetSignUrl(signUrl string) (*js.Config, error) {
|
||||||
|
|
||||||
|
js := that.OfficialAccount.GetJs()
|
||||||
|
cfg1, e := js.GetConfig(signUrl)
|
||||||
|
if e != nil {
|
||||||
|
return nil, e
|
||||||
|
}
|
||||||
|
|
||||||
|
return cfg1, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSignUrl js url签名
|
||||||
|
//func (that *h5Program) GetJsPay(signUrl string) (*js.Config, error) {
|
||||||
|
// //
|
||||||
|
// //js := that.OfficialAccount().GetJs()
|
||||||
|
// //
|
||||||
|
// //cfg1, e := js.GetConfig(signUrl)
|
||||||
|
// //if e != nil {
|
||||||
|
// // return nil, e
|
||||||
|
// //}
|
||||||
|
//
|
||||||
|
// return cfg1, nil
|
||||||
|
//}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package wechat
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"github.com/silenceper/wechat/v2"
|
||||||
|
"github.com/silenceper/wechat/v2/cache"
|
||||||
|
"github.com/silenceper/wechat/v2/miniprogram"
|
||||||
|
"github.com/silenceper/wechat/v2/miniprogram/auth"
|
||||||
|
"github.com/silenceper/wechat/v2/miniprogram/config"
|
||||||
|
"github.com/silenceper/wechat/v2/miniprogram/encryptor"
|
||||||
|
)
|
||||||
|
|
||||||
|
type miniProgram struct {
|
||||||
|
Memory *cache.Memory
|
||||||
|
Config *config.Config
|
||||||
|
weixin *wechat.Wechat //微信登录实例
|
||||||
|
*miniprogram.MiniProgram
|
||||||
|
}
|
||||||
|
|
||||||
|
var MiniProgram = miniProgram{}
|
||||||
|
|
||||||
|
// Init 初始化
|
||||||
|
func (that *miniProgram) Init(appid string, appsecret string) {
|
||||||
|
|
||||||
|
that.weixin = wechat.NewWechat()
|
||||||
|
that.Memory = cache.NewMemory()
|
||||||
|
that.Config = &config.Config{
|
||||||
|
AppID: appid,
|
||||||
|
AppSecret: appsecret,
|
||||||
|
//Token: "xxx",
|
||||||
|
//EncodingAESKey: "xxxx",
|
||||||
|
Cache: that.Memory,
|
||||||
|
}
|
||||||
|
that.MiniProgram = that.weixin.GetMiniProgram(that.Config)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (that *miniProgram) GetBaseUserInfo(code string) (appid string, re auth.ResCode2Session, err error) {
|
||||||
|
appid = that.Config.AppID
|
||||||
|
a := that.GetAuth()
|
||||||
|
re, err = a.Code2Session(code)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return appid, re, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return appid, re, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (that *miniProgram) GetPhoneNumber(sessionkey, encryptedData, iv string) (appid string, re *encryptor.PlainData, err error) {
|
||||||
|
appid = that.Config.AppID
|
||||||
|
|
||||||
|
if sessionkey == "" || encryptedData == "" || iv == "" {
|
||||||
|
return appid, re, errors.New("参数不足")
|
||||||
|
}
|
||||||
|
|
||||||
|
eny := that.GetEncryptor()
|
||||||
|
|
||||||
|
re, err = eny.Decrypt(sessionkey, encryptedData, iv)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return appid, re, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return appid, re, err
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
package wechat
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"github.com/go-pay/gopay"
|
||||||
|
"github.com/go-pay/gopay/wechat/v3"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
//基于此文档开发
|
||||||
|
//https://github.com/silenceper/wechat/blob/v2/doc/api/officialaccount.md
|
||||||
|
type wxpay struct {
|
||||||
|
client *wechat.ClientV3
|
||||||
|
ctx context.Context
|
||||||
|
apiV3Key string
|
||||||
|
MchId string
|
||||||
|
}
|
||||||
|
|
||||||
|
var WxPay = wxpay{}
|
||||||
|
|
||||||
|
// Init 初始化
|
||||||
|
func (that *wxpay) Init(MchId, SerialNo, APIv3Key, PrivateKey string) {
|
||||||
|
client, err := wechat.NewClientV3(MchId, SerialNo, APIv3Key, PrivateKey)
|
||||||
|
if err != nil {
|
||||||
|
//xlog.Error(err)
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
that.client = client
|
||||||
|
that.apiV3Key = APIv3Key
|
||||||
|
that.MchId = MchId
|
||||||
|
// 设置微信平台API证书和序列号(如开启自动验签,请忽略此步骤)
|
||||||
|
//client.SetPlatformCert([]byte(""), "")
|
||||||
|
that.ctx = context.Background()
|
||||||
|
// 启用自动同步返回验签,并定时更新微信平台API证书(开启自动验签时,无需单独设置微信平台API证书和序列号)
|
||||||
|
err = client.AutoVerifySign()
|
||||||
|
if err != nil {
|
||||||
|
//xlog.Error(err)
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 打开Debug开关,输出日志,默认是关闭的
|
||||||
|
client.DebugSwitch = gopay.DebugOn
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetUserInfo 获取用户信息
|
||||||
|
func (that *wxpay) GetJsOrder(money int64, appid, openid, name, tradeNo, notifyUrl string) (jsApiParams *wechat.JSAPIPayParams, err error) {
|
||||||
|
fmt.Println("dasdas", money, appid, name, tradeNo, notifyUrl)
|
||||||
|
PrepayId, err := that.getPrepayId(money, appid, that.MchId, openid, name, tradeNo, notifyUrl)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
//小程序
|
||||||
|
jsapi, err := that.client.PaySignOfJSAPI(appid, PrepayId)
|
||||||
|
return jsapi, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (that *wxpay) CallbackJsOrder(req *http.Request) (*wechat.V3DecryptResult, error) {
|
||||||
|
|
||||||
|
notifyReq, err := wechat.V3ParseNotify(req)
|
||||||
|
if err != nil {
|
||||||
|
//xlog.Error(err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// wxPublicKey 通过 client.WxPublicKey() 获取
|
||||||
|
err = notifyReq.VerifySignByPK(that.client.WxPublicKey())
|
||||||
|
if err != nil {
|
||||||
|
//xlog.Error(err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========异步通知敏感信息解密========
|
||||||
|
// 普通支付通知解密
|
||||||
|
result, err := notifyReq.DecryptCipherText(that.apiV3Key)
|
||||||
|
|
||||||
|
//that.client.V3TransactionQueryOrder(that.ctx,result.BankType,result.OR)
|
||||||
|
|
||||||
|
return result, err
|
||||||
|
|
||||||
|
// 合单支付通知解密
|
||||||
|
//result, err := notifyReq.DecryptCombineCipherText(apiV3Key)
|
||||||
|
//// 退款通知解密
|
||||||
|
//result, err := notifyReq.DecryptRefundCipherText(apiV3Key)
|
||||||
|
|
||||||
|
// ========异步通知应答========
|
||||||
|
// 退款通知http应答码为200且返回状态码为SUCCESS才会当做商户接收成功,否则会重试。
|
||||||
|
// 注意:重试过多会导致微信支付端积压过多通知而堵塞,影响其他正常通知。
|
||||||
|
|
||||||
|
// 此写法是 gin 框架返回微信的写法
|
||||||
|
//c.JSON(http.StatusOK, &wechat.V3NotifyRsp{Code: gopay.SUCCESS, Message: "成功"})
|
||||||
|
//
|
||||||
|
//// 此写法是 echo 框架返回微信的写法
|
||||||
|
//return c.JSON(http.StatusOK, &wechat.V3NotifyRsp{Code: gopay.SUCCESS, Message: "成功"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetUserInfo 获取用户信息
|
||||||
|
//func (that *wxpay) GetMiniOrder(money int64,appid,name,tradeNo,notifyUrl string) (jsApiParams *wechat.AppletParams,err error){
|
||||||
|
//
|
||||||
|
// PrepayId,err:=that.getPrepayId(money,name,tradeNo,notifyUrl)
|
||||||
|
// if err!=nil{
|
||||||
|
// return nil,err
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// //小程序
|
||||||
|
// applet, err := that.client.PaySignOfApplet(appid,PrepayId)
|
||||||
|
//
|
||||||
|
// return applet,err
|
||||||
|
//}
|
||||||
|
|
||||||
|
func (that *wxpay) getPrepayId(money int64, appid, mchid, openid, name, tradeNo, notifyUrl string) (prepayid string, err error) {
|
||||||
|
expire := time.Now().Add(10 * time.Minute).Format(time.RFC3339)
|
||||||
|
// 初始化 BodyMap
|
||||||
|
bm := make(gopay.BodyMap)
|
||||||
|
bm.Set("appid", appid).
|
||||||
|
Set("mchid", mchid).
|
||||||
|
//Set("sub_mchid", "sub_mchid").
|
||||||
|
Set("description", name).
|
||||||
|
Set("out_trade_no", tradeNo).
|
||||||
|
Set("time_expire", expire).
|
||||||
|
Set("notify_url", notifyUrl).
|
||||||
|
SetBodyMap("amount", func(bm gopay.BodyMap) {
|
||||||
|
bm.Set("total", money).
|
||||||
|
Set("currency", "CNY")
|
||||||
|
}).
|
||||||
|
SetBodyMap("payer", func(bm gopay.BodyMap) {
|
||||||
|
bm.Set("openid", openid)
|
||||||
|
})
|
||||||
|
//ctx:=context.Context()
|
||||||
|
|
||||||
|
wxRsp, err := that.client.V3TransactionJsapi(that.ctx, bm)
|
||||||
|
fmt.Println("获取PrepayId", wxRsp, err)
|
||||||
|
if err != nil {
|
||||||
|
//xlog.Error(err)
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return wxRsp.Response.PrepayId, nil
|
||||||
|
}
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
package admin
|
|
||||||
|
|
||||||
import (
|
|
||||||
. "../../../hotime"
|
|
||||||
. "../../../hotime/common"
|
|
||||||
)
|
|
||||||
|
|
||||||
var ID = "3c5fc9732b8ddcb0a91b428976f2ce86"
|
|
||||||
|
|
||||||
// Project 管理端项目
|
|
||||||
var Project = Proj{
|
|
||||||
//"user": UserCtr,
|
|
||||||
"admin": adminCtr,
|
|
||||||
"category": categoryCtr,
|
|
||||||
"ctg_order_date": ctg_order_dateCtr,
|
|
||||||
"order": orderCtr,
|
|
||||||
"org": orgCtr,
|
|
||||||
"role": roleCtr,
|
|
||||||
"user": userCtr,
|
|
||||||
"hotime": Ctr{
|
|
||||||
"login": func(this *Context) {
|
|
||||||
name := this.Req.FormValue("name")
|
|
||||||
password := this.Req.FormValue("password")
|
|
||||||
if name == "" || password == "" {
|
|
||||||
this.Display(3, "参数不足")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
user := this.Db.Get("admin", "*", Map{"AND": Map{"name": name, "password": Md5(password)}})
|
|
||||||
if user == nil {
|
|
||||||
this.Display(5, "登录失败")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.Session("admin_id", user.GetCeilInt("id"))
|
|
||||||
this.Session("admin_name", name)
|
|
||||||
this.Display(0, this.SessionId)
|
|
||||||
},
|
|
||||||
"logout": func(this *Context) {
|
|
||||||
this.Session("admin_id", nil)
|
|
||||||
this.Session("admin_name", nil)
|
|
||||||
this.Display(0, "退出登录成功")
|
|
||||||
},
|
|
||||||
"info": func(that *Context) {
|
|
||||||
re := that.Db.Get("admin", that.MakeCode.Info("admin"), Map{"id": that.Session("admin_id").ToCeilInt()})
|
|
||||||
|
|
||||||
if re == nil {
|
|
||||||
that.Display(4, "找不到对应信息")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for k, v := range re {
|
|
||||||
|
|
||||||
column := that.MakeCode.TableColumns["admin"][k]
|
|
||||||
if column == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" {
|
|
||||||
re[column.GetString("link")] = that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
that.Display(0, re)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
import (
|
|
||||||
. "../../../hotime"
|
|
||||||
. "../../../hotime/common"
|
|
||||||
)
|
|
||||||
|
|
||||||
var categoryCtr = Ctr{
|
|
||||||
"info": func(that *Context) {
|
|
||||||
parentId := ObjToInt(that.Req.FormValue("id"))
|
|
||||||
//parentId := ObjToInt(that.RouterString[2])
|
|
||||||
childData:=[]Map{}
|
|
||||||
if parentId == 0 {
|
|
||||||
childData1 := that.Db.Select("category", "*", Map{"parent_id": nil})
|
|
||||||
|
|
||||||
for _, v := range childData1 {
|
|
||||||
data := that.Db.Get("category", "*", Map{"parent_id": v.GetCeilInt("id")})
|
|
||||||
childData=append(childData,data)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}else{
|
|
||||||
childData = that.Db.Select("category", "*", Map{"parent_id": parentId})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for _, v := range childData {
|
|
||||||
v["child"] = that.Db.Select("category", "*", Map{"parent_id": v.GetCeilInt("id")})
|
|
||||||
}
|
|
||||||
|
|
||||||
that.Display(0, childData)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
@@ -1,104 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
import (
|
|
||||||
. "../../../hotime"
|
|
||||||
. "../../../hotime/common"
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
var ctg_order_dateCtr = Ctr{
|
|
||||||
|
|
||||||
"info": func(that *Context) {
|
|
||||||
|
|
||||||
//today:=time.Now().Weekday()
|
|
||||||
id := ObjToInt(that.Req.FormValue("id"))
|
|
||||||
category := that.Db.Get("category", "*", Map{"id": id})
|
|
||||||
if category == nil {
|
|
||||||
that.Display(4, "找不到该类别!")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
todayPMTime, _ := time.Parse("2006-01-02 15:04", time.Now().Format("2006-01-02")+" 14:00")
|
|
||||||
todayAMTime, _ := time.Parse("2006-01-02 15:04", time.Now().Format("2006-01-02"+" 09:00"))
|
|
||||||
|
|
||||||
weekDay := 1
|
|
||||||
|
|
||||||
switch time.Now().Weekday().String() {
|
|
||||||
case "Monday":
|
|
||||||
weekDay = 1
|
|
||||||
case "Tuesday":
|
|
||||||
weekDay = 2
|
|
||||||
case "Wednesday":
|
|
||||||
weekDay = 3
|
|
||||||
case "Thursday":
|
|
||||||
weekDay = 4
|
|
||||||
case "Friday":
|
|
||||||
weekDay = 5
|
|
||||||
case "Saturday":
|
|
||||||
weekDay = 6
|
|
||||||
case "Sunday":
|
|
||||||
weekDay = 7
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
////future:=that.Db.Select("ctg_order_date","*",Map{"category_id":that.RouterString[2],"date[>]":time})
|
|
||||||
date := Slice{}
|
|
||||||
for i := 0; i < 7; i++ {
|
|
||||||
day := weekDay + i + 1
|
|
||||||
|
|
||||||
if day > 7 {
|
|
||||||
day = day - 7
|
|
||||||
}
|
|
||||||
if day == 6 || day == 7 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
//fmt.Println(todayAMTime.Unix() + int64(24*60*60*(i+1)))
|
|
||||||
dayAM := that.Db.Get("ctg_order_date", "*", Map{"AND": Map{"category_id": category.GetCeilInt("id"),
|
|
||||||
"date": todayAMTime.Unix() + int64(24*60*60*(i+1))}})
|
|
||||||
if dayAM == nil {
|
|
||||||
dayAM = Map{"name": "9:00-12:00",
|
|
||||||
"date": todayAMTime.Unix() + int64(24*60*60*(i+1)),
|
|
||||||
"create_time": time.Now().Unix(),
|
|
||||||
"modify_time": time.Now().Unix(),
|
|
||||||
"start_sn": category.GetCeilInt("start_sn"),
|
|
||||||
"max_sn": category.GetCeilInt("start_sn") + category.GetCeilInt("am"+ObjToStr(day)),
|
|
||||||
"now_sn": category.GetCeilInt("start_sn"),
|
|
||||||
"category_id": category.GetCeilInt("id"),
|
|
||||||
}
|
|
||||||
dayAM["id"] = that.Db.Insert("ctg_order_date", dayAM)
|
|
||||||
if dayAM.GetCeilInt64("id") == 0 {
|
|
||||||
that.Display(4, "内部错误!")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dayPM := that.Db.Get("ctg_order_date", "*", Map{"AND": Map{"category_id": category.GetCeilInt("id"), "date": todayPMTime.Unix() + int64(24*60*60*(i+1))}})
|
|
||||||
fmt.Println(that.Db.LastQuery, that.Db.LastData, dayPM, that.Db.LastErr)
|
|
||||||
if dayPM == nil {
|
|
||||||
fmt.Println("dasdasdasda")
|
|
||||||
dayPM = Map{"name": "14:00-16:00",
|
|
||||||
"date": todayPMTime.Unix() + int64(24*60*60*(i+1)),
|
|
||||||
"create_time": time.Now().Unix(),
|
|
||||||
"modify_time": time.Now().Unix(),
|
|
||||||
"start_sn": category.GetCeilInt("start_sn"),
|
|
||||||
"max_sn": category.GetCeilInt("start_sn") + category.GetCeilInt("pm"+ObjToStr(day)),
|
|
||||||
"now_sn": category.GetCeilInt("start_sn"),
|
|
||||||
"category_id": category.GetCeilInt("id"),
|
|
||||||
}
|
|
||||||
dayPM["id"] = that.Db.Insert("ctg_order_date", dayPM)
|
|
||||||
if dayPM.GetCeilInt64("id") == 0 {
|
|
||||||
that.Display(4, "内部错误!")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
date = append(date, Map{"name": "星期" + ObjToStr(day) + "(" + time.Unix(todayPMTime.Unix()+int64(24*60*60*(i+1)), 0).Format("01-02") + ")",
|
|
||||||
"am": dayAM,
|
|
||||||
"pm": dayPM,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
that.Display(0, date)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
import (
|
|
||||||
. "../../../hotime"
|
|
||||||
. "../../../hotime/common"
|
|
||||||
"bytes"
|
|
||||||
"crypto/sha256"
|
|
||||||
"encoding/hex"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
var ID = "aad1472b19e575a71ee8f75629e27867"
|
|
||||||
|
|
||||||
// Project 管理端项目
|
|
||||||
var Project = Proj{
|
|
||||||
//"user": UserCtr,
|
|
||||||
"category": categoryCtr,
|
|
||||||
"ctg_order_date": ctg_order_dateCtr,
|
|
||||||
"order": orderCtr,
|
|
||||||
"user": userCtr,
|
|
||||||
"sms": Sms,
|
|
||||||
}
|
|
||||||
|
|
||||||
//生成随机码的4位随机数
|
|
||||||
func getCode() string {
|
|
||||||
//res := ""
|
|
||||||
//for i := 0; i < 4; i++ {
|
|
||||||
res := ObjToStr(RandX(1000, 9999))
|
|
||||||
//}
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
func tencentSendYzm(umobile, code string) error {
|
|
||||||
|
|
||||||
random := RandX(999999, 9999999)
|
|
||||||
url := "https://yun.tim.qq.com/v5/tlssmssvr/sendsms?sdkappid=1400235813&random=" + ObjToStr(random)
|
|
||||||
fmt.Println("URL:>", url)
|
|
||||||
|
|
||||||
h := sha256.New()
|
|
||||||
h.Write([]byte(`appkey=d511de15e5ccb43fc171772dbb8b599f&random=` + ObjToStr(random) + `&time=` + ObjToStr(time.Now().Unix()) + `&mobile=` + umobile))
|
|
||||||
bs := h.Sum(nil)
|
|
||||||
s256 := hex.EncodeToString(bs)
|
|
||||||
|
|
||||||
//json序列化
|
|
||||||
post := `{
|
|
||||||
"ext": "",
|
|
||||||
"extend": "",
|
|
||||||
"params": [
|
|
||||||
"` + code + `"
|
|
||||||
],
|
|
||||||
"sig": "` + s256 + `",
|
|
||||||
"sign": "乐呵呵旅游网",
|
|
||||||
"tel": {
|
|
||||||
"mobile": "` + umobile + `",
|
|
||||||
"nationcode": "86"
|
|
||||||
},
|
|
||||||
"time": ` + ObjToStr(time.Now().Unix()) + `,
|
|
||||||
"tpl_id": 378916
|
|
||||||
}`
|
|
||||||
|
|
||||||
fmt.Println(url, "post", post)
|
|
||||||
|
|
||||||
var jsonStr = []byte(post)
|
|
||||||
fmt.Println("jsonStr", jsonStr)
|
|
||||||
fmt.Println("new_str", bytes.NewBuffer(jsonStr))
|
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
|
|
||||||
// req.Header.Set("X-Custom-Header", "myvalue")
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
|
|
||||||
client := &http.Client{}
|
|
||||||
resp, err := client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
fmt.Println("response Status:", resp.Status)
|
|
||||||
fmt.Println("response Headers:", resp.Header)
|
|
||||||
body, _ := ioutil.ReadAll(resp.Body)
|
|
||||||
fmt.Println("response Body:", string(body))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
import (
|
|
||||||
. "../../../hotime"
|
|
||||||
. "../../../hotime/common"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
var orderCtr = Ctr{
|
|
||||||
"count": func(this *Context) {
|
|
||||||
if this.Session("id").ToCeilInt() == 0 {
|
|
||||||
this.Display(2, "没有登录!")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
re := Map{}
|
|
||||||
re["total"] = this.Db.Count("order", Map{"user_id": this.Session("id").ToCeilInt()})
|
|
||||||
re["finish"] = this.Db.Count("order", Map{"AND": Map{"user_id": this.Session("id").ToCeilInt(), "status": 2}})
|
|
||||||
re["late"] = this.Db.Count("order", Map{"AND": Map{"user_id": this.Session("id").ToCeilInt(), "status": 3}})
|
|
||||||
|
|
||||||
this.Display(0, re)
|
|
||||||
},
|
|
||||||
"add": func(this *Context) {
|
|
||||||
if this.Session("id").ToCeilInt() == 0 {
|
|
||||||
this.Display(2, "没有登录!")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ctgOrderDateId := ObjToInt(this.Req.FormValue("ctg_order_date_id"))
|
|
||||||
//ctgId:=ObjToInt(this.Req.FormValue("category_id"))
|
|
||||||
ctgOrderDate := this.Db.Get("ctg_order_date", "*", Map{"id": ctgOrderDateId})
|
|
||||||
|
|
||||||
if ctgOrderDate.GetCeilInt64("now_sn")+1 > ctgOrderDate.GetCeilInt64("max_sn") {
|
|
||||||
this.Display(5, "当前排号已经用完")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
data := Map{"create_time": time.Now().Unix(),
|
|
||||||
"modify_time": time.Now().Unix(),
|
|
||||||
"user_id": this.Session("id").ToCeilInt(),
|
|
||||||
"date": ctgOrderDate.GetString("date"),
|
|
||||||
"sn": ctgOrderDate.GetCeilInt64("now_sn") + 1,
|
|
||||||
"category_id": ctgOrderDate.GetCeilInt("category_id"),
|
|
||||||
"admin_id": 1,
|
|
||||||
"status": 1,
|
|
||||||
"name": time.Unix(ctgOrderDate.GetCeilInt64("date"), 0).Format("2006-01-02 ") + ctgOrderDate.GetString("name"),
|
|
||||||
}
|
|
||||||
|
|
||||||
data["id"] = this.Db.Insert("order", data)
|
|
||||||
|
|
||||||
if data.GetCeilInt("id") == 0 {
|
|
||||||
this.Display(5, "预约失败")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Db.Update("ctg_order_date", Map{"now_sn": ctgOrderDate.GetCeilInt64("now_sn") + 1, "modify_time": time.Now().Unix()}, Map{"id": ctgOrderDate.GetCeilInt("id")})
|
|
||||||
this.Display(0, data)
|
|
||||||
},
|
|
||||||
"search": func(that *Context) {
|
|
||||||
if that.Session("id").ToCeilInt() == 0 {
|
|
||||||
that.Display(2, "没有登录!")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
data := that.Db.Select("order", "*", Map{"user_id": that.Session("id").ToCeilInt()})
|
|
||||||
for _, v := range data {
|
|
||||||
v["category"] = that.Db.Get("category", "*", Map{"id": v.GetCeilInt("category_id")})
|
|
||||||
v["parent_category"] = that.Db.Get("category", "id,name", Map{"id": v.GetMap("category").GetCeilInt("parent_id")})
|
|
||||||
}
|
|
||||||
that.Display(0, data)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
import (
|
|
||||||
. "../../../hotime"
|
|
||||||
)
|
|
||||||
|
|
||||||
var Sms = Ctr{
|
|
||||||
//只允许微信验证过的或者登录成功的发送短信
|
|
||||||
"send": func(this *Context) {
|
|
||||||
//if this.Session("uid").Data == nil && this.Session("wechatInfo").Data == nil {
|
|
||||||
// this.Display(2, "没有授权")
|
|
||||||
// return
|
|
||||||
//}
|
|
||||||
if len(this.Req.FormValue("token")) != 32 {
|
|
||||||
this.Display(2, "没有授权")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
phone := this.Req.FormValue("phone")
|
|
||||||
if len(phone) < 11 {
|
|
||||||
this.Display(3, "手机号格式错误")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
code := getCode()
|
|
||||||
this.Session("phone", phone)
|
|
||||||
this.Session("code", code)
|
|
||||||
|
|
||||||
tencentSendYzm(phone, code)
|
|
||||||
|
|
||||||
this.Display(0, "发送成功")
|
|
||||||
},
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
import (
|
|
||||||
. "../../../hotime"
|
|
||||||
. "../../../hotime/common"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
var userCtr = Ctr{
|
|
||||||
"token": func(this *Context) {
|
|
||||||
this.Display(0, this.SessionId)
|
|
||||||
},
|
|
||||||
"test": func(this *Context) {
|
|
||||||
this.Session("id", 1)
|
|
||||||
},
|
|
||||||
"add": func(this *Context) {
|
|
||||||
if this.Req.FormValue("code") != this.Session("code").ToStr() ||
|
|
||||||
this.Req.FormValue("phone") != this.Session("phone").ToStr() {
|
|
||||||
this.Display(3, "短信验证不通过")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
phone := this.Req.FormValue("phone")
|
|
||||||
idcard := this.Req.FormValue("idcard")
|
|
||||||
name := this.Req.FormValue("name")
|
|
||||||
|
|
||||||
user := this.Db.Get("user", "*", Map{"phone": phone})
|
|
||||||
|
|
||||||
if user == nil {
|
|
||||||
user = Map{"phone": phone, "idcard": idcard, "name": name, "create_time": time.Now().Unix(), "modify_time": time.Now().Unix()}
|
|
||||||
user["id"] = this.Db.Insert("user", user)
|
|
||||||
|
|
||||||
} else {
|
|
||||||
user["phone"] = phone
|
|
||||||
user["idcard"] = idcard
|
|
||||||
user["name"] = name
|
|
||||||
user["modify_time"] = time.Now().Unix()
|
|
||||||
re := this.Db.Update("user", user, Map{"id": user.GetCeilInt64("id")})
|
|
||||||
if re == 0 {
|
|
||||||
this.Display(4, "系统错误")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if user.GetCeilInt64("id") == 0 {
|
|
||||||
this.Display(5, "登录失败")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Session("id", user.GetCeilInt("id"))
|
|
||||||
this.Display(0, "登录成功")
|
|
||||||
|
|
||||||
},
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
{
|
|
||||||
"cache": {
|
|
||||||
"db": {
|
|
||||||
"db": false,
|
|
||||||
"session": true
|
|
||||||
},
|
|
||||||
"memory": {
|
|
||||||
"db": true,
|
|
||||||
"session": true,
|
|
||||||
"timeout": 7200
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"codeConfig": {
|
|
||||||
"admin": "config/app.json"
|
|
||||||
},
|
|
||||||
"codeConfig1": {
|
|
||||||
"admin": {
|
|
||||||
"config": "config/app.json",
|
|
||||||
"package": "admin",
|
|
||||||
"rule": "config/rule.json"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"crossDomain": "auto",
|
|
||||||
"db": {
|
|
||||||
"mysql": {
|
|
||||||
"host": "192.168.6.253",
|
|
||||||
"name": "bzyy",
|
|
||||||
"password": "dasda8454456",
|
|
||||||
"port": "3306",
|
|
||||||
"prefix": "",
|
|
||||||
"user": "root"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"defFile": [
|
|
||||||
"index.html",
|
|
||||||
"index.htm"
|
|
||||||
],
|
|
||||||
"error": {
|
|
||||||
"1": "内部系统异常",
|
|
||||||
"2": "访问权限异常",
|
|
||||||
"3": "请求参数异常",
|
|
||||||
"4": "数据处理异常",
|
|
||||||
"5": "数据结果异常"
|
|
||||||
},
|
|
||||||
"mode": 0,
|
|
||||||
"port": "80",
|
|
||||||
"sessionName": "HOTIME",
|
|
||||||
"tpt": "tpt"
|
|
||||||
}
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
{
|
|
||||||
"cache": {
|
|
||||||
"db": {
|
|
||||||
"db": "默认false,非必须,缓存数据库,启用后能减少数据库的读写压力",
|
|
||||||
"session": "默认true,非必须,缓存web session,同时缓存session保持的用户缓存",
|
|
||||||
"timeout": "默认60 * 60 * 24 * 30,非必须,过期时间,超时自动删除"
|
|
||||||
},
|
|
||||||
"memory": {
|
|
||||||
"db": "默认true,非必须,缓存数据库,启用后能减少数据库的读写压力",
|
|
||||||
"session": "默认true,非必须,缓存web session,同时缓存session保持的用户缓存",
|
|
||||||
"timeout": "默认60 * 60 * 2,非必须,过期时间,超时自动删除"
|
|
||||||
},
|
|
||||||
"redis": {
|
|
||||||
"db": "默认true,非必须,缓存数据库,启用后能减少数据库的读写压力",
|
|
||||||
"host": "默认服务ip:127.0.0.1,必须,如果需要使用redis服务时配置,",
|
|
||||||
"password": "默认密码空,必须,如果需要使用redis服务时配置,默认密码空",
|
|
||||||
"port": "默认服务端口:6379,必须,如果需要使用redis服务时配置,",
|
|
||||||
"session": "默认true,非必须,缓存web session,同时缓存session保持的用户缓存",
|
|
||||||
"timeout": "默认60 * 60 * 24 * 15,非必须,过期时间,超时自动删除"
|
|
||||||
},
|
|
||||||
"注释": "可配置memory,db,redis,默认启用memory,默认优先级为memory\u003eredis\u003edb,memory与数据库缓存设置项一致,缓存数据填充会自动反方向反哺,加入memory缓存过期将自动从redis更新,但memory永远不会更新redis,如果是集群建议不要开启memory,配置即启用"
|
|
||||||
},
|
|
||||||
"codeConfig": {
|
|
||||||
"packageName": "默认无,必须,包名称以及应用名,生成代码的配置文件地址,比如config/app.json,数据库有更新时自动更新配置文件以及对应的生成文件",
|
|
||||||
"注释": "配置即启用,非必须,默认无"
|
|
||||||
},
|
|
||||||
"crossDomain": "默认空 非必须,空字符串为不开启,如果需要跨域设置,auto为智能开启所有网站允许跨域,http://www.baidu.com为指定域允许跨域",
|
|
||||||
"db": {
|
|
||||||
"mysql": {
|
|
||||||
"host": "默认127.0.0.1,必须,数据库ip地址",
|
|
||||||
"name": "默认test,必须,数据库名称",
|
|
||||||
"password": "默认root,必须,数据库密码",
|
|
||||||
"port": "默认3306,必须,数据库端口",
|
|
||||||
"prefix": "默认空,非必须,数据表前缀",
|
|
||||||
"slave": {
|
|
||||||
"host": "默认127.0.0.1,必须,数据库ip地址",
|
|
||||||
"name": "默认test,必须,数据库名称",
|
|
||||||
"password": "默认root,必须,数据库密码",
|
|
||||||
"port": "默认3306,必须,数据库端口",
|
|
||||||
"user": "默认root,必须,数据库用户名",
|
|
||||||
"注释": "从数据库配置,mysql里配置slave项即启用主从读写,减少数据库压力"
|
|
||||||
},
|
|
||||||
"user": "默认root,必须,数据库用户名",
|
|
||||||
"注释": "除prefix及主从数据库slave项,其他全部必须"
|
|
||||||
},
|
|
||||||
"sqlite": {
|
|
||||||
"path": "默认config/data.db,必须,数据库位置"
|
|
||||||
},
|
|
||||||
"注释": "配置即启用,非必须,默认使用sqlite数据库"
|
|
||||||
},
|
|
||||||
"defFile": "默认访问index.html或者index.htm文件,必须,默认访问文件类型",
|
|
||||||
"error": {
|
|
||||||
"1": "内部系统异常,在环境配置,文件访问权限等基础运行环境条件不足造成严重错误时使用",
|
|
||||||
"2": "访问权限异常,没有登录或者登录异常等时候使用",
|
|
||||||
"3": "请求参数异常,request参数不满足要求,比如参数不足,参数类型错误,参数不满足要求等时候使用",
|
|
||||||
"4": "数据处理异常,数据库操作或者三方请求返回的结果非正常结果,比如数据库突然中断等时候使用",
|
|
||||||
"5": "数据结果异常,一般用于无法给出response要求的格式要求下使用,比如response需要的是string格式但你只能提供int数据时",
|
|
||||||
"注释": "web服务内置错误提示,自定义异常建议10开始"
|
|
||||||
},
|
|
||||||
"logFile": "无默认,非必须,如果需要存储日志文件时使用,保存格式为:a/b/c/20060102150405.txt,将生成:a/b/c/年月日时分秒.txt,按需设置",
|
|
||||||
"logLevel": "默认0,必须,0关闭,1打印,日志等级",
|
|
||||||
"mode": "默认0,非必须,0生产模式,1,测试模式,2,开发模式,在开发模式下会显示更多的数据用于开发测试,并能够辅助研发,自动生成配置文件、代码等功能,web无缓存,数据库不启用缓存",
|
|
||||||
"modeRouterStrict": "默认false,必须,路由严格模式false,为大小写忽略必须匹配,true必须大小写匹配",
|
|
||||||
"port": "默认80,必须,web服务开启Http端口,0为不启用http服务,默认80",
|
|
||||||
"sessionName": "默认HOTIME,必须,设置session的cookie名",
|
|
||||||
"tlsCert": "默认空,非必须,https证书",
|
|
||||||
"tlsKey": "默认空,非必须,https密钥",
|
|
||||||
"tlsPort": "默认空,非必须,web服务https端口,0为不启用https服务",
|
|
||||||
"tpt": "默认tpt,必须,web静态文件目录,默认为程序目录下tpt目录",
|
|
||||||
"webConnectLogFile": "无默认,非必须,webConnectLogShow开启之后才能使用,如果需要存储日志文件时使用,保存格式为:a/b/c/20060102150405.txt,将生成:a/b/c/年月日时分秒.txt,按需设置",
|
|
||||||
"webConnectLogShow": "默认true,非必须,访问日志如果需要web访问链接、访问ip、访问时间打印,false为关闭true开启此功能"
|
|
||||||
}
|
|
||||||
Binary file not shown.
-193
@@ -1,193 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"../../hotime"
|
|
||||||
"../../hotime/common"
|
|
||||||
"./admin"
|
|
||||||
"./app"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
fmt.Println(time.Now().Weekday().String())
|
|
||||||
appIns := hotime.Init("config/config.json")
|
|
||||||
//RESTfull接口适配
|
|
||||||
appIns.SetConnectListener(func(context *hotime.Context) bool {
|
|
||||||
|
|
||||||
if len(context.RouterString)>1&& context.RouterString[0] == "admin" {
|
|
||||||
if context.RouterString[1] == "hotime" && context.RouterString[2] == "login" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if context.Session("admin_id").Data == nil {
|
|
||||||
context.Display(2, "你还没有登录")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//文件上传接口
|
|
||||||
if len(context.RouterString) == 1 && context.RouterString[0] == "file" && context.Req.Method == "POST" {
|
|
||||||
|
|
||||||
//读取网络文件
|
|
||||||
fi, fheader, err := context.Req.FormFile("file")
|
|
||||||
if err != nil {
|
|
||||||
context.Display(3, err)
|
|
||||||
return false
|
|
||||||
|
|
||||||
}
|
|
||||||
filePath := context.Config.GetString("filePath")
|
|
||||||
if filePath == "" {
|
|
||||||
filePath = "file/2006/01/02/"
|
|
||||||
}
|
|
||||||
|
|
||||||
path := time.Now().Format(filePath)
|
|
||||||
e := os.MkdirAll(context.Config.GetString("tpt")+"/"+path, os.ModeDir)
|
|
||||||
if e != nil {
|
|
||||||
context.Display(3, e)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
filePath = path + common.Md5(common.ObjToStr(common.RandX(100000, 9999999))) + fheader.Filename[strings.LastIndex(fheader.Filename, "."):]
|
|
||||||
newFile, e := os.Create(context.Config.GetString("tpt") + "/" + filePath)
|
|
||||||
|
|
||||||
if e != nil {
|
|
||||||
context.Display(3, e)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
_, e = io.Copy(newFile, fi)
|
|
||||||
|
|
||||||
if e != nil {
|
|
||||||
context.Display(3, e)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
context.Display(0, filePath)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(context.RouterString) < 2 || len(context.RouterString) > 3 ||
|
|
||||||
!(context.Router[context.RouterString[0]] != nil &&
|
|
||||||
context.Router[context.RouterString[0]][context.RouterString[1]] != nil) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
//排除无效操作
|
|
||||||
if len(context.RouterString) == 2 &&
|
|
||||||
context.Req.Method != "GET" &&
|
|
||||||
context.Req.Method != "POST" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
//列表检索
|
|
||||||
if len(context.RouterString) == 2 &&
|
|
||||||
context.Req.Method == "GET" {
|
|
||||||
if context.Router[context.RouterString[0]][context.RouterString[1]]["search"] == nil {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
context.Router[context.RouterString[0]][context.RouterString[1]]["search"](context)
|
|
||||||
}
|
|
||||||
//新建
|
|
||||||
if len(context.RouterString) == 2 &&
|
|
||||||
context.Req.Method == "POST" {
|
|
||||||
if context.Router[context.RouterString[0]][context.RouterString[1]]["add"] == nil {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
context.Router[context.RouterString[0]][context.RouterString[1]]["add"](context)
|
|
||||||
}
|
|
||||||
if len(context.RouterString) == 3 &&
|
|
||||||
context.Req.Method == "POST" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
//查询单条
|
|
||||||
if len(context.RouterString) == 3 &&
|
|
||||||
context.Req.Method == "GET" {
|
|
||||||
|
|
||||||
if context.Router[context.RouterString[0]][context.RouterString[1]]["info"] == nil {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
context.Router[context.RouterString[0]][context.RouterString[1]]["info"](context)
|
|
||||||
}
|
|
||||||
//更新
|
|
||||||
if len(context.RouterString) == 3 &&
|
|
||||||
context.Req.Method == "PUT" {
|
|
||||||
|
|
||||||
if context.Router[context.RouterString[0]][context.RouterString[1]]["update"] == nil {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
context.Router[context.RouterString[0]][context.RouterString[1]]["update"](context)
|
|
||||||
}
|
|
||||||
//移除
|
|
||||||
if len(context.RouterString) == 3 &&
|
|
||||||
context.Req.Method == "DELETE" {
|
|
||||||
|
|
||||||
if context.Router[context.RouterString[0]][context.RouterString[1]]["remove"] == nil {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
context.Router[context.RouterString[0]][context.RouterString[1]]["remove"](context)
|
|
||||||
}
|
|
||||||
context.View()
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
|
|
||||||
//makeCode := code.MakeCode{}
|
|
||||||
//fmt.Println(common.ObjToStr(makeCode.Db2JSON("admin","test",appIns.Db)))
|
|
||||||
|
|
||||||
appIns.Run(hotime.Router{
|
|
||||||
"admin": admin.Project,
|
|
||||||
"app": app.Project,
|
|
||||||
//"app": hotime.Proj{
|
|
||||||
// "index": hotime.Ctr{
|
|
||||||
// "test": func(this *hotime.Context) {
|
|
||||||
//
|
|
||||||
// data := this.Db.Get("cached", "*")
|
|
||||||
// fmt.Println(data)
|
|
||||||
// fmt.Println(this.Session("test").ToCeilInt())
|
|
||||||
// this.Session("test1", 98984984)
|
|
||||||
// fmt.Println(this.Session("test1").Data)
|
|
||||||
// this.Error.SetError(errors.New("dasdasdas"))
|
|
||||||
// //fmt.Println(this.Db.GetTag())
|
|
||||||
// //this.Application.Log.Error("dasdasdas")
|
|
||||||
// //this.Log.Error("dadasdasd")
|
|
||||||
// //x:=this.Db.Action(func(db hotime.HoTimeDB) bool {
|
|
||||||
// //
|
|
||||||
// // db.Insert("user",hotime.Map{"unickname":"dasdas"})
|
|
||||||
// //
|
|
||||||
// // return true
|
|
||||||
// //})
|
|
||||||
// //hotime.LogError("dasdasdasdasdas")
|
|
||||||
// this.Display(5, "dsadas")
|
|
||||||
// },
|
|
||||||
// "websocket": func(this *hotime.Context) {
|
|
||||||
// hdler := websocket.Handler(func(ws *websocket.Conn) {
|
|
||||||
// for true {
|
|
||||||
// msg := make([]byte, 5120)
|
|
||||||
// n, err := ws.Read(msg)
|
|
||||||
// go func() {
|
|
||||||
// time.Sleep(time.Second * 5)
|
|
||||||
// ws.Write([]byte("dsadasdasgregergrerge"))
|
|
||||||
//
|
|
||||||
// }()
|
|
||||||
// if err != nil {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// fmt.Printf("Receive: %s\n", msg[:n])
|
|
||||||
//
|
|
||||||
// send_msg := "[" + string(msg[:n]) + "]"
|
|
||||||
// m, err := ws.Write([]byte(send_msg))
|
|
||||||
// if err != nil {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// fmt.Printf("Send: %s\n", msg[:m])
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// hdler.ServeHTTP(this.Resp, this.Req)
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
//},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
h3[data-v-b9167eee]{margin:40px 0 0}ul[data-v-b9167eee]{list-style-type:none;padding:0}li[data-v-b9167eee]{display:inline-block;margin:0 10px}a[data-v-b9167eee]{color:#42b983}
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 66 KiB |
Binary file not shown.
Binary file not shown.
@@ -1,3 +0,0 @@
|
|||||||
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="favicon.ico"><title>hotime</title><style>body{
|
|
||||||
margin: 0px;
|
|
||||||
}</style><link href="css/chunk-038340db.e4ca99de.css" rel="prefetch"><link href="css/chunk-0524801b.1e910850.css" rel="prefetch"><link href="css/chunk-1c438cad.2fd7d31d.css" rel="prefetch"><link href="css/chunk-1d1a12b6.8c684de3.css" rel="prefetch"><link href="css/chunk-2c1d9b2f.78c69bda.css" rel="prefetch"><link href="css/chunk-5ccac4d0.5f1c91ca.css" rel="prefetch"><link href="css/chunk-c569a38e.01bc1b83.css" rel="prefetch"><link href="css/chunk-c7a51d14.4a0871eb.css" rel="prefetch"><link href="js/chunk-038340db.3c8b0cb6.js" rel="prefetch"><link href="js/chunk-0524801b.de9b433f.js" rel="prefetch"><link href="js/chunk-14f17cfa.c5104e8c.js" rel="prefetch"><link href="js/chunk-1c438cad.72a22c19.js" rel="prefetch"><link href="js/chunk-1d1a12b6.6900cc01.js" rel="prefetch"><link href="js/chunk-2c1d9b2f.39065c9e.js" rel="prefetch"><link href="js/chunk-5b2ead63.af868ff8.js" rel="prefetch"><link href="js/chunk-5ccac4d0.98ff45de.js" rel="prefetch"><link href="js/chunk-68815fbc.04152d5f.js" rel="prefetch"><link href="js/chunk-c569a38e.16d55c64.js" rel="prefetch"><link href="js/chunk-c7a51d14.3cd28dc4.js" rel="prefetch"><link href="css/app.5e2eb449.css" rel="preload" as="style"><link href="js/app.f5f26baa.js" rel="preload" as="script"><link href="css/app.5e2eb449.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but hotime doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="js/app.f5f26baa.js"></script></body></html>
|
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
module code.hoteas.com/golang/hotime
|
||||||
|
|
||||||
|
go 1.16
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/garyburd/redigo v1.6.3
|
||||||
|
github.com/go-pay/gopay v1.5.78
|
||||||
|
github.com/go-sql-driver/mysql v1.6.0
|
||||||
|
github.com/mattn/go-sqlite3 v1.14.12
|
||||||
|
github.com/silenceper/wechat/v2 v2.1.2
|
||||||
|
github.com/sirupsen/logrus v1.8.1
|
||||||
|
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.364
|
||||||
|
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr v1.0.364
|
||||||
|
golang.org/x/net v0.0.0-20220225172249-27dd8689420f
|
||||||
|
)
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b h1:L/QXpzIa3pOvUGt1D1lA5KjYhPBAN/3iWdP7xeFS9F0=
|
||||||
|
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA=
|
||||||
|
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
|
||||||
|
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
|
||||||
|
github.com/garyburd/redigo v1.6.3 h1:HCeeRluvAgMusMomi1+6Y5dmFOdYV/JzoRrrbFlkGIc=
|
||||||
|
github.com/garyburd/redigo v1.6.3/go.mod h1:rTb6epsqigu3kYKBnaF028A7Tf/Aw5s0cqA47doKKqw=
|
||||||
|
github.com/go-pay/gopay v1.5.78 h1:wIHp8g/jK0ik5bZo2MWt3jAQsktT3nkdXZxlRZvljko=
|
||||||
|
github.com/go-pay/gopay v1.5.78/go.mod h1:M6Nlk2VdZHCbWphOw3rtbnz4SiOk6Xvxg6mxwDfg+Ps=
|
||||||
|
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
|
||||||
|
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||||
|
github.com/gomodule/redigo v1.8.5 h1:nRAxCa+SVsyjSBrtZmG/cqb6VbTmuRzpg/PoTFlpumc=
|
||||||
|
github.com/gomodule/redigo v1.8.5/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0=
|
||||||
|
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
|
||||||
|
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
|
||||||
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
|
github.com/mattn/go-sqlite3 v1.14.12 h1:TJ1bhYJPV44phC+IMu1u2K/i5RriLTPe+yc68XDJ1Z0=
|
||||||
|
github.com/mattn/go-sqlite3 v1.14.12/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||||
|
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
|
||||||
|
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/silenceper/wechat/v2 v2.1.2 h1:+QfIMiYfwST2ZloTwmYp0O0p5Y1LYRZxfLWfMuSE30k=
|
||||||
|
github.com/silenceper/wechat/v2 v2.1.2/go.mod h1:0OprxYCCp2CZAKw06BBlnaczInTk2KxOLsKeiopshGg=
|
||||||
|
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
||||||
|
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||||
|
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
|
||||||
|
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
|
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||||
|
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||||
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.364 h1:X1Jws4XqrTH+p7FBQ7BpjW4qFXObKHWm0/XhW/GvqRs=
|
||||||
|
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.364/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
|
||||||
|
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr v1.0.364 h1:kbor60vo37v7Hu+i17gooox9Rw281fVHNna8zwtDG1w=
|
||||||
|
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr v1.0.364/go.mod h1:LeIUBOLhc+Y5YCEpZrULPD9lgoXXV4/EmIcoEvmHz9c=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||||
|
golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29 h1:tkVvjkPTB7pnW3jnid7kNyAMPVWllTNOf/qKDze4p9o=
|
||||||
|
golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||||
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
|
golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
|
||||||
|
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
|
||||||
|
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||||
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/h2non/gock.v1 v1.0.15 h1:SzLqcIlb/fDfg7UvukMpNcWsu7sI5tWwL+KCATZqks0=
|
||||||
|
gopkg.in/h2non/gock.v1 v1.0.15/go.mod h1:sX4zAkdYX1TRGJ2JY156cFspQn4yRWn6p9EMdODlynE=
|
||||||
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
+6
-6
@@ -44,17 +44,17 @@ func Run() {
|
|||||||
appIns.Run(hotime.Router{
|
appIns.Run(hotime.Router{
|
||||||
"app": hotime.Proj{
|
"app": hotime.Proj{
|
||||||
"index": hotime.Ctr{
|
"index": hotime.Ctr{
|
||||||
"test": func(this *hotime.Context) {
|
"test": func(that *hotime.Context) {
|
||||||
fmt.Println(this.Db.GetTag())
|
fmt.Println(that.Db.GetTag())
|
||||||
//x := this.Db.Action(func(db hotime.HoTimeDB) bool {
|
//x := that.Db.Action(func(db hotime.HoTimeDB) bool {
|
||||||
//
|
//
|
||||||
// db.Insert("user", hotime.Map{"unickname": "dasdas"})
|
// db.Insert("user", hotime.Map{"unickname": "dasdas"})
|
||||||
//
|
//
|
||||||
// return true
|
// return true
|
||||||
//})
|
//})
|
||||||
this.Display(0, 1)
|
that.Display(0, 1)
|
||||||
},
|
},
|
||||||
"websocket": func(this *hotime.Context) {
|
"websocket": func(that *hotime.Context) {
|
||||||
hdler := websocket.Handler(func(ws *websocket.Conn) {
|
hdler := websocket.Handler(func(ws *websocket.Conn) {
|
||||||
for true {
|
for true {
|
||||||
msg := make([]byte, 5120)
|
msg := make([]byte, 5120)
|
||||||
@@ -73,7 +73,7 @@ func Run() {
|
|||||||
fmt.Printf("Send: %s\n", msg[:m])
|
fmt.Printf("Send: %s\n", msg[:m])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
hdler.ServeHTTP(this.Resp, this.Req)
|
hdler.ServeHTTP(that.Resp, that.Req)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
package hotime
|
package hotime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "./cache"
|
. "code.hoteas.com/golang/hotime/cache"
|
||||||
. "./common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
//session对象
|
//session对象
|
||||||
|
|||||||
@@ -5,4 +5,4 @@ type Ctr map[string]Method
|
|||||||
type Proj map[string]Ctr
|
type Proj map[string]Ctr
|
||||||
type Router map[string]Proj
|
type Router map[string]Proj
|
||||||
type MethodRouter map[string]Method //直接字符串关联函数
|
type MethodRouter map[string]Method //直接字符串关联函数
|
||||||
type Method func(this *Context)
|
type Method func(that *Context)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package hotime
|
package hotime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "./common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
var IsRun = false //当前状态
|
var IsRun = false //当前状态
|
||||||
@@ -11,14 +11,16 @@ var App = map[string]*Application{} //整个项目
|
|||||||
|
|
||||||
var Config = Map{
|
var Config = Map{
|
||||||
"mode": 2, //模式 0生产模式,1,测试模式,2,开发模式
|
"mode": 2, //模式 0生产模式,1,测试模式,2,开发模式
|
||||||
"codeConfig": Map{
|
//"codeConfig": Map{
|
||||||
"admin": "config/app.json",
|
// "admin": "config/app.json",
|
||||||
},
|
//},
|
||||||
"codeConfig1": Map{
|
"codeConfig": Slice{
|
||||||
"admin": Map{ //默认无,必须,接口类别名称
|
Map{
|
||||||
"package": "admin", //默认admin,非必须,有则生成代码到此目录,无则采用缺省模式不生成代码只生成接口
|
"table": "admin", //默认admin,必须,有则根据数据库内当前表名做为用户生成数据
|
||||||
"config": "config/app.json", //默认config/app.json,必须,接口描述配置文件
|
"name": "", //默认admin,非必须,有则生成代码到此目录,无则采用缺省模式使用表名
|
||||||
"rule": "config/rule.json", //默认config/rule.json,非必须,有则按改规则生成接口,无则按系统内嵌方式生成
|
"config": "config/app.json", //默认config/app.json,必须,接口描述配置文件
|
||||||
|
"rule": "config/rule.json", //默认config/rule.json,非必须,有则按改规则生成接口,无则按系统内嵌方式生成
|
||||||
|
"mode": 0, //默认0,非必须,0为内嵌代码模式,1为生成代码模式
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"db": Map{
|
"db": Map{
|
||||||
@@ -51,13 +53,24 @@ var ConfigNote = Map{
|
|||||||
"logFile": "无默认,非必须,如果需要存储日志文件时使用,保存格式为:a/b/c/20060102150405.txt,将生成:a/b/c/年月日时分秒.txt,按需设置",
|
"logFile": "无默认,非必须,如果需要存储日志文件时使用,保存格式为:a/b/c/20060102150405.txt,将生成:a/b/c/年月日时分秒.txt,按需设置",
|
||||||
"webConnectLogShow": "默认true,非必须,访问日志如果需要web访问链接、访问ip、访问时间打印,false为关闭true开启此功能",
|
"webConnectLogShow": "默认true,非必须,访问日志如果需要web访问链接、访问ip、访问时间打印,false为关闭true开启此功能",
|
||||||
"webConnectLogFile": "无默认,非必须,webConnectLogShow开启之后才能使用,如果需要存储日志文件时使用,保存格式为:a/b/c/20060102150405.txt,将生成:a/b/c/年月日时分秒.txt,按需设置",
|
"webConnectLogFile": "无默认,非必须,webConnectLogShow开启之后才能使用,如果需要存储日志文件时使用,保存格式为:a/b/c/20060102150405.txt,将生成:a/b/c/年月日时分秒.txt,按需设置",
|
||||||
"mode": "默认0,非必须,0生产模式,1,测试模式,2,开发模式,在开发模式下会显示更多的数据用于开发测试,并能够辅助研发,自动生成配置文件、代码等功能,web无缓存,数据库不启用缓存", //debug 0关闭1开启
|
"mode": "默认0,非必须,0生产模式,1,测试模式,2开发模式,3内嵌代码模式,在开发模式下会显示更多的数据用于开发测试,并能够辅助研发,自动生成配置文件、代码等功能,web无缓存,数据库不启用缓存", //debug 0关闭1开启
|
||||||
"codeConfig": Map{
|
//"codeConfig": Map{
|
||||||
"注释": "配置即启用,非必须,默认无",
|
// "注释": "配置即启用,非必须,默认无",
|
||||||
//"package":"默认admin,必须,mode模式为2时会自动生成包文件夹和代码文件",
|
// //"package":"默认admin,必须,mode模式为2时会自动生成包文件夹和代码文件",
|
||||||
//"path":""
|
// //"path":""
|
||||||
|
//
|
||||||
"packageName": "默认无,必须,包名称以及应用名,生成代码的配置文件地址,比如config/app.json,数据库有更新时自动更新配置文件以及对应的生成文件",
|
// "packageName": "默认无,必须,包名称以及应用名,生成代码的配置文件地址,比如config/app.json,数据库有更新时自动更新配置文件以及对应的生成文件",
|
||||||
|
//},
|
||||||
|
"codeConfig": Slice{
|
||||||
|
"注释:配置即启用,非必须,默认无",
|
||||||
|
Map{ //默认无,必须,接口类别名称
|
||||||
|
//"注释": "", //
|
||||||
|
"table": "默认admin,必须,根据数据库内当前表名做为用户生成数据",
|
||||||
|
"name": "默认无,非必须,有则生成代码到此目录,无则采用缺省模式使用表名,如设置为:admin,将在admin目录生成包名为admin的代码",
|
||||||
|
"config": "默认config/app.json,必须,接口描述配置文件", //
|
||||||
|
"rule": "默认config/rule.json,非必须,有则按改规则生成接口,无则按系统内嵌方式生成",
|
||||||
|
"mode": "默认0,非必须,0为内嵌代码模式,1为生成代码模式",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"db": Map{
|
"db": Map{
|
||||||
"注释": "配置即启用,非必须,默认使用sqlite数据库",
|
"注释": "配置即启用,非必须,默认使用sqlite数据库",
|
||||||
|
|||||||
Reference in New Issue
Block a user