// DomainDefinition defines the entire domain.
436081
func (g *Generator) DomainDefinition(d proto.Domain) {
	g.hasContent = true

	comment := fmt.Sprintf("domainClient is a client for the %s domain. ", d.Name())
	g.Printf(`
// %[1]s%[3]s
type domainClient struct{ conn *rpcc.Conn }

// NewClient returns a client for the %[2]s domain with the connection set to conn.
func NewClient(conn *rpcc.Conn) *domainClient {
	return &domainClient{conn: conn}
}
`, comment, d.Name(), d.Desc(0, len(comment)))

	for _, c := range d.Commands {
		if c.Redirect != "" {
			continue
		}
		request := ""
		invokeReply := "nil"
		if len(c.Parameters) > 0 {
			request = ", args *" + c.ArgsName(d)
		}
		reply := "(err error)"
		if len(c.Returns) > 0 {
			reply = fmt.Sprintf("(reply *%s, err error)", c.ReplyName(d))
		}
		comment := fmt.Sprintf("%[1]s invokes the %[2]s method. ", c.Name(), d.Name())
		g.Printf(`
// %[2]s%[5]s
func (d *domainClient) %[1]s(ctx context.Context%[3]s) %[4]s {`, c.Name(), comment, request, reply, c.Desc(true, 0, len(comment)))
		if len(c.Returns) > 0 {
			g.Printf(`
	reply = new(%s)`, c.ReplyName(d))
			invokeReply = "reply"
		}
		if len(c.Parameters) > 0 {
			g.Printf(`
	if args != nil {
		err = rpcc.Invoke(ctx, %[1]q, args, %[2]s, d.conn)
	} else {
		err = rpcc.Invoke(ctx, %[1]q, nil, %[2]s, d.conn)
	}
	if err != nil {
		err = &internal.OpError{Domain: %[3]q, Op: %[4]q, Err: err}
	}
	return
}
`, d.Domain+"."+c.NameName, invokeReply, d.Name(), c.Name())
		} else {
			g.Printf(`
	err = rpcc.Invoke(ctx, %q, nil, %s, d.conn)
	if err != nil {
		err = &internal.OpError{Domain: %q, Op: %q, Err: err}
	}
	return
}
`, d.Domain+"."+c.NameName, invokeReply, d.Name(), c.Name())
		}

		// Generate method tests.
		g.TestPrintf(`
func Test%[1]s_%[2]s(t *testing.T) {
	conn, codec, cleanup := newTestConn(t)
	defer cleanup()

	dom := New%[1]s(conn)
	var err error
`, d.Name(), c.Name())
		assign := "err"
		if len(c.Returns) > 0 {
			assign = "_, err"
		}
		if len(c.Parameters) > 0 {
			g.TestPrintf(`
	// Test nil args.
	%[1]s = dom.%[2]s(nil, nil)
	if err != nil {
		t.Error(err)
	}
	// Test args.
	%[1]s = dom.%[2]s(nil, &%[3]s{})`, assign, c.Name(), c.ArgsName(d))
		} else {
			g.TestPrintf(`
	%[1]s = dom.%[2]s(nil)`, assign, c.Name())
		}
		g.TestPrintf(`
	if err != nil {
		t.Error(err)
	}

	// Test error.
	codec.respErr = errors.New("bad request")`)
		if len(c.Parameters) > 0 {
			g.TestPrintf(`
	%[1]s = dom.%[2]s(nil, &%[3]s{})`, assign, c.Name(), c.ArgsName(d))
		} else {
			g.TestPrintf(`
	%[1]s = dom.%[2]s(nil)`, assign, c.Name())
		}
		g.TestPrintf(`
	if err == nil || err.(*internal.OpError).Err.(*rpcc.ResponseError).Message != codec.respErr.Error() {
		t.Errorf("unexpected error; got: %%v, want bad request", err)
	}`)
		g.TestPrintf(`
}
`)

	}
	for _, e := range d.Events {
		eventClient := fmt.Sprintf("%sClient", e.EventName(d))
		eventClientImpl := strings.ToLower(string(eventClient[0])) + eventClient[1:]

		// Implement event on domain.
		g.Printf(`
func (d *domainClient) %s(ctx context.Context) (%s, error) {
	s, err := rpcc.NewStream(ctx, %q, d.conn)
	if err != nil {
		return nil, err
	}
	return &%s{Stream: s}, nil
}
`, e.Name(), eventClient, d.Domain+"."+e.NameName, eventClientImpl)

		g.Printf(`
type %[4]s struct { rpcc.Stream }

// GetStream returns the original Stream for use with cdp.Sync.
func (c *%[4]s) GetStream() rpcc.Stream { return c.Stream }

func (c *%[4]s) Recv() (*%[3]s, error) {
	event := new(%[3]s)
	if err := c.RecvMsg(event); err != nil {
		return nil, &internal.OpError{Domain: %[5]q, Op: "%[6]s Recv", Err: err}
	}
	return event, nil
}
`, eventClient, "", e.ReplyName(d), eventClientImpl, d.Name(), e.Name())

		// Generate event tests.
		g.TestPrintf(`
func Test%[1]s_%[2]s(t *testing.T) {
	conn, codec, cleanup := newTestConn(t)
	defer cleanup()

	dom := New%[1]s(conn)

	stream, err := dom.%[2]s(nil)
	if err != nil {
		t.Fatal(err)
	}
	defer stream.Close()

	codec.event = %[3]s.String()
	codec.conn <- nil
	_, err = stream.Recv()
	if err != nil {
		t.Error(err)
	}

	codec.eventArgs = []byte("invalid json")
	codec.conn <- nil
	_, err = stream.Recv()
	if err, ok := err.(*internal.OpError); !ok {
		t.Errorf("Recv() got %%v, want internal.OpError", err)
	}

	conn.Close()
	stream, err = dom.%[2]s(nil)
	if err == nil {
		t.Errorf("Open stream: got nil, want error")
	}
`, d.Name(), e.Name(), e.EventName(d))
		g.TestPrintf(`
}
`)
	}
}
31448
func (s *CreateServiceActionInput) SetDefinitionType(v string) *CreateServiceActionInput {
	s.DefinitionType = &v
	return s
}
193738
func (org *Organization) Domains() ([]*Domain, error) {
	var d domainsResponse
	err := org.PPE.get(fmt.Sprintf("/domains/%s", org.PrimaryDomain), &d)
	if err != nil {
		return []*Domain{}, err
	}
	drs := d.Domains
	doms := make([]*Domain, len(org.domains))
	for _, dr := range drs {
		for i, dom := range org.domains {
			if dr.DomainName == dom {
				doms[i] = domainFromDomainResponse(org, dr)
			}
		}
	}
	return doms, nil
}
15464
func (o *Domain) Domains(info *bambou.FetchingInfo) (DomainsList, *bambou.Error) {

	var list DomainsList
	err := bambou.CurrentSession().FetchChildren(o, DomainIdentity, &list, info)
	return list, err
}
30237
func FormatDefinition(definition []string, count int) string {
	var buffer bytes.Buffer

	spacer := strings.Repeat(" ", count)

	for i, d := range definition {
		if i == 0 {
			buffer.WriteString(d)
			buffer.WriteString("\n")
		} else {
			buffer.WriteString(spacer)
			buffer.WriteString(d)
			buffer.WriteString("\n")
		}
	}

	return strings.TrimSuffix(buffer.String(), "\n")
}
119053
func Domains(argv []string) error {
	usage := `
Valid commands for domains:

domains:add           bind a domain to an application
domains:list          list domains bound to an application
domains:remove        unbind a domain from an application

Use 'deis help [command]' to learn more.
`
	switch argv[0] {
	case "domains:add":
		return domainsAdd(argv)
	case "domains:list":
		return domainsList(argv)
	case "domains:remove":
		return domainsRemove(argv)
	default:
		if printHelp(argv, usage) {
			return nil
		}

		if argv[0] == "domains" {
			argv[0] = "domains:list"
			return domainsList(argv)
		}

		PrintUsage()
		return nil
	}
}
193972
func (g *Generator) DomainType(d proto.Domain, t proto.AnyType) {
	g.hasContent = true

	var comment string
	if d.Name() == "Page" && (t.Name(d) == "FrameID") {
		comment = "//"
		g.Printf(`
// %[1]s %[2]s
//
// Provided as an alias to prevent circular dependencies.
type %[1]s = internal.Page%[1]s
`, t.Name(d), t.Desc(0, len(t.Name(d))+1))
	}
	desc := t.Desc(0, len(t.Name(d))+1)
	if t.Deprecated {
		desc = "\n//\n// Deprecated: " + t.Desc(0, 12)
	}
	if t.Experimental {
		desc = desc + "\n//\n// Note: This type is experimental."
	}
	g.Printf(`
// %[1]s %[2]s
%[3]stype %[1]s `, t.Name(d), desc, comment)

	typ := t.GoType(g.pkg, d)
	switch typ {
	case "struct":
		g.domainTypeStruct(d, t)
	case "enum":
		g.domainTypeEnum(d, t)
	case "time.Time":
		g.domainTypeTime(d, t)
	case "RawMessage":
		g.domainTypeRawMessage(d, t)
	default:
		g.Printf(typ)
	}
	g.Printf("\n\n")
}
1246008
func (g *Generator) DomainInterface(d proto.Domain) {
	g.hasContent = true

	comment := "The " + d.Name() + " domain. "
	desc := d.Desc(0, len(comment))
	if d.Deprecated {
		desc = "\n//\n// Deprecated: " + desc
	}
	if d.Experimental {
		desc += "\n//\n// Note: This domain is experimental."
	}
	g.Printf(`
// %[1]s%[2]s
type %[3]s interface{`, comment, desc, d.Name())
	for _, c := range d.Commands {
		if c.Redirect != "" {
			continue
		}
		request := ""
		reply := "error"
		if len(c.Parameters) > 0 {
			request = ", *" + strings.ToLower(d.Name()) + "." + c.ArgsName(d)
		}
		if len(c.Returns) > 0 {
			reply = fmt.Sprintf("(*%s.%s, error)", strings.ToLower(d.Name()), c.ReplyName(d))
		}
		desc := c.Desc(true, 8, 0)
		if c.Deprecated {
			desc = strings.Replace(c.Desc(true, 8, 12), "Deprecated, ", "", 1)
			desc = "Deprecated: " + strings.ToUpper(desc[0:1]) + desc[1:]
		}
		if desc != "" {
			desc = "\n\t//\n\t// " + desc
		}
		if c.Experimental {
			desc += "\n\t//\n\t// Note: This command is experimental."
		}
		g.Printf("\n\t// Command %s%s\n\t%s(context.Context%s) %s\n", c.Name(), desc, c.Name(), request, reply)
	}
	for _, e := range d.Events {
		eventClient := fmt.Sprintf("%sClient", e.EventName(d))
		desc := e.Desc(true, 8, 0)
		if e.Deprecated {
			desc = strings.Replace(e.Desc(true, 8, 12), "Deprecated, ", "", 1)
			desc = "Deprecated: " + strings.ToUpper(desc[0:1]) + desc[1:]
		}
		if desc != "" {
			desc = "\n\t//\n\t// " + desc
		}
		if e.Experimental {
			desc += "\n//\n// Note: This event is experimental."
		}
		g.Printf("\n\t// Event %s%s\n\t%s(context.Context) (%s.%s, error)\n", e.Name(), desc, e.Name(), strings.ToLower(d.Name()), eventClient)
	}
	g.Printf("}\n")
}
1038536
func Domain(s string) string {
	l := strings.Split(s, "/")
	// start with 1, to strip /skydns
	for i, j := 1, len(l)-1; i < j; i, j = i+1, j-1 {
		l[i], l[j] = l[j], l[i]
	}
	return dnsutil.Join(l[1 : len(l)-1]...)
}
653380
func (s *ListWebhookItem) SetDefinition(v *WebhookDefinition) *ListWebhookItem {
	s.Definition = v
	return s
}
725202
func (e *EntityDefinition) FindColumnDefinition(name string) *ColumnDefinition {
	for _, cd := range e.Columns {
		if cd.Name == name {
			return cd
		}
	}
	return nil
}
792178
func (s *GetGroupVersionOutput) SetDefinition(v *GroupVersion) *GetGroupVersionOutput {
	s.Definition = v
	return s
}
651290
func (s *Service) DomainDelete(ctx context.Context, appIdentity string, domainIdentity string) (*Domain, error) {
	var domain Domain
	return &domain, s.Delete(ctx, &domain, fmt.Sprintf("/apps/%v/domains/%v", appIdentity, domainIdentity))
}
1222019
func (f *RelationalFieldDefinition) FieldDefinition() string {
	var comment string
	if f.Description != "" {
		comment = "// " + f.Description
	}
	def := fmt.Sprintf("%s\t%s %s %s\n", f.FieldName, goDatatype(f, true), tags(f), comment)
	return def
}
329939
func encodingDefinition() (*design.EncodingDefinition, bool) {
	e, ok := dslengine.CurrentDefinition().(*design.EncodingDefinition)
	if !ok {
		dslengine.IncompatibleDSL()
	}
	return e, ok
}
622043
func (inv *Investigate) DomainTags(domain string) ([]DomainTag, error) {
	var resp []DomainTag
	err := inv.GetParse(fmt.Sprintf(urls["tags"], domain), &resp)
	if err != nil {
		return nil, err
	}
	return resp, nil
}
1200473
func IsDefinition(s spec.Schema) bool {
	return len(s.SchemaProps.Ref.GetPointer().String()) > 0
}