initExample sets the example or examples of the given object.
(obj exampler, attr *expr.AttributeExpr, r *expr.ExampleGenerator)
| 15 | |
| 16 | // initExample sets the example or examples of the given object. |
| 17 | func initExamples(obj exampler, attr *expr.AttributeExpr, r *expr.ExampleGenerator) { |
| 18 | examples := attr.ExtractUserExamples() |
| 19 | switch { |
| 20 | case len(examples) > 1: |
| 21 | refs := make(map[string]*ExampleRef, len(examples)) |
| 22 | for _, ex := range examples { |
| 23 | example := &Example{ |
| 24 | Summary: ex.Summary, |
| 25 | Description: ex.Description, |
| 26 | Value: ex.Value, |
| 27 | } |
| 28 | refs[ex.Summary] = &ExampleRef{Value: example} |
| 29 | } |
| 30 | obj.setExamples(refs) |
| 31 | return |
| 32 | case len(examples) > 0: |
| 33 | obj.setExample(examples[0].Value) |
| 34 | default: |
| 35 | obj.setExample(attr.Example(r)) |
| 36 | } |
| 37 | } |
no test coverage detected