mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-11-12 11:20:26 +08:00
优化OSS源站相关代码
This commit is contained in:
6
pkg/serverconfigs/ossconfigs/oss_bucket_param.go
Normal file
6
pkg/serverconfigs/ossconfigs/oss_bucket_param.go
Normal 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
|
||||||
@@ -1,15 +1,9 @@
|
|||||||
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||||
|
//go:build !plus
|
||||||
|
|
||||||
package ossconfigs
|
package ossconfigs
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"reflect"
|
|
||||||
)
|
|
||||||
|
|
||||||
type OSSConfig struct {
|
type OSSConfig struct {
|
||||||
Type OSSType `yaml:"oss" json:"type"`
|
|
||||||
Options any `yaml:"options" json:"options"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewOSSConfig() *OSSConfig {
|
func NewOSSConfig() *OSSConfig {
|
||||||
@@ -17,69 +11,9 @@ func NewOSSConfig() *OSSConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *OSSConfig) Init() error {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *OSSConfig) Summary() string {
|
func (this *OSSConfig) Summary() string {
|
||||||
var name = ""
|
return ""
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,4 @@ package ossconfigs
|
|||||||
|
|
||||||
type OSSOptions interface {
|
type OSSOptions interface {
|
||||||
Init() error // 初始化
|
Init() error // 初始化
|
||||||
Summary() string // 内容简述
|
|
||||||
UniqueId() string // 唯一标识
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,26 @@
|
|||||||
|
|
||||||
package ossconfigs
|
package ossconfigs
|
||||||
|
|
||||||
import "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
|
||||||
|
|
||||||
type OSSType = string
|
type OSSType = string
|
||||||
|
|
||||||
func FindAllOSSTypes() []*shared.Definition {
|
type OSSTypeDefinition struct {
|
||||||
return []*shared.Definition{}
|
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) {
|
func DecodeOSSOptions(ossType OSSType, optionsJSON []byte) (any, error) {
|
||||||
|
|||||||
@@ -4,5 +4,10 @@ package systemconfigs
|
|||||||
|
|
||||||
// CheckUpdatesConfig 检查更新配置
|
// CheckUpdatesConfig 检查更新配置
|
||||||
type CheckUpdatesConfig struct {
|
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{}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user