Skip to content

Commit ef6405e

Browse files
author
xuleiming
committed
fix nil
Signed-off-by: xuleiming <xuleiming@yf-networks.com>
1 parent 5ed7898 commit ef6405e

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

bfe_modules/mod_wasmplug/conf_mod_wasmplug.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ type PluginMeta struct {
9898

9999
type FilterRule struct {
100100
Cond condition.Condition // condition for plugin
101-
PluginList []*bfe_wasmplug.WasmPlugin
101+
PluginList []bfe_wasmplug.WasmPlugin
102102
}
103103

104104
type RuleList []FilterRule
105-
type ProductRules map[string]*RuleList // product => list of filter rules
105+
type ProductRules map[string]RuleList // product => list of filter rules
106106

107107
func updatePluginConf(t *PluginTable, conf PluginConfFile, pluginPath string) error {
108108
if conf.Version != nil && *conf.Version != t.GetVersion() {
109-
pluginMapNew := make(map[string]*bfe_wasmplug.WasmPlugin)
109+
pluginMapNew := make(map[string]bfe_wasmplug.WasmPlugin)
110110
var beforeLocationRulesNew RuleList
111111
productRulesNew := make(ProductRules)
112112

@@ -116,16 +116,16 @@ func updatePluginConf(t *PluginTable, conf PluginConfFile, pluginPath string) er
116116
pm := t.GetPluginMap()
117117
if conf.PluginMap != nil {
118118
for pn, p := range *conf.PluginMap {
119-
plugOld := (*pm)[pn]
119+
plugOld := pm[pn]
120120
// check whether plugin version changed.
121121
if plugOld != nil {
122-
configOld := (*plugOld).GetConfig()
122+
configOld := plugOld.GetConfig()
123123
if configOld.WasmVersion == p.WasmVersion && configOld.ConfigVersion == p.ConfVersion {
124124
// not change, just copy to new map
125125
pluginMapNew[pn] = plugOld
126126

127127
// ensure instance num
128-
actual := (*plugOld).EnsureInstanceNum(p.InstanceNum)
128+
actual := plugOld.EnsureInstanceNum(p.InstanceNum)
129129
if actual != p.InstanceNum {
130130
return fmt.Errorf("can not EnsureInstanceNum, plugin:%s, num:%d", pn, p.InstanceNum)
131131
}
@@ -151,7 +151,7 @@ func updatePluginConf(t *PluginTable, conf PluginConfFile, pluginPath string) er
151151

152152
// plug.OnPluginStart()
153153

154-
pluginMapNew[pn] = &plug
154+
pluginMapNew[pn] = plug
155155
}
156156
}
157157

@@ -194,19 +194,19 @@ func updatePluginConf(t *PluginTable, conf PluginConfFile, pluginPath string) er
194194
}
195195
rulelist = append(rulelist, rule)
196196
}
197-
productRulesNew[product] = &rulelist
197+
productRulesNew[product] = rulelist
198198
}
199199
}
200200

201201
// 3. update PluginTable
202-
t.Update(*conf.Version, &beforeLocationRulesNew, productRulesNew, &pluginMapNew)
202+
t.Update(*conf.Version, beforeLocationRulesNew, productRulesNew, pluginMapNew)
203203

204204
// 4. stop & clear old plugins
205-
for pn, plug := range *pm {
205+
for pn, plug := range pm {
206206
if _, ok := unchanged[pn]; !ok {
207207
// stop plug
208-
(*plug).OnPluginDestroy()
209-
(*plug).Clear()
208+
plug.OnPluginDestroy()
209+
plug.Clear()
210210
}
211211
}
212212
}
@@ -216,19 +216,19 @@ func updatePluginConf(t *PluginTable, conf PluginConfFile, pluginPath string) er
216216
type PluginTable struct {
217217
lock sync.RWMutex
218218
version string
219-
beforeLocationRules *RuleList
219+
beforeLocationRules RuleList
220220
productRules ProductRules
221-
pluginMap *map[string]*bfe_wasmplug.WasmPlugin
221+
pluginMap map[string]bfe_wasmplug.WasmPlugin
222222
}
223223

224224
func NewPluginTable() *PluginTable {
225225
t := new(PluginTable)
226226
t.productRules = make(ProductRules)
227-
t.pluginMap = new(map[string]*bfe_wasmplug.WasmPlugin)
227+
t.pluginMap = make(map[string]bfe_wasmplug.WasmPlugin)
228228
return t
229229
}
230230

231-
func (t *PluginTable) Update(version string, beforeLocationRules *RuleList, productRules ProductRules, pluginMap *map[string]*bfe_wasmplug.WasmPlugin) {
231+
func (t *PluginTable) Update(version string, beforeLocationRules RuleList, productRules ProductRules, pluginMap map[string]bfe_wasmplug.WasmPlugin) {
232232
t.lock.Lock()
233233

234234
t.version = version
@@ -245,19 +245,19 @@ func (t *PluginTable) GetVersion() string {
245245
return t.version
246246
}
247247

248-
func (t *PluginTable) GetPluginMap() *map[string]*bfe_wasmplug.WasmPlugin {
248+
func (t *PluginTable) GetPluginMap() map[string]bfe_wasmplug.WasmPlugin {
249249
defer t.lock.RUnlock()
250250
t.lock.RLock()
251251
return t.pluginMap
252252
}
253253

254-
func (t *PluginTable) GetBeforeLocationRules() *RuleList {
254+
func (t *PluginTable) GetBeforeLocationRules() RuleList {
255255
defer t.lock.RUnlock()
256256
t.lock.RLock()
257257
return t.beforeLocationRules
258258
}
259259

260-
func (t *PluginTable) Search(product string) (*RuleList, bool) {
260+
func (t *PluginTable) Search(product string) (RuleList, bool) {
261261
t.lock.RLock()
262262
productRules := t.productRules
263263
t.lock.RUnlock()

bfe_modules/mod_wasmplug/mod_wasmplug.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ func (m *ModuleWasm) init(cfg *ConfModWasm, cbs *bfe_module.BfeCallbacks,
127127

128128
//
129129
func (m *ModuleWasm) wasmBeforeLocationHandler(request *bfe_basic.Request) (int, *bfe_http.Response) {
130-
var pl []*bfe_wasmplug.WasmPlugin
130+
var pl []bfe_wasmplug.WasmPlugin
131131
rl := m.pluginTable.GetBeforeLocationRules()
132-
for _, rule := range *rl {
132+
for _, rule := range rl {
133133
if rule.Cond.Match(request) {
134134
// find pluginlist
135135
pl = rule.PluginList
@@ -162,9 +162,9 @@ func (m *ModuleWasm) wasmBeforeLocationHandler(request *bfe_basic.Request) (int,
162162

163163
//
164164
func (m *ModuleWasm) wasmRequestHandler(request *bfe_basic.Request) (int, *bfe_http.Response) {
165-
var pl []*bfe_wasmplug.WasmPlugin
165+
var pl []bfe_wasmplug.WasmPlugin
166166
rl, _ := m.pluginTable.Search(request.Route.Product)
167-
for _, rule := range *rl {
167+
for _, rule := range rl {
168168
if rule.Cond.Match(request) {
169169
// find pluginlist
170170
pl = rule.PluginList

bfe_wasmplug/filter.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ func newContextID(rootContextID int32) int32 {
5353
}
5454
}
5555

56-
func NewFilter(plugin *WasmPlugin, request *bfe_basic.Request) *Filter {
57-
instance := (*plugin).GetInstance()
58-
rootContextID := (*plugin).GetRootContextID()
56+
func NewFilter(plugin WasmPlugin, request *bfe_basic.Request) *Filter {
57+
instance := plugin.GetInstance()
58+
rootContextID := plugin.GetRootContextID()
5959

6060
filter := &Filter{
61-
plugin: *plugin,
61+
plugin: plugin,
6262
instance: instance,
6363
rootContextID: rootContextID,
6464
contextID: newContextID(rootContextID),
@@ -69,7 +69,7 @@ func NewFilter(plugin *WasmPlugin, request *bfe_basic.Request) *Filter {
6969
log.Logger.Info("[proxywasm][filter] abi version: %v", filter.abi.Name())
7070
if filter.abi != nil {
7171
// v1
72-
imports := &v1Imports{plugin: *plugin, filter: filter}
72+
imports := &v1Imports{plugin: plugin, filter: filter}
7373
imports.DefaultImportsHandler.Instance = instance
7474
filter.abi.SetImports(imports)
7575
filter.exports = filter.abi.GetExports()

0 commit comments

Comments
 (0)