|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- package svc
-
- import (
- "applet/app/db"
- "applet/app/utils/cache"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
- openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
- ram20150501 "github.com/alibabacloud-go/ram-20150501/v2/client"
- sts20150401 "github.com/alibabacloud-go/sts-20150401/v2/client"
- util2 "github.com/alibabacloud-go/tea-utils/v2/service"
- "github.com/alibabacloud-go/tea/tea"
- "strings"
- )
-
- func GetOssUrl(img string) string {
- redisConn := cache.GetPool().Get()
- sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
- sysCfg := sysCfgDb.SysCfgFindWithDb("oss_domain", "oss_bucket_scheme")
- if strings.Contains(img, "http") == false && img != "" {
- http := sysCfg["oss_bucket_scheme"]
- img = http + "://" + sysCfg["oss_domain"] + "/" + img
- }
- return img
- }
- func GetOssDomain() string {
- redisConn := cache.GetPool().Get()
- sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
- sysCfg := sysCfgDb.SysCfgFindWithDb("oss_domain", "oss_bucket_scheme")
- http := sysCfg["oss_bucket_scheme"]
- return http + "://" + sysCfg["oss_domain"] + "/"
- }
- func GetSysCfgStr(key string) string {
- redisConn := cache.GetPool().Get()
- sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
- return sysCfgDb.SysCfgGetWithDb(key)
- }
- func SetSysCfgStr(key, val string) bool {
- redisConn := cache.GetPool().Get()
- cfgDb := implement.NewSysCfgDb(db.Db, redisConn)
- var bools bool
- if val != "" {
- data, _ := cfgDb.SysCfgGetOne(key)
- if data == nil {
- bools = cfgDb.SysCfgInsert(key, val, "")
- } else {
- bools = cfgDb.SysCfgUpdate(key, val)
- }
- }
- return bools
- }
-
- func CreateSTSClient(accessKeyId *string, accessKeySecret *string, stsEndpoint *string) (*sts20150401.Client, error) {
- config := &openapi.Config{
- AccessKeyId: accessKeyId,
- AccessKeySecret: accessKeySecret,
- // Endpoint 请参考 https://api.aliyun.com/product/Sts
- Endpoint: stsEndpoint,
- }
- return sts20150401.NewClient(config)
- }
-
- func AssumeRole(client *sts20150401.Client, roleArn *string, roleSessionName *string, durationSeconds int64) (*sts20150401.AssumeRoleResponse, error) {
- assumeRoleRequest := &sts20150401.AssumeRoleRequest{
- DurationSeconds: &durationSeconds,
- RoleArn: roleArn,
- RoleSessionName: roleSessionName,
- }
- return client.AssumeRoleWithOptions(assumeRoleRequest, &util2.RuntimeOptions{})
- }
-
- func CreateGetRoleClient(accessKeyId, accessKeySecret *string) (_result *ram20150501.Client, _err error) {
- config := &openapi.Config{
- AccessKeyId: accessKeyId,
- AccessKeySecret: accessKeySecret,
- }
- // Endpoint 请参考 https://api.aliyun.com/product/Ram
- config.Endpoint = tea.String("ram.aliyuncs.com")
- _result = &ram20150501.Client{}
- _result, _err = ram20150501.NewClient(config)
- return _result, _err
- }
|