Skip to content

Commit 00576a2

Browse files
committed
Scope property as int pointer
Signed-off-by: Lionel Jouin <[email protected]>
1 parent a4d4a0d commit 00576a2

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

pkg/types/types.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ type Route struct {
171171
AdvMSS int
172172
Priority int
173173
Table *int
174-
Scope int
174+
Scope *int
175175
}
176176

177177
func (r *Route) String() string {
@@ -180,7 +180,12 @@ func (r *Route) String() string {
180180
table = fmt.Sprintf("%d", *r.Table)
181181
}
182182

183-
return fmt.Sprintf("{Dst:%+v GW:%v MTU:%d AdvMSS:%d Priority:%d Table:%s Scope:%d}", r.Dst, r.GW, r.MTU, r.AdvMSS, r.Priority, table, r.Scope)
183+
scope := "<nil>"
184+
if r.Scope != nil {
185+
scope = fmt.Sprintf("%d", *r.Scope)
186+
}
187+
188+
return fmt.Sprintf("{Dst:%+v GW:%v MTU:%d AdvMSS:%d Priority:%d Table:%s Scope:%s}", r.Dst, r.GW, r.MTU, r.AdvMSS, r.Priority, table, scope)
184189
}
185190

186191
func (r *Route) Copy() *Route {
@@ -202,6 +207,11 @@ func (r *Route) Copy() *Route {
202207
route.Table = &table
203208
}
204209

210+
if r.Scope != nil {
211+
scope := *r.Scope
212+
route.Scope = &scope
213+
}
214+
205215
return route
206216
}
207217

@@ -258,7 +268,7 @@ type route struct {
258268
AdvMSS int `json:"advmss,omitempty"`
259269
Priority int `json:"priority,omitempty"`
260270
Table *int `json:"table,omitempty"`
261-
Scope int `json:"scope,omitempty"`
271+
Scope *int `json:"scope,omitempty"`
262272
}
263273

264274
func (r *Route) UnmarshalJSON(data []byte) error {

pkg/types/types_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ var _ = Describe("Types", func() {
9393
AdvMSS: 1340,
9494
Priority: 100,
9595
Table: types040.Int(50),
96-
Scope: 253,
96+
Scope: types040.Int(253),
9797
}
9898
})
9999

0 commit comments

Comments
 (0)