公司pc的代码merge

master
18650180552 2019-03-07 10:36:09 +08:00
parent 974c3d6fc8
commit bc2de61c4d
14 changed files with 319 additions and 314 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
glide.yaml glide.yaml
api_user.exe api_user.exe
user.exe

View File

@ -1,8 +1,8 @@
package config package config
import ( import (
"log"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
"log"
"os" "os"
"runtime" "runtime"
) )
@ -47,7 +47,9 @@ type MysqlConfig struct {
MaxOpen int `yaml:"max_open"` MaxOpen int `yaml:"max_open"`
MaxIdle int `yaml:"max_idle"` MaxIdle int `yaml:"max_idle"`
} }
var gConf ConfAPI var gConf ConfAPI
func Init(path string) error { func Init(path string) error {
file, e := os.Open(path) file, e := os.Open(path)
if nil != e { if nil != e {

View File

@ -69,6 +69,7 @@ func Auth(c *gin.Context) {
return return
} }
} }
// SetUser godoc // SetUser godoc
// @Summary SetUser // @Summary SetUser
// @Description set userinfo // @Description set userinfo
@ -108,6 +109,7 @@ func GetUser(c *gin.Context) {
resp.Msg = "操作成功" resp.Msg = "操作成功"
resp.Data = users resp.Data = users
} }
// GetUsers godoc // GetUsers godoc
// @Summary GetUsers // @Summary GetUsers
// @Description Get all user with query // @Description Get all user with query
@ -193,7 +195,7 @@ func SerarchUsers(c *gin.Context) {
resp.Data = dat resp.Data = dat
} }
func CreateVerify(length int32) string { func CreateVerify(length int32) string {
strAry := []byte{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; strAry := []byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}
result := string("") result := string("")
for i := int32(0); i < length; i++ { for i := int32(0); i < length; i++ {
x := rand.Intn(len(strAry)) x := rand.Intn(len(strAry))
@ -201,13 +203,14 @@ func CreateVerify(length int32) string{
} }
return result return result
} }
/** /**
* Token * Token
* @param {Number} length Token * @param {Number} length Token
* @return {string} Token * @return {string} Token
*/ */
func createToken(length int32) string { func createToken(length int32) string {
strAry := []byte{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '_' }; strAry := []byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '_'}
result := string("") result := string("")
for i := int32(0); i < length; i++ { for i := int32(0); i < length; i++ {
x := rand.Intn(len(strAry)) x := rand.Intn(len(strAry))
@ -233,6 +236,7 @@ func DefaultOption(c *gin.Context) {
c.JSON(204, resp) c.JSON(204, resp)
}() }()
} }
// Login godoc // Login godoc
// @Summary Login // @Summary Login
// @Description login // @Description login
@ -280,7 +284,7 @@ func Login(c *gin.Context) {
socketToken.Write([]byte(createToken(6))) // 需要加密的字符串为 123456 socketToken.Write([]byte(createToken(6))) // 需要加密的字符串为 123456
socketTokenMd5 := socketToken.Sum(nil) socketTokenMd5 := socketToken.Sum(nil)
m := structs.Map(result[0]) m := structs.Map(result[0])
m["socketToken"] = ByteSliceToString(socketTokenMd5); m["socketToken"] = ByteSliceToString(socketTokenMd5)
sessionInfo, err := json.Marshal(m) sessionInfo, err := json.Marshal(m)
if err != nil { if err != nil {
log.Println(err.Error()) log.Println(err.Error())
@ -414,7 +418,6 @@ func Logout(c *gin.Context) {
session.Save() session.Save()
} }
func Reader2Json(r io.ReadCloser) string { func Reader2Json(r io.ReadCloser) string {
var ret string var ret string
for i := 0; ; i++ { for i := 0; ; i++ {

View File

@ -14,8 +14,8 @@ import (
"strings" "strings"
"text/template" "text/template"
"time" "time"
"user/controller"
"user/config" "user/config"
"user/controller"
"user/db" "user/db"
) )
@ -66,6 +66,7 @@ type ReqSendEmail struct {
Email string `json:"email_address"` Email string `json:"email_address"`
Content string `json:"content"` Content string `json:"content"`
} }
func SendToMail(title, user, password, host, to, content string) error { func SendToMail(title, user, password, host, to, content string) error {
var content_type string var content_type string
hp := strings.Split(host, ":") hp := strings.Split(host, ":")
@ -90,7 +91,6 @@ func SendToMail(title, user, password, host, to, content string) error {
return err return err
} }
func SendToMailTpl(title, user, password, host, to, tplname string, content interface{}, mailtype string, ifgenerate bool) error { func SendToMailTpl(title, user, password, host, to, tplname string, content interface{}, mailtype string, ifgenerate bool) error {
var content_type string var content_type string
var paseresult bytes.Buffer var paseresult bytes.Buffer

View File

@ -324,7 +324,7 @@ func GenSql(obj interface{}) (string,error) {
if i == 0 { if i == 0 {
ret += "(" ret += "("
} }
switch (value.Field(i).Type().Kind()){ switch value.Field(i).Type().Kind() {
case reflect.String: case reflect.String:
str := value.Field(i).Interface().(string) str := value.Field(i).Interface().(string)
if str[0] != '"' { if str[0] != '"' {
@ -347,9 +347,9 @@ func GenSql(obj interface{}) (string,error) {
ret += fmt.Sprintf("%d", value.Field(i).Interface().(int16)) ret += fmt.Sprintf("%d", value.Field(i).Interface().(int16))
case reflect.Bool: case reflect.Bool:
if value.Field(i).Interface().(bool) { if value.Field(i).Interface().(bool) {
ret += fmt.Sprintf("true",) ret += fmt.Sprintf("true")
} else { } else {
ret += fmt.Sprintf("false",) ret += fmt.Sprintf("false")
} }
case reflect.Float32: case reflect.Float32:
ret += fmt.Sprintf("%x", value.Field(i).Interface().(float32)) ret += fmt.Sprintf("%x", value.Field(i).Interface().(float32))
@ -417,6 +417,7 @@ func (this *Database) InsertObejct(tb_name string,obj interface{}) (int64,error)
} }
return 0, nil return 0, nil
} }
// 执行INSERT语句并返回最后生成的自增ID // 执行INSERT语句并返回最后生成的自增ID
// 返回0表示没有出错, 但没生成自增ID // 返回0表示没有出错, 但没生成自增ID
// 返回-1表示出错 // 返回-1表示出错

View File

@ -27,5 +27,3 @@ func Init() {
func GetMysqlClient() *Database { func GetMysqlClient() *Database {
return &gDb return &gDb
} }

View File

@ -3,12 +3,12 @@ package db
import ( import (
"database/sql" "database/sql"
"errors" "errors"
"fmt"
"log"
"math/big"
"reflect"
"strconv" "strconv"
"strings" "strings"
"log"
"fmt"
"reflect"
"math/big"
"git.jiaxianghudong.com/go/utils" "git.jiaxianghudong.com/go/utils"
) )
@ -473,8 +473,8 @@ func (q *SB) Exec(args ...interface{}) *SBResult {
case TYPE_INSERT: case TYPE_INSERT:
if DBType == "mysql" { if DBType == "mysql" {
last, err := ret.LastInsertId() last, err := ret.LastInsertId()
if (err == nil) { if err == nil {
sbRet.LastID = last; sbRet.LastID = last
} }
} }
case TYPE_DELETE: case TYPE_DELETE:
@ -483,7 +483,7 @@ func (q *SB) Exec(args ...interface{}) *SBResult {
fallthrough fallthrough
case TYPE_INSERTUPDATE: case TYPE_INSERTUPDATE:
aff, err := ret.RowsAffected() aff, err := ret.RowsAffected()
if (err == nil) { if err == nil {
sbRet.Affected = aff sbRet.Affected = aff
} }
} }

View File

@ -1,9 +1,9 @@
package db package db
import ( import (
"strings"
"strconv"
"database/sql" "database/sql"
"strconv"
"strings"
) )
// 根据传入的字段列表生成相符数量的占位符 // 根据传入的字段列表生成相符数量的占位符

View File

@ -5,8 +5,8 @@ import (
"github.com/tommy351/gin-sessions" "github.com/tommy351/gin-sessions"
"log" "log"
"strconv" "strconv"
"user/controller"
"user/config" "user/config"
"user/controller"
"user/controller/mail" "user/controller/mail"
"user/db" "user/db"
"user/logs" "user/logs"
@ -24,7 +24,6 @@ func CORSMiddleware(c *gin.Context) {
ori := c.Request.Header.Get("Origin") ori := c.Request.Header.Get("Origin")
c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE") c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE")
c.Writer.Header().Set("Access-Control-Allow-Origin", ori) c.Writer.Header().Set("Access-Control-Allow-Origin", ori)
log.Println(c.Request.Header.Get("Origin"))
c.Writer.Header().Set("Access-Control-Max-Age", "86400") c.Writer.Header().Set("Access-Control-Max-Age", "86400")
c.Writer.Header().Set("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, Origin, Authorization, Accept, Client-Security-Token, Accept-Encoding, x-access-token") c.Writer.Header().Set("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, Origin, Authorization, Accept, Client-Security-Token, Accept-Encoding, x-access-token")
c.Writer.Header().Set("Access-Control-Expose-Headers", "Content-Length") c.Writer.Header().Set("Access-Control-Expose-Headers", "Content-Length")
@ -72,5 +71,8 @@ func main() {
r.GET("/api/logout", controller.Logout) r.GET("/api/logout", controller.Logout)
r.POST("/api/verify", mail.OnSendEmailCode) r.POST("/api/verify", mail.OnSendEmailCode)
} }
r.Run(":" + strconv.Itoa(config.GetPort())) e = r.Run(":" + strconv.Itoa(config.GetPort()))
if nil != e{
log.Print(e.Error())
}
} }

View File

@ -2,7 +2,7 @@ package model
import ( import (
"fmt" "fmt"
"qiniupkg.com/x/log.v7" "log"
"user/db" "user/db"
"user/logs" "user/logs"
) )
@ -44,5 +44,3 @@ func GetUsers(limit int32,offsetPage int32,name string) ([]Users,int32){
} }
return users, cnts[0].Count return users, cnts[0].Count
} }