Skip to content

Commit

Permalink
Add metadata in your flag configuration (#857)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaspoignant authored Jun 9, 2023
1 parent ed6cdf4 commit 2f9bccf
Show file tree
Hide file tree
Showing 24 changed files with 600 additions and 24 deletions.
5 changes: 5 additions & 0 deletions cmd/relayproxy/docs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions cmd/relayproxy/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@
"type": "boolean",
"example": false
},
"metadata": {
"description": "Metadata is a field containing information about your flag such as an issue tracker link, a description, etc ...",
"type": "object",
"additionalProperties": true
},
"reason": {
"description": "reason why we have returned this value.",
"type": "string",
Expand Down
5 changes: 5 additions & 0 deletions cmd/relayproxy/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ definitions:
not exists, ...) and we serve the defaultValue.'
example: false
type: boolean
metadata:
additionalProperties: true
description: Metadata is a field containing information about your flag such
as an issue tracker link, a description, etc ...
type: object
reason:
description: reason why we have returned this value.
example: TARGETING_MATCH
Expand Down
1 change: 0 additions & 1 deletion cmd/relayproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ _____________________________________________`
// @license.url https://github.com/thomaspoignant/go-feature-flag/blob/main/LICENSE
// @x-logo {"url":"https://raw.githubusercontent.com/thomaspoignant/go-feature-flag/main/logo_128.png"}
// @BasePath /

// @securitydefinitions.apikey ApiKeyAuth
// @in header
// @name Authorization
Expand Down
2 changes: 2 additions & 0 deletions cmd/relayproxy/modeldocs/eval_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ type EvalFlagDoc struct {
ErrorCode string `json:"errorCode" example:""`
// The flag value for this user.
Value interface{} `json:"value"`
// Metadata is a field containing information about your flag such as an issue tracker link, a description, etc ...
Metadata *map[string]interface{} `json:"metadata" yaml:"metadata,omitempty" toml:"metadata,omitempty"`
}
1 change: 1 addition & 0 deletions internal/dto/convert_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ func ConvertV1DtoToInternalFlag(dto DTO) flag.InternalFlag {
Version: dto.Version,
Scheduled: dto.Scheduled,
Experimentation: experimentation,
Metadata: dto.Metadata,
}
}
3 changes: 3 additions & 0 deletions internal/dto/dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ type DTOv1 struct {
// an end date for your flag.
// When the experimentation is not running, the flag will serve the default value.
Experimentation *ExperimentationDto `json:"experimentation,omitempty" yaml:"experimentation,omitempty" toml:"experimentation,omitempty"` // nolint: lll

// Metadata is a field containing information about your flag such as an issue tracker link, a description, etc ...
Metadata *map[string]interface{} `json:"metadata,omitempty" yaml:"metadata,omitempty" toml:"metadata,omitempty"`
}

// DTOv0 describe the fields of a flag.
Expand Down
3 changes: 3 additions & 0 deletions internal/flag/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ type Flag interface {

// GetVariationValue return the value of variation from his name
GetVariationValue(name string) interface{}

// GetMetadata return the metadata associated to the flag
GetMetadata() map[string]interface{}
}
14 changes: 14 additions & 0 deletions internal/flag/internal_flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ type InternalFlag struct {
// The version is manually managed when you configure your flags, and it is used to display the information
// in the notifications and data collection.
Version *string `json:"version,omitempty" yaml:"version,omitempty" toml:"version,omitempty"`

// Metadata is a field containing information about your flag such as an issue tracker link, a description, etc ...
Metadata *map[string]interface{} `json:"metadata,omitempty" yaml:"metadata,omitempty" toml:"metadata,omitempty"`
}

// Value is returning the Value associate to the flag
Expand All @@ -69,6 +72,7 @@ func (f *InternalFlag) Value(
Variant: VariationSDKDefault,
Reason: ReasonDisabled,
Cacheable: f.isCacheable(),
Metadata: f.GetMetadata(),
}
}

Expand All @@ -79,6 +83,7 @@ func (f *InternalFlag) Value(
Variant: VariationSDKDefault,
Reason: ReasonError,
ErrorCode: ErrorFlagConfiguration,
Metadata: f.GetMetadata(),
}
}

Expand All @@ -88,6 +93,7 @@ func (f *InternalFlag) Value(
RuleIndex: variationSelection.ruleIndex,
RuleName: variationSelection.ruleName,
Cacheable: variationSelection.cacheable,
Metadata: f.GetMetadata(),
}
}

Expand Down Expand Up @@ -332,3 +338,11 @@ func (f *InternalFlag) GetVariationValue(name string) interface{} {
}
return nil
}

// GetMetadata return the metadata associated to the flag
func (f *InternalFlag) GetMetadata() map[string]interface{} {
if f.Metadata == nil {
return nil
}
return *f.Metadata
}
Loading

0 comments on commit 2f9bccf

Please sign in to comment.