Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
bassosimone committed Jun 27, 2024
1 parent 4575f5e commit d1f243d
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions internal/registry/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,47 @@ var (

// Options returns the options exposed by this experiment.
func (b *Factory) Options() (map[string]model.ExperimentOptionInfo, error) {
// create the result value
result := make(map[string]model.ExperimentOptionInfo)

// make sure we're dealing with a pointer
ptrinfo := reflect.ValueOf(b.config)
if ptrinfo.Kind() != reflect.Ptr {
return nil, ErrConfigIsNotAStructPointer
}

// obtain information about the value and its type
valueinfo := ptrinfo.Elem()
structinfo := valueinfo.Type()
if structinfo.Kind() != reflect.Struct {
typeinfo := valueinfo.Type()

// make sure we're dealing with a struct
if typeinfo.Kind() != reflect.Struct {
return nil, ErrConfigIsNotAStructPointer
}
for i := 0; i < structinfo.NumField(); i++ {
field := structinfo.Field(i)
result[field.Name] = model.ExperimentOptionInfo{
Doc: field.Tag.Get("ooni"),
Type: field.Type.String(),
Value: valueinfo.Field(i).Interface(),

// cycle through the fields
for i := 0; i < typeinfo.NumField(); i++ {
fieldType, fieldValue := typeinfo.Field(i), valueinfo.Field(i)

// do not include private fields into our list of fields
if !fieldType.IsExported() {
continue
}

// skip fields that are missing an `ooni` tag
docs := fieldType.Tag.Get("ooni")
if docs == "" {
continue
}

// create a description of this field
result[fieldType.Name] = model.ExperimentOptionInfo{
Doc: docs,
Type: fieldType.Type.String(),
Value: fieldValue.Interface(),
}
}

return result, nil
}

Expand Down

0 comments on commit d1f243d

Please sign in to comment.