Skip to content
This repository has been archived by the owner on Oct 6, 2022. It is now read-only.

Commit

Permalink
Val() helper method for nullable enum types
Browse files Browse the repository at this point in the history
  • Loading branch information
mxmCherry committed Oct 26, 2017
1 parent 53a3574 commit a0ed15f
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ad_position.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ const (
func (p AdPosition) Ptr() *AdPosition {
return &p
}

// Val safely dereferences pointer, returning default value (AdPositionUnknown) for nil.
func (p *AdPosition) Val() AdPosition {
if p == nil {
return AdPositionUnknown
}
return *p
}
8 changes: 8 additions & 0 deletions connection_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ const (
func (t ConnectionType) Ptr() *ConnectionType {
return &t
}

// Val safely dereferences pointer, returning default value (ConnectionTypeUnknown) for nil.
func (t *ConnectionType) Val() ConnectionType {
if t == nil {
return ConnectionTypeUnknown
}
return *t
}
8 changes: 8 additions & 0 deletions no_bid_reason_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ const (
func (c NoBidReasonCode) Ptr() *NoBidReasonCode {
return &c
}

// Val safely dereferences pointer, returning default value (NoBidReasonCodeUnknownError) for nil.
func (c *NoBidReasonCode) Val() NoBidReasonCode {
if c == nil {
return NoBidReasonCodeUnknownError
}
return *c
}
8 changes: 8 additions & 0 deletions production_quality.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,11 @@ const (
func (q ProductionQuality) Ptr() *ProductionQuality {
return &q
}

// Val safely dereferences pointer, returning default value (ProductionQualityUnknown) for nil.
func (q *ProductionQuality) Val() ProductionQuality {
if q == nil {
return ProductionQualityUnknown
}
return *q
}
8 changes: 8 additions & 0 deletions start_delay.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ const (
func (d StartDelay) Ptr() *StartDelay {
return &d
}

// Val safely dereferences pointer, returning default value (StartDelayPreRoll) for nil.
func (d *StartDelay) Val() StartDelay {
if d == nil {
return StartDelayPreRoll
}
return *d
}
8 changes: 8 additions & 0 deletions volume_normalization_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,11 @@ const (
func (m VolumeNormalizationMode) Ptr() *VolumeNormalizationMode {
return &m
}

// Val safely dereferences pointer, returning default value (VolumeNormalizationModeNone) for nil.
func (m *VolumeNormalizationMode) Val() VolumeNormalizationMode {
if m == nil {
return VolumeNormalizationModeNone
}
return *m
}

0 comments on commit a0ed15f

Please sign in to comment.