mirror of
https://github.com/fatedier/frp.git
synced 2026-04-29 12:39:10 +08:00
refactor: use maps.Clone and slices.Concat (#5220)
This commit is contained in:
@@ -93,8 +93,7 @@ type featureGate struct {
|
|||||||
|
|
||||||
// NewFeatureGate creates a new feature gate with the default features
|
// NewFeatureGate creates a new feature gate with the default features
|
||||||
func NewFeatureGate() MutableFeatureGate {
|
func NewFeatureGate() MutableFeatureGate {
|
||||||
known := map[Feature]FeatureSpec{}
|
known := maps.Clone(defaultFeatures)
|
||||||
maps.Copy(known, defaultFeatures)
|
|
||||||
|
|
||||||
f := &featureGate{}
|
f := &featureGate{}
|
||||||
f.known.Store(known)
|
f.known.Store(known)
|
||||||
@@ -108,10 +107,8 @@ func (f *featureGate) SetFromMap(m map[string]bool) error {
|
|||||||
defer f.lock.Unlock()
|
defer f.lock.Unlock()
|
||||||
|
|
||||||
// Copy existing state
|
// Copy existing state
|
||||||
known := map[Feature]FeatureSpec{}
|
known := maps.Clone(f.known.Load().(map[Feature]FeatureSpec))
|
||||||
maps.Copy(known, f.known.Load().(map[Feature]FeatureSpec))
|
enabled := maps.Clone(f.enabled.Load().(map[Feature]bool))
|
||||||
enabled := map[Feature]bool{}
|
|
||||||
maps.Copy(enabled, f.enabled.Load().(map[Feature]bool))
|
|
||||||
|
|
||||||
// Apply the new settings
|
// Apply the new settings
|
||||||
for k, v := range m {
|
for k, v := range m {
|
||||||
@@ -142,8 +139,7 @@ func (f *featureGate) Add(features map[Feature]FeatureSpec) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Copy existing state
|
// Copy existing state
|
||||||
known := map[Feature]FeatureSpec{}
|
known := maps.Clone(f.known.Load().(map[Feature]FeatureSpec))
|
||||||
maps.Copy(known, f.known.Load().(map[Feature]FeatureSpec))
|
|
||||||
|
|
||||||
// Add new features
|
// Add new features
|
||||||
for name, spec := range features {
|
for name, spec := range features {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"maps"
|
"maps"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
flog "github.com/fatedier/frp/pkg/util/log"
|
flog "github.com/fatedier/frp/pkg/util/log"
|
||||||
@@ -14,9 +15,7 @@ import (
|
|||||||
// RunProcesses run multiple processes from templates.
|
// RunProcesses run multiple processes from templates.
|
||||||
// The first template should always be frps.
|
// The first template should always be frps.
|
||||||
func (f *Framework) RunProcesses(serverTemplates []string, clientTemplates []string) ([]*process.Process, []*process.Process) {
|
func (f *Framework) RunProcesses(serverTemplates []string, clientTemplates []string) ([]*process.Process, []*process.Process) {
|
||||||
templates := make([]string, 0, len(serverTemplates)+len(clientTemplates))
|
templates := slices.Concat(serverTemplates, clientTemplates)
|
||||||
templates = append(templates, serverTemplates...)
|
|
||||||
templates = append(templates, clientTemplates...)
|
|
||||||
outs, ports, err := f.RenderTemplates(templates)
|
outs, ports, err := f.RenderTemplates(templates)
|
||||||
ExpectNoError(err)
|
ExpectNoError(err)
|
||||||
ExpectTrue(len(templates) > 0)
|
ExpectTrue(len(templates) > 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user