蛋蛋星球 后台端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 

82 行
2.7 KiB

  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/utils/cache"
  5. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  6. openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
  7. ram20150501 "github.com/alibabacloud-go/ram-20150501/v2/client"
  8. sts20150401 "github.com/alibabacloud-go/sts-20150401/v2/client"
  9. util2 "github.com/alibabacloud-go/tea-utils/v2/service"
  10. "github.com/alibabacloud-go/tea/tea"
  11. "strings"
  12. )
  13. func GetOssUrl(img string) string {
  14. redisConn := cache.GetPool().Get()
  15. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  16. sysCfg := sysCfgDb.SysCfgFindWithDb("oss_domain", "oss_bucket_scheme")
  17. if strings.Contains(img, "http") == false && img != "" {
  18. http := sysCfg["oss_bucket_scheme"]
  19. img = http + "://" + sysCfg["oss_domain"] + "/" + img
  20. }
  21. return img
  22. }
  23. func GetOssDomain() string {
  24. redisConn := cache.GetPool().Get()
  25. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  26. sysCfg := sysCfgDb.SysCfgFindWithDb("oss_domain", "oss_bucket_scheme")
  27. http := sysCfg["oss_bucket_scheme"]
  28. return http + "://" + sysCfg["oss_domain"] + "/"
  29. }
  30. func GetSysCfgStr(key string) string {
  31. redisConn := cache.GetPool().Get()
  32. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  33. return sysCfgDb.SysCfgGetWithDb(key)
  34. }
  35. func SetSysCfgStr(key, val string) bool {
  36. redisConn := cache.GetPool().Get()
  37. cfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  38. var bools bool
  39. if val != "" {
  40. data, _ := cfgDb.SysCfgGetOne(key)
  41. if data == nil {
  42. bools = cfgDb.SysCfgInsert(key, val, "")
  43. } else {
  44. bools = cfgDb.SysCfgUpdate(key, val)
  45. }
  46. }
  47. return bools
  48. }
  49. func CreateSTSClient(accessKeyId *string, accessKeySecret *string, stsEndpoint *string) (*sts20150401.Client, error) {
  50. config := &openapi.Config{
  51. AccessKeyId: accessKeyId,
  52. AccessKeySecret: accessKeySecret,
  53. // Endpoint 请参考 https://api.aliyun.com/product/Sts
  54. Endpoint: stsEndpoint,
  55. }
  56. return sts20150401.NewClient(config)
  57. }
  58. func AssumeRole(client *sts20150401.Client, roleArn *string, roleSessionName *string, durationSeconds int64) (*sts20150401.AssumeRoleResponse, error) {
  59. assumeRoleRequest := &sts20150401.AssumeRoleRequest{
  60. DurationSeconds: &durationSeconds,
  61. RoleArn: roleArn,
  62. RoleSessionName: roleSessionName,
  63. }
  64. return client.AssumeRoleWithOptions(assumeRoleRequest, &util2.RuntimeOptions{})
  65. }
  66. func CreateGetRoleClient(accessKeyId, accessKeySecret *string) (_result *ram20150501.Client, _err error) {
  67. config := &openapi.Config{
  68. AccessKeyId: accessKeyId,
  69. AccessKeySecret: accessKeySecret,
  70. }
  71. // Endpoint 请参考 https://api.aliyun.com/product/Ram
  72. config.Endpoint = tea.String("ram.aliyuncs.com")
  73. _result = &ram20150501.Client{}
  74. _result, _err = ram20150501.NewClient(config)
  75. return _result, _err
  76. }