forked from chromedp/pdlgen
/
domainuse.qtpl
49 lines (47 loc) · 1.98 KB
/
domainuse.qtpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
{% import (
"github.com/chromedp/cdproto-gen/gen/genutil"
"github.com/chromedp/cdproto-gen/pdl"
"strings"
) %}
// DomainTemplate is the template for a single domain file.
{% func DomainTemplate(d *pdl.Domain, domains []*pdl.Domain) %}
// {%s= d.Domain.String() %} executes a cdproto command under {%s= d.Domain.String() %} domain.
type {%s= d.Domain.String() %} struct {
ctxWithExecutor context.Context
}
{% for _, c := range d.Commands %}
{%s= CommandTemplate(c, d, domains) %}
{% endfor %}
{% endfunc %}
// CommandTemplate defines a single command.
{% func CommandTemplate(c *pdl.Type, d *pdl.Domain, domains []*pdl.Domain) %}{% code
domainName := d.Domain.String()
packageName := strings.ToLower(domainName)
cmdName := CamelName(c)
hasEmptyRet := len(c.Returns) == 0
retTypeList := RetTypeList(c, d, domains)
if retTypeList != "" {
retTypeList += ", "
}
%}
{%s= genutil.FormatComment(c.Description, "", cmdName + " ") %}
//
// See: {%s= DocRefLink(c) %}{% if len(c.Parameters) > 0 %}
//
// parameters:{% for _, p := range c.Parameters %}
// - {%s= ParamDesc(p) %}{% endfor %}{% endif %}{% if !hasEmptyRet %}
//
// returns:{% for _, p := range c.Returns %}{% if p.Name == Base64EncodedParamName %}{% continue %}{% endif %}
// - {%s= RetParamDesc(p) %}{% endfor %}{% endif %}
func (do{%s= domainName %} {%s= domainName %}) {%s= cmdName %}({%s= ParamList(c, d, domains, true) %}) ({%s= retTypeList %}err error) {
b := {%s= packageName %}.{%s= cmdName %}({%s= ArgList(c, d, domains, false) %}){%if len(c.Parameters) != 0
%}{% for _, p := range c.Parameters %}{% if !p.Optional %}{% continue %}{% endif %}{% code
optName := OptionFuncPrefix + GoName(p, false) + OptionFuncSuffix
v := strings.TrimSpace(GoName(p, true))
%}
if {%s= v %} != nil {
b = b.{%s= optName %}{% if IsTypeOriginallyNilable(p, d, domains) %}({%s= v %}){% else %}(*{%s= v %}){% endif %}
}{% endfor %}{% endif %}
return b.Do(do{%s= domainName %}.ctxWithExecutor)
}
{% endfunc %}