Extend adds the parameter type attributes to the type using Extend. The parameter type must be an object. Extend may be used in Type or ResultType. Extend accepts a single argument: the type or result type containing the attributes to be copied. Example: var CreateBottlePayload = Type("CreateBot
(t expr.DataType)
| 453 | // Extend(CreateBottlePayload) // Adds attributes "name" and "vintage" |
| 454 | // }) |
| 455 | func Extend(t expr.DataType) { |
| 456 | if !expr.IsObject(t) { |
| 457 | eval.ReportError("argument of Extend must be an object, got %s", t.Name()) |
| 458 | return |
| 459 | } |
| 460 | switch def := eval.Current().(type) { |
| 461 | case *expr.ResultTypeExpr: |
| 462 | def.Bases = append(def.Bases, t) |
| 463 | case *expr.AttributeExpr: |
| 464 | def.Bases = append(def.Bases, t) |
| 465 | default: |
| 466 | eval.IncompatibleDSL() |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | // Attributes implements the result type Attributes DSL. See ResultType. |
| 471 | func Attributes(fn func()) { |
no test coverage detected