1.4.5.2
This commit is contained in:
47
EdgeNode/internal/js/common_scripts.go
Normal file
47
EdgeNode/internal/js/common_scripts.go
Normal file
@@ -0,0 +1,47 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
//go:build script
|
||||
// +build script
|
||||
|
||||
package js
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
)
|
||||
|
||||
var sharedCommonScripts []*serverconfigs.CommonScript
|
||||
|
||||
func SetCommonScripts(commonScripts []*serverconfigs.CommonScript) {
|
||||
sharedCommonScripts = commonScripts
|
||||
}
|
||||
|
||||
func GetCommonScripts() []*serverconfigs.CommonScript {
|
||||
return sharedCommonScripts
|
||||
}
|
||||
|
||||
func IsSameCommonScripts(commonScripts []*serverconfigs.CommonScript) bool {
|
||||
var oldScripts = sharedCommonScripts // 为了操作安全需要拷贝
|
||||
var newScripts = commonScripts
|
||||
if len(oldScripts) != len(newScripts) {
|
||||
return false
|
||||
}
|
||||
var oldMap = map[string]*serverconfigs.CommonScript{} // filename => CommonScript
|
||||
for _, script := range oldScripts {
|
||||
oldMap[script.Filename] = script
|
||||
}
|
||||
|
||||
var newMap = map[string]*serverconfigs.CommonScript{} // filename => CommonScript
|
||||
for _, script := range newScripts {
|
||||
newMap[script.Filename] = script
|
||||
}
|
||||
|
||||
for filename, oldScript := range oldMap {
|
||||
newScript, ok := newMap[filename]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
if oldScript.Code != newScript.Code {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user