config.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package conf
  2. import (
  3. "AIOTCOER/logs"
  4. "fmt"
  5. beego "github.com/beego/beego/v2/server/web"
  6. "math/rand"
  7. "os"
  8. "strings"
  9. "time"
  10. )
  11. func init() {
  12. dir, err := os.Getwd()
  13. if err != nil {
  14. dir = "/tmp"
  15. }
  16. Analysis_Dir = dir + "/Plugin/Prot/"
  17. logs.Println("Analysis_Dir:", Analysis_Dir)
  18. Config_AdminTokey, err = beego.AppConfig.String("Config_AdminTokey")
  19. //fmt.Println("AdminTokey:",Config_AdminTokey,err)
  20. if err != nil || len(Config_AdminTokey) == 0{
  21. Config_AdminTokey = GetRandstring(32, "", 1)
  22. fmt.Println("AdminTokey:",Config_AdminTokey)
  23. }
  24. }
  25. var HTTPPort, _ = beego.AppConfig.Int("httpport")
  26. var AppName, _ = beego.AppConfig.String("appname")
  27. // Redis
  28. var Redis_address, _ = beego.AppConfig.String("Redis_address")
  29. var Redis_password, _ = beego.AppConfig.String("Redis_password")
  30. var Redis_dbNum, _ = beego.AppConfig.String("Redis_dbNum")
  31. // Mysql
  32. var MysqlServer_UrlPort, _ = beego.AppConfig.String("MysqlServer_UrlPort")
  33. var MysqlServer_Database, _ = beego.AppConfig.String("MysqlServer_Database")
  34. var MysqlServer_Username, _ = beego.AppConfig.String("MysqlServer_Username")
  35. var MysqlServer_Password, _ = beego.AppConfig.String("MysqlServer_Password")
  36. var MysqlServer_MaxIdleConnections, _ = beego.AppConfig.Int("MysqlServer_MaxIdleConnections")
  37. var MysqlServer_MaxOpenConnections, _ = beego.AppConfig.Int("MysqlServer_MaxOpenConnections")
  38. // Mongodb
  39. var Mongodb_Url, _ = beego.AppConfig.String("Mongodb_Url")
  40. var Mongodb_DB, _ = beego.AppConfig.String("Mongodb_DB")
  41. var Mongodb_Username, _ = beego.AppConfig.String("Mongodb_Username")
  42. var Mongodb_Password, _ = beego.AppConfig.String("Mongodb_Password")
  43. // 数据解析加载目录
  44. var Analysis_Dir string
  45. // 管理
  46. var Config_AddProductType, _ = beego.AppConfig.Bool("Config_AddProductType") // 是否可以添加产品
  47. var Config_AdminTokey string // 管理员秘钥
  48. // Qiniu
  49. var Qiniu_AccessKey, _ = beego.AppConfig.String("Qiniu_AccessKey")
  50. var Qiniu_SecretKey, _ = beego.AppConfig.String("Qiniu_SecretKey")
  51. var Qiniu_BUCKET, _ = beego.AppConfig.String("Qiniu_BUCKET")
  52. var Qiniu_Url, _ = beego.AppConfig.String("Qiniu_Url")
  53. // #取得随机字符串:通过打乱slice来操作
  54. func GetRandstring(length int, char string, rand_x int64) string {
  55. if length < 1 {
  56. return ""
  57. }
  58. if len(char) <= 6 || len(char) <= length {
  59. char = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
  60. }
  61. charArr := strings.Split(char, "")
  62. ran := rand.New(rand.NewSource(time.Now().Unix() + rand_x))
  63. l := len(charArr)
  64. for i := l - 1; i > 0; i-- {
  65. r := ran.Intn(i)
  66. charArr[r], charArr[i] = charArr[i], charArr[r]
  67. }
  68. rchar := charArr[:length]
  69. return strings.Join(rchar, "")
  70. }