|
- package svc
-
- import (
- "applet/app/db"
- "applet/app/svc/sys_cfg"
- "applet/app/utils"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
- 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"
- "github.com/gin-gonic/gin"
- "strings"
- "time"
- )
-
- func GetOssUrl(img string) string {
- sysCfgDb := sys_cfg.NewSysCfgDb(db.Db)
- 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 {
- sysCfgDb := sys_cfg.NewSysCfgDb(db.Db)
- sysCfg := sysCfgDb.SysCfgFindWithDb("oss_domain", "oss_bucket_scheme")
- http := sysCfg["oss_bucket_scheme"]
- return http + "://" + sysCfg["oss_domain"] + "/"
- }
- func GetSysCfgStr(key string) string {
- return sys_cfg.NewSysCfgDb(db.Db).SysCfgGetWithDb(key)
- }
- func SetSysCfgStr(key, val string) bool {
- cfgDb := sys_cfg.NewSysCfgDb(db.Db)
- 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
- }
-
- // 操作日志
- func AddAdminLog(c *gin.Context, adminId int, types, memo, ext string) {
- var tmp = model.AdminLog{
- Type: types,
- AdminId: adminId,
- Memo: memo,
- Time: time.Now(),
- Ip: utils.GetIP(c.Request),
- Data: ext,
- }
- db.Db.Insert(&tmp)
- }
|