优化OSS源站相关代码

This commit is contained in:
GoEdgeLab
2023-06-13 15:44:43 +08:00
parent ae8682dd2d
commit 1f23703ae9
5 changed files with 32 additions and 75 deletions

View File

@@ -0,0 +1,6 @@
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build !plus
package ossconfigs
type OSSBucketParam = string

View File

@@ -1,15 +1,9 @@
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build !plus
package ossconfigs
import (
"encoding/json"
"reflect"
)
type OSSConfig struct {
Type OSSType `yaml:"oss" json:"type"`
Options any `yaml:"options" json:"options"`
}
func NewOSSConfig() *OSSConfig {
@@ -17,69 +11,9 @@ func NewOSSConfig() *OSSConfig {
}
func (this *OSSConfig) Init() error {
if this.Options != nil {
// decode options
if reflect.TypeOf(this.Options).Kind() == reflect.Map {
optionsJSON, err := json.Marshal(this.Options)
if err != nil {
return err
}
newOptions, decodeErr := DecodeOSSOptions(this.Type, optionsJSON)
if decodeErr != nil {
return decodeErr
}
if newOptions != nil {
this.Options = newOptions
}
}
options, ok := this.Options.(OSSOptions)
if ok {
err := options.Init()
if err != nil {
return err
}
}
}
return nil
}
func (this *OSSConfig) Summary() string {
var name = ""
var found = false
for _, def := range FindAllOSSTypes() {
if def.Code == this.Type {
name = def.Name
found = true
break
}
}
if !found {
return ""
}
var summary = ""
if this.Options != nil {
// decode options
if reflect.TypeOf(this.Options).Kind() == reflect.Map {
optionsJSON, err := json.Marshal(this.Options)
if err == nil { // ignore error
newOptions, decodeErr := DecodeOSSOptions(this.Type, optionsJSON)
if decodeErr == nil && newOptions != nil {
this.Options = newOptions
}
}
}
options, ok := this.Options.(OSSOptions)
if ok {
summary = options.Summary()
}
}
if len(summary) == 0 {
return name
}
return name + " - " + summary
return ""
}

View File

@@ -4,6 +4,4 @@ package ossconfigs
type OSSOptions interface {
Init() error // 初始化
Summary() string // 内容简述
UniqueId() string // 唯一标识
}

View File

@@ -3,12 +3,26 @@
package ossconfigs
import "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
type OSSType = string
func FindAllOSSTypes() []*shared.Definition {
return []*shared.Definition{}
type OSSTypeDefinition struct {
Name string `json:"name"`
Code string `json:"code"`
BucketOptionName string `json:"bucketOptionName"`
BucketIgnored bool `json:"bucketIgnored"` // 是否忽略Bucket名称
}
func FindAllOSSTypes() []*OSSTypeDefinition {
return []*OSSTypeDefinition{}
}
func FindOSSType(code string) *OSSTypeDefinition {
for _, t := range FindAllOSSTypes() {
if t.Code == code {
return t
}
}
return nil
}
func DecodeOSSOptions(ossType OSSType, optionsJSON []byte) (any, error) {

View File

@@ -4,5 +4,10 @@ package systemconfigs
// CheckUpdatesConfig 检查更新配置
type CheckUpdatesConfig struct {
AutoCheck bool `yaml:"autoCheck" json:"autoCheck"`
AutoCheck bool `yaml:"autoCheck" json:"autoCheck"` // 是否开启自动检查
IgnoredVersion string `yaml:"ignoredVersion" json:"ignoredVersion"` // 上次忽略的版本
}
func NewCheckUpdatesConfig() *CheckUpdatesConfig {
return &CheckUpdatesConfig{}
}