update
continuous-integration/drone/push Build is passing Details

master
kgdxpr 4 years ago
parent 2fb8077151
commit a6e9c2db86

@ -24,6 +24,8 @@ func Routers(r *gin.RouterGroup) {
rr.POST("/fileUpload", fileUpload)
}
//聊天中的文件上传
func fileUpload(c *gin.Context) {
file, err := c.FormFile("file")

@ -0,0 +1,36 @@
package ImRelateDao
import (
"dsSzxy/Utils/CommonUtil"
"dsSzxy/Utils/ConfigUtil"
ssdb "dsSzxy/Utils/SsdbUtil"
"fmt"
)
/**
2021-08-12
*/
func GetPersonAvatar(personId string, identityId string, w string, h string) string {
prefix := "/dsideal_yy/html/thumb/Material/%s/%s%s"
zoom := "@" + w + "w_" + h + "h_100Q_1x.png"
avatarId := "EA0BC5FB-52D9-E232-D3E3-E6C2960B5739.png"
avatarUrl := fmt.Sprintf(prefix, avatarId[0:2], avatarId, zoom)
ssdbClient, ssdbClientErr := ssdb.Connect(ConfigUtil.SSDBIp, ConfigUtil.SSDBPort)
if ssdbClientErr != nil {
return avatarUrl
}
res, resErr := ssdbClient.Get("space_ajson_personbaseinfo_" + personId + "_" + identityId)
if resErr != nil {
return avatarUrl
}
jsonObj, jsonObjErr := CommonUtil.JsonStringToMap(fmt.Sprintf("%v", res))
if jsonObjErr != nil {
return avatarUrl
}
avatarId = jsonObj["space_avatar_fileid"]
avatarUrl = fmt.Sprintf(prefix, avatarId[0:2], avatarId, zoom)
return avatarUrl
}

@ -23,10 +23,14 @@ user = root
pwd = DsideaL147258369
[redis]
ip = 10.10.14.175
ip = 10.10.14.169
port = 18890
db = 0
[ssdb]
ip = 10.10.14.169
port = 8888
#minio配置
[minio]
minio_endpoint = 10.10.14.231:9000
@ -47,6 +51,7 @@ prefix = https://ow365.cn/?i=14531&furl=http://video.edusoa.com/crh/
[savePath]
path = /usr/local/dsMin/dsSzxy/files/
#融云配置文件位置
[rongyun]
config_path = /usr/local/tomcat7/webapps/dsideal_yy/WEB-INF/classes/config.properties

@ -2,13 +2,18 @@ package CommonUtil
import (
"crypto/md5"
"crypto/sha1"
"dsSzxy/Utils/ConfigUtil"
"encoding/hex"
"encoding/json"
"fmt"
uuid "github.com/satori/go.uuid"
"github.com/spf13/viper"
"math/rand"
"os"
"strconv"
"strings"
"time"
)
/**
@ -86,3 +91,48 @@ func Ext(path string) string {
}
return ""
}
/**
6
*/
func GetSixRandom() string {
return fmt.Sprintf("%v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
}
/**
*/
func GetTimeStamp() string {
return fmt.Sprintf("%v", time.Now().UnixNano()/1e6)
}
/**
SHA1
*/
func SHA1(s string) string {
o := sha1.New()
o.Write([]byte(s))
return hex.EncodeToString(o.Sum(nil))
}
/**
*/
func GetRongYunConfig() (map[string]string, error) {
m := make(map[string]string)
viper.SetConfigFile(ConfigUtil.RongYunConfigPath)
if err := viper.ReadInConfig(); err != nil {
return nil, err
}
m["suffix"] = viper.GetString("rong_server_name")
m["app_key"] = viper.GetString("rong_key")
m["app_secret"] = viper.GetString("rong_secret")
return m, nil
}

@ -51,7 +51,12 @@ var (
SavePath string
//融云配置文件位置
RongYunConfigPath string
//SSDB
SSDBIp string
SSDBPort int
)
//cookie中的SessionId名称
@ -106,7 +111,7 @@ func init() {
MysqlUser = iniParser.GetString("mysql", "user")
MysqlPwd = iniParser.GetString("mysql", "pwd")
//读取redis配置
//Redis
RedisIp = iniParser.GetString("redis", "ip")
RedisPort = iniParser.GetString("redis", "port")
RedisDb = iniParser.GetString("redis", "db")
@ -132,6 +137,10 @@ func init() {
//融云配置文件位置
RongYunConfigPath = iniParser.GetString("rongyun", "config_path")
//SSDB
SSDBIp = iniParser.GetString("ssdb", "ip")
SSDBPort = iniParser.GetInt("ssdb", "port")
}
type IniParser struct {
@ -181,3 +190,18 @@ func (this *IniParser) GetInt32(section string, key string) int32 {
return int32(valueInt)
}
func (this *IniParser) GetInt(section string, key string) int {
if this.confReader == nil {
return 0
}
s := this.confReader.Section(section)
if s == nil {
return 0
}
valueInt, _ := s.Key(key).Int()
return int(valueInt)
}

@ -28,7 +28,6 @@ func SET(key string, value string, expiration time.Duration) {
func GET(key string) (string, error) {
val, err := RedisClient.Get(key).Result()
return val, err
}
func EXPIRE(key string, expiration time.Duration) {
@ -47,3 +46,8 @@ func HMGETALL(key string) map[string]string {
resMap, _ := RedisClient.HGetAll(key).Result()
return resMap
}
func HMGET(key string, fields []string) []interface{} {
resMap, _ := RedisClient.HMGet(key, fields...).Result()
return resMap
}

@ -0,0 +1,190 @@
package ssdb
import (
"bytes"
"fmt"
"net"
"strconv"
)
type Client struct {
sock *net.TCPConn
recv_buf bytes.Buffer
}
func Connect(ip string, port int) (*Client, error) {
addr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", ip, port))
if err != nil {
return nil, err
}
sock, err := net.DialTCP("tcp", nil, addr)
if err != nil {
return nil, err
}
var c Client
c.sock = sock
return &c, nil
}
func (c *Client) Do(args ...interface{}) ([]string, error) {
err := c.send(args)
if err != nil {
return nil, err
}
resp, err := c.recv()
return resp, err
}
func (c *Client) Set(key string, val string) (interface{}, error) {
resp, err := c.Do("set", key, val)
if err != nil {
return nil, err
}
if len(resp) == 2 && resp[0] == "ok" {
return true, nil
}
return nil, fmt.Errorf("bad response")
}
// TODO: Will somebody write addition semantic methods?
func (c *Client) Get(key string) (interface{}, error) {
resp, err := c.Do("get", key)
if err != nil {
return nil, err
}
if len(resp) == 2 && resp[0] == "ok" {
return resp[1], nil
}
if resp[0] == "not_found" {
return nil, nil
}
return nil, fmt.Errorf("bad response")
}
func (c *Client) Del(key string) (interface{}, error) {
resp, err := c.Do("del", key)
if err != nil {
return nil, err
}
//response looks like this: [ok 1]
if len(resp) > 0 && resp[0] == "ok" {
return true, nil
}
return nil, fmt.Errorf("bad response:resp:%v:", resp)
}
func (c *Client) Send(args ...interface{}) error {
return c.send(args)
}
func (c *Client) send(args []interface{}) error {
var buf bytes.Buffer
for _, arg := range args {
var s string
switch arg := arg.(type) {
case string:
s = arg
case []byte:
s = string(arg)
case []string:
for _, s := range arg {
buf.WriteString(fmt.Sprintf("%d", len(s)))
buf.WriteByte('\n')
buf.WriteString(s)
buf.WriteByte('\n')
}
continue
case int:
s = fmt.Sprintf("%d", arg)
case int64:
s = fmt.Sprintf("%d", arg)
case float64:
s = fmt.Sprintf("%f", arg)
case bool:
if arg {
s = "1"
} else {
s = "0"
}
case nil:
s = ""
default:
return fmt.Errorf("bad arguments")
}
buf.WriteString(fmt.Sprintf("%d", len(s)))
buf.WriteByte('\n')
buf.WriteString(s)
buf.WriteByte('\n')
}
buf.WriteByte('\n')
_, err := c.sock.Write(buf.Bytes())
return err
}
func (c *Client) Recv() ([]string, error) {
return c.recv()
}
func (c *Client) recv() ([]string, error) {
var tmp [8192]byte
for {
resp := c.parse()
if resp == nil || len(resp) > 0 {
return resp, nil
}
n, err := c.sock.Read(tmp[0:])
if err != nil {
return nil, err
}
c.recv_buf.Write(tmp[0:n])
}
}
func (c *Client) parse() []string {
resp := []string{}
buf := c.recv_buf.Bytes()
var idx, offset int
idx = 0
offset = 0
for {
idx = bytes.IndexByte(buf[offset:], '\n')
if idx == -1 {
break
}
p := buf[offset : offset+idx]
offset += idx + 1
//fmt.Printf("> [%s]\n", p);
if len(p) == 0 || (len(p) == 1 && p[0] == '\r') {
if len(resp) == 0 {
continue
} else {
var new_buf bytes.Buffer
new_buf.Write(buf[offset:])
c.recv_buf = new_buf
return resp
}
}
size, err := strconv.Atoi(string(p))
if err != nil || size < 0 {
return nil
}
if offset+size >= c.recv_buf.Len() {
break
}
v := buf[offset : offset+size]
resp = append(resp, string(v))
offset += size + 1
}
//fmt.Printf("buf.size: %d packet not ready...\n", len(buf))
return []string{}
}
// Close The Client Connection
func (c *Client) Close() error {
return c.sock.Close()
}
Loading…
Cancel
Save