git.sr.ht/~sircmpwn/gqlgen@v0.0.0-20200522192042-c84d29a1c940/codegen/testserver/interfaces.go (about)

     1  package testserver
     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  }
    18  
    19  func (c *Circle) Area() float64 {
    20  	return c.Radius * math.Pi * math.Pi
    21  }
    22  
    23  func (c *Circle) isShapeUnion() {}
    24  func (c *Circle) isShape()      {}
    25  
    26  type Rectangle struct {
    27  	Length, Width float64
    28  }
    29  
    30  func (r *Rectangle) Area() float64 {
    31  	return r.Length * r.Width
    32  }
    33  func (r *Rectangle) isShapeUnion() {}
    34  func (r *Rectangle) isShape()      {}
    35  
    36  type Node interface {
    37  	Child() (Node, error)
    38  }
    39  
    40  type ConcreteNodeA struct {
    41  	ID    string
    42  	Name  string
    43  	child Node
    44  }
    45  
    46  func (n *ConcreteNodeA) Child() (Node, error) {
    47  	return n.child, nil
    48  }
    49  
    50  //  Implements the Node interface with another interface
    51  type ConcreteNodeInterface interface {
    52  	Node
    53  	ID() string
    54  }
    55  
    56  type ConcreteNodeInterfaceImplementor struct{}
    57  
    58  func (c ConcreteNodeInterfaceImplementor) ID() string {
    59  	return "CNII"
    60  }
    61  
    62  func (c ConcreteNodeInterfaceImplementor) Child() (Node, error) {
    63  	return &ConcreteNodeA{
    64  		ID:   "Child",
    65  		Name: "child",
    66  	}, nil
    67  }
    68  
    69  type BackedByInterface interface {
    70  	ThisShouldBind() string
    71  	ThisShouldBindWithError() (string, error)
    72  }
    73  
    74  type BackedByInterfaceImpl struct {
    75  	Value string
    76  	Error error
    77  }
    78  
    79  func (b *BackedByInterfaceImpl) ThisShouldBind() string {
    80  	return b.Value
    81  }
    82  func (b *BackedByInterfaceImpl) ThisShouldBindWithError() (string, error) {
    83  	return b.Value, b.Error
    84  }