github.com/operandinc/gqlgen@v0.16.1/codegen/testserver/followschema/interfaces.go (about)

     1  package followschema
     2  
     3  import "math"
     4  
     5  type Shape interface {
     6  	Area() float64
     7  	isShape()
     8  }
     9  
    10  type ShapeUnion interface {
    11  	Area() float64
    12  	isShapeUnion()
    13  }
    14  
    15  type Circle struct {
    16  	Radius float64
    17  	Coordinates
    18  }
    19  
    20  func (c *Circle) Area() float64 {
    21  	return c.Radius * math.Pi * math.Pi
    22  }
    23  
    24  func (c *Circle) isShapeUnion() {}
    25  func (c *Circle) isShape()      {}
    26  
    27  type Rectangle struct {
    28  	Length, Width float64
    29  	Coordinates
    30  }
    31  
    32  func (r *Rectangle) Area() float64 {
    33  	return r.Length * r.Width
    34  }
    35  func (r *Rectangle) isShapeUnion() {}
    36  func (r *Rectangle) isShape()      {}
    37  
    38  type Node interface {
    39  	Child() (Node, error)
    40  }
    41  
    42  type ConcreteNodeA struct {
    43  	ID    string
    44  	Name  string
    45  	child Node
    46  }
    47  
    48  func (n *ConcreteNodeA) Child() (Node, error) {
    49  	return n.child, nil
    50  }
    51  
    52  //  Implements the Node interface with another interface
    53  type ConcreteNodeInterface interface {
    54  	Node
    55  	ID() string
    56  }
    57  
    58  type ConcreteNodeInterfaceImplementor struct{}
    59  
    60  func (c ConcreteNodeInterfaceImplementor) ID() string {
    61  	return "CNII"
    62  }
    63  
    64  func (c ConcreteNodeInterfaceImplementor) Child() (Node, error) {
    65  	return &ConcreteNodeA{
    66  		ID:   "Child",
    67  		Name: "child",
    68  	}, nil
    69  }
    70  
    71  type BackedByInterface interface {
    72  	ThisShouldBind() string
    73  	ThisShouldBindWithError() (string, error)
    74  }
    75  
    76  type BackedByInterfaceImpl struct {
    77  	Value string
    78  	Error error
    79  }
    80  
    81  func (b *BackedByInterfaceImpl) ThisShouldBind() string {
    82  	return b.Value
    83  }
    84  
    85  func (b *BackedByInterfaceImpl) ThisShouldBindWithError() (string, error) {
    86  	return b.Value, b.Error
    87  }