id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
10,400 | sethvargo/go-fastly | fastly/waf.go | ListWAFs | func (c *Client) ListWAFs(i *ListWAFsInput) ([]*WAF, error) {
if i.Service == "" {
return nil, ErrMissingService
}
if i.Version == 0 {
return nil, ErrMissingVersion
}
path := fmt.Sprintf("/service/%s/version/%d/wafs", i.Service, i.Version)
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
}
data, err := jsonapi.UnmarshalManyPayload(resp.Body, wafType)
if err != nil {
return nil, err
}
wafs := make([]*WAF, len(data))
for i := range data {
typed, ok := data[i].(*WAF)
if !ok {
return nil, fmt.Errorf("got back a non-WAF response")
}
wafs[i] = typed
}
return wafs, nil
} | go | func (c *Client) ListWAFs(i *ListWAFsInput) ([]*WAF, error) {
if i.Service == "" {
return nil, ErrMissingService
}
if i.Version == 0 {
return nil, ErrMissingVersion
}
path := fmt.Sprintf("/service/%s/version/%d/wafs", i.Service, i.Version)
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
}
data, err := jsonapi.UnmarshalManyPayload(resp.Body, wafType)
if err != nil {
return nil, err
}
wafs := make([]*WAF, len(data))
for i := range data {
typed, ok := data[i].(*WAF)
if !ok {
return nil, fmt.Errorf("got back a non-WAF response")
}
wafs[i] = typed
}
return wafs, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ListWAFs",
"(",
"i",
"*",
"ListWAFsInput",
")",
"(",
"[",
"]",
"*",
"WAF",
",",
"error",
")",
"{",
"if",
"i",
".",
"Service",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"ErrMissingService",
"\n",
"}",
"\n\n",
"if",
"i",
".",
"Version",
"==",
"0",
"{",
"return",
"nil",
",",
"ErrMissingVersion",
"\n",
"}",
"\n\n",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
".",
"Service",
",",
"i",
".",
"Version",
")",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"Get",
"(",
"path",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"data",
",",
"err",
":=",
"jsonapi",
".",
"UnmarshalManyPayload",
"(",
"resp",
".",
"Body",
",",
"wafType",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"wafs",
":=",
"make",
"(",
"[",
"]",
"*",
"WAF",
",",
"len",
"(",
"data",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"data",
"{",
"typed",
",",
"ok",
":=",
"data",
"[",
"i",
"]",
".",
"(",
"*",
"WAF",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"wafs",
"[",
"i",
"]",
"=",
"typed",
"\n",
"}",
"\n",
"return",
"wafs",
",",
"nil",
"\n",
"}"
] | // ListWAFs returns the list of wafs for the configuration version. | [
"ListWAFs",
"returns",
"the",
"list",
"of",
"wafs",
"for",
"the",
"configuration",
"version",
"."
] | f249287bd4fda366a7f324f45a2308e934198464 | https://github.com/sethvargo/go-fastly/blob/f249287bd4fda366a7f324f45a2308e934198464/fastly/waf.go#L48-L77 |
10,401 | sethvargo/go-fastly | fastly/waf.go | CreateWAF | func (c *Client) CreateWAF(i *CreateWAFInput) (*WAF, error) {
if i.Service == "" {
return nil, ErrMissingService
}
if i.Version == 0 {
return nil, ErrMissingVersion
}
path := fmt.Sprintf("/service/%s/version/%d/wafs", i.Service, i.Version)
resp, err := c.PostJSONAPI(path, i, nil)
if err != nil {
return nil, err
}
var waf WAF
if err := jsonapi.UnmarshalPayload(resp.Body, &waf); err != nil {
return nil, err
}
return &waf, nil
} | go | func (c *Client) CreateWAF(i *CreateWAFInput) (*WAF, error) {
if i.Service == "" {
return nil, ErrMissingService
}
if i.Version == 0 {
return nil, ErrMissingVersion
}
path := fmt.Sprintf("/service/%s/version/%d/wafs", i.Service, i.Version)
resp, err := c.PostJSONAPI(path, i, nil)
if err != nil {
return nil, err
}
var waf WAF
if err := jsonapi.UnmarshalPayload(resp.Body, &waf); err != nil {
return nil, err
}
return &waf, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"CreateWAF",
"(",
"i",
"*",
"CreateWAFInput",
")",
"(",
"*",
"WAF",
",",
"error",
")",
"{",
"if",
"i",
".",
"Service",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"ErrMissingService",
"\n",
"}",
"\n\n",
"if",
"i",
".",
"Version",
"==",
"0",
"{",
"return",
"nil",
",",
"ErrMissingVersion",
"\n",
"}",
"\n\n",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
".",
"Service",
",",
"i",
".",
"Version",
")",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"PostJSONAPI",
"(",
"path",
",",
"i",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"waf",
"WAF",
"\n",
"if",
"err",
":=",
"jsonapi",
".",
"UnmarshalPayload",
"(",
"resp",
".",
"Body",
",",
"&",
"waf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"waf",
",",
"nil",
"\n",
"}"
] | // CreateWAF creates a new Fastly WAF. | [
"CreateWAF",
"creates",
"a",
"new",
"Fastly",
"WAF",
"."
] | f249287bd4fda366a7f324f45a2308e934198464 | https://github.com/sethvargo/go-fastly/blob/f249287bd4fda366a7f324f45a2308e934198464/fastly/waf.go#L92-L112 |
10,402 | sethvargo/go-fastly | fastly/waf.go | UpdateWAF | func (c *Client) UpdateWAF(i *UpdateWAFInput) (*WAF, error) {
if i.Service == "" {
return nil, ErrMissingService
}
if i.Version == 0 {
return nil, ErrMissingVersion
}
if i.ID == "" {
return nil, ErrMissingWAFID
}
path := fmt.Sprintf("/service/%s/version/%d/wafs/%s", i.Service, i.Version, i.ID)
resp, err := c.PatchJSONAPI(path, i, nil)
if err != nil {
return nil, err
}
var waf WAF
if err := jsonapi.UnmarshalPayload(resp.Body, &waf); err != nil {
return nil, err
}
return &waf, nil
} | go | func (c *Client) UpdateWAF(i *UpdateWAFInput) (*WAF, error) {
if i.Service == "" {
return nil, ErrMissingService
}
if i.Version == 0 {
return nil, ErrMissingVersion
}
if i.ID == "" {
return nil, ErrMissingWAFID
}
path := fmt.Sprintf("/service/%s/version/%d/wafs/%s", i.Service, i.Version, i.ID)
resp, err := c.PatchJSONAPI(path, i, nil)
if err != nil {
return nil, err
}
var waf WAF
if err := jsonapi.UnmarshalPayload(resp.Body, &waf); err != nil {
return nil, err
}
return &waf, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"UpdateWAF",
"(",
"i",
"*",
"UpdateWAFInput",
")",
"(",
"*",
"WAF",
",",
"error",
")",
"{",
"if",
"i",
".",
"Service",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"ErrMissingService",
"\n",
"}",
"\n\n",
"if",
"i",
".",
"Version",
"==",
"0",
"{",
"return",
"nil",
",",
"ErrMissingVersion",
"\n",
"}",
"\n\n",
"if",
"i",
".",
"ID",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"ErrMissingWAFID",
"\n",
"}",
"\n\n",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
".",
"Service",
",",
"i",
".",
"Version",
",",
"i",
".",
"ID",
")",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"PatchJSONAPI",
"(",
"path",
",",
"i",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"waf",
"WAF",
"\n",
"if",
"err",
":=",
"jsonapi",
".",
"UnmarshalPayload",
"(",
"resp",
".",
"Body",
",",
"&",
"waf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"waf",
",",
"nil",
"\n",
"}"
] | // UpdateWAF updates a specific WAF. | [
"UpdateWAF",
"updates",
"a",
"specific",
"WAF",
"."
] | f249287bd4fda366a7f324f45a2308e934198464 | https://github.com/sethvargo/go-fastly/blob/f249287bd4fda366a7f324f45a2308e934198464/fastly/waf.go#L164-L188 |
10,403 | sethvargo/go-fastly | fastly/waf.go | GetOWASP | func (c *Client) GetOWASP(i *GetOWASPInput) (*OWASP, error) {
if i.Service == "" {
return nil, ErrMissingService
}
if i.ID == "" {
return nil, ErrMissingWAFID
}
path := fmt.Sprintf("/service/%s/wafs/%s/owasp", i.Service, i.ID)
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
}
var owasp OWASP
if err := jsonapi.UnmarshalPayload(resp.Body, &owasp); err != nil {
return nil, err
}
return &owasp, nil
} | go | func (c *Client) GetOWASP(i *GetOWASPInput) (*OWASP, error) {
if i.Service == "" {
return nil, ErrMissingService
}
if i.ID == "" {
return nil, ErrMissingWAFID
}
path := fmt.Sprintf("/service/%s/wafs/%s/owasp", i.Service, i.ID)
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
}
var owasp OWASP
if err := jsonapi.UnmarshalPayload(resp.Body, &owasp); err != nil {
return nil, err
}
return &owasp, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetOWASP",
"(",
"i",
"*",
"GetOWASPInput",
")",
"(",
"*",
"OWASP",
",",
"error",
")",
"{",
"if",
"i",
".",
"Service",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"ErrMissingService",
"\n",
"}",
"\n\n",
"if",
"i",
".",
"ID",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"ErrMissingWAFID",
"\n",
"}",
"\n\n",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
".",
"Service",
",",
"i",
".",
"ID",
")",
"\n\n",
"resp",
",",
"err",
":=",
"c",
".",
"Get",
"(",
"path",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"owasp",
"OWASP",
"\n",
"if",
"err",
":=",
"jsonapi",
".",
"UnmarshalPayload",
"(",
"resp",
".",
"Body",
",",
"&",
"owasp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"owasp",
",",
"nil",
"\n",
"}"
] | // GetOWASP gets OWASP settings for a service firewall object. | [
"GetOWASP",
"gets",
"OWASP",
"settings",
"for",
"a",
"service",
"firewall",
"object",
"."
] | f249287bd4fda366a7f324f45a2308e934198464 | https://github.com/sethvargo/go-fastly/blob/f249287bd4fda366a7f324f45a2308e934198464/fastly/waf.go#L263-L284 |
10,404 | sethvargo/go-fastly | fastly/waf.go | GetRules | func (c *Client) GetRules() ([]*Rule, error) {
path := fmt.Sprintf("/wafs/rules")
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
}
data, err := jsonapi.UnmarshalManyPayload(resp.Body, rulesType)
if err != nil {
return nil, err
}
rules := make([]*Rule, len(data))
for i := range data {
typed, ok := data[i].(*Rule)
if !ok {
return nil, fmt.Errorf("got back a non-Rules response")
}
rules[i] = typed
}
return rules, nil
} | go | func (c *Client) GetRules() ([]*Rule, error) {
path := fmt.Sprintf("/wafs/rules")
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
}
data, err := jsonapi.UnmarshalManyPayload(resp.Body, rulesType)
if err != nil {
return nil, err
}
rules := make([]*Rule, len(data))
for i := range data {
typed, ok := data[i].(*Rule)
if !ok {
return nil, fmt.Errorf("got back a non-Rules response")
}
rules[i] = typed
}
return rules, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetRules",
"(",
")",
"(",
"[",
"]",
"*",
"Rule",
",",
"error",
")",
"{",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
")",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"Get",
"(",
"path",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"data",
",",
"err",
":=",
"jsonapi",
".",
"UnmarshalManyPayload",
"(",
"resp",
".",
"Body",
",",
"rulesType",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"rules",
":=",
"make",
"(",
"[",
"]",
"*",
"Rule",
",",
"len",
"(",
"data",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"data",
"{",
"typed",
",",
"ok",
":=",
"data",
"[",
"i",
"]",
".",
"(",
"*",
"Rule",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"rules",
"[",
"i",
"]",
"=",
"typed",
"\n",
"}",
"\n\n",
"return",
"rules",
",",
"nil",
"\n",
"}"
] | // GetRules returns the list of wafs for the configuration version. | [
"GetRules",
"returns",
"the",
"list",
"of",
"wafs",
"for",
"the",
"configuration",
"version",
"."
] | f249287bd4fda366a7f324f45a2308e934198464 | https://github.com/sethvargo/go-fastly/blob/f249287bd4fda366a7f324f45a2308e934198464/fastly/waf.go#L399-L421 |
10,405 | sethvargo/go-fastly | fastly/waf.go | GetRule | func (c *Client) GetRule(i *GetRuleInput) (*Rule, error) {
if i.RuleID == "" {
return nil, ErrMissingRuleID
}
path := fmt.Sprintf("/wafs/rules/%s", i.RuleID)
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
}
var rule Rule
if err := jsonapi.UnmarshalPayload(resp.Body, &rule); err != nil {
return nil, err
}
return &rule, nil
} | go | func (c *Client) GetRule(i *GetRuleInput) (*Rule, error) {
if i.RuleID == "" {
return nil, ErrMissingRuleID
}
path := fmt.Sprintf("/wafs/rules/%s", i.RuleID)
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
}
var rule Rule
if err := jsonapi.UnmarshalPayload(resp.Body, &rule); err != nil {
return nil, err
}
return &rule, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetRule",
"(",
"i",
"*",
"GetRuleInput",
")",
"(",
"*",
"Rule",
",",
"error",
")",
"{",
"if",
"i",
".",
"RuleID",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"ErrMissingRuleID",
"\n",
"}",
"\n\n",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
".",
"RuleID",
")",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"Get",
"(",
"path",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"rule",
"Rule",
"\n",
"if",
"err",
":=",
"jsonapi",
".",
"UnmarshalPayload",
"(",
"resp",
".",
"Body",
",",
"&",
"rule",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"rule",
",",
"nil",
"\n",
"}"
] | // GetRule gets a Rule using the Rule ID. | [
"GetRule",
"gets",
"a",
"Rule",
"using",
"the",
"Rule",
"ID",
"."
] | f249287bd4fda366a7f324f45a2308e934198464 | https://github.com/sethvargo/go-fastly/blob/f249287bd4fda366a7f324f45a2308e934198464/fastly/waf.go#L430-L446 |
10,406 | sethvargo/go-fastly | fastly/waf.go | GetRuleVCL | func (c *Client) GetRuleVCL(i *GetRuleInput) (*RuleVCL, error) {
if i.RuleID == "" {
return nil, ErrMissingRuleID
}
path := fmt.Sprintf("/wafs/rules/%s/vcl", i.RuleID)
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
}
var vcl RuleVCL
if err := jsonapi.UnmarshalPayload(resp.Body, &vcl); err != nil {
return nil, err
}
return &vcl, nil
} | go | func (c *Client) GetRuleVCL(i *GetRuleInput) (*RuleVCL, error) {
if i.RuleID == "" {
return nil, ErrMissingRuleID
}
path := fmt.Sprintf("/wafs/rules/%s/vcl", i.RuleID)
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
}
var vcl RuleVCL
if err := jsonapi.UnmarshalPayload(resp.Body, &vcl); err != nil {
return nil, err
}
return &vcl, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetRuleVCL",
"(",
"i",
"*",
"GetRuleInput",
")",
"(",
"*",
"RuleVCL",
",",
"error",
")",
"{",
"if",
"i",
".",
"RuleID",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"ErrMissingRuleID",
"\n",
"}",
"\n\n",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
".",
"RuleID",
")",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"Get",
"(",
"path",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"vcl",
"RuleVCL",
"\n",
"if",
"err",
":=",
"jsonapi",
".",
"UnmarshalPayload",
"(",
"resp",
".",
"Body",
",",
"&",
"vcl",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"vcl",
",",
"nil",
"\n",
"}"
] | // GetRuleVCL gets the VCL for a Rule. | [
"GetRuleVCL",
"gets",
"the",
"VCL",
"for",
"a",
"Rule",
"."
] | f249287bd4fda366a7f324f45a2308e934198464 | https://github.com/sethvargo/go-fastly/blob/f249287bd4fda366a7f324f45a2308e934198464/fastly/waf.go#L455-L471 |
10,407 | sethvargo/go-fastly | fastly/waf.go | GetWAFRuleVCL | func (c *Client) GetWAFRuleVCL(i *GetWAFRuleVCLInput) (*RuleVCL, error) {
if i.ID == "" {
return nil, ErrMissingWAFID
}
if i.RuleID == "" {
return nil, ErrMissingRuleID
}
path := fmt.Sprintf("/wafs/%s/rules/%s/vcl", i.ID, i.RuleID)
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
}
var vcl RuleVCL
if err := jsonapi.UnmarshalPayload(resp.Body, &vcl); err != nil {
return nil, err
}
return &vcl, nil
} | go | func (c *Client) GetWAFRuleVCL(i *GetWAFRuleVCLInput) (*RuleVCL, error) {
if i.ID == "" {
return nil, ErrMissingWAFID
}
if i.RuleID == "" {
return nil, ErrMissingRuleID
}
path := fmt.Sprintf("/wafs/%s/rules/%s/vcl", i.ID, i.RuleID)
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
}
var vcl RuleVCL
if err := jsonapi.UnmarshalPayload(resp.Body, &vcl); err != nil {
return nil, err
}
return &vcl, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetWAFRuleVCL",
"(",
"i",
"*",
"GetWAFRuleVCLInput",
")",
"(",
"*",
"RuleVCL",
",",
"error",
")",
"{",
"if",
"i",
".",
"ID",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"ErrMissingWAFID",
"\n",
"}",
"\n\n",
"if",
"i",
".",
"RuleID",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"ErrMissingRuleID",
"\n",
"}",
"\n\n",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
".",
"ID",
",",
"i",
".",
"RuleID",
")",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"Get",
"(",
"path",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"vcl",
"RuleVCL",
"\n",
"if",
"err",
":=",
"jsonapi",
".",
"UnmarshalPayload",
"(",
"resp",
".",
"Body",
",",
"&",
"vcl",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"vcl",
",",
"nil",
"\n",
"}"
] | // GetWAFRuleVCL gets the VCL for a role associated with a firewall WAF. | [
"GetWAFRuleVCL",
"gets",
"the",
"VCL",
"for",
"a",
"role",
"associated",
"with",
"a",
"firewall",
"WAF",
"."
] | f249287bd4fda366a7f324f45a2308e934198464 | https://github.com/sethvargo/go-fastly/blob/f249287bd4fda366a7f324f45a2308e934198464/fastly/waf.go#L482-L502 |
10,408 | sethvargo/go-fastly | fastly/waf.go | GetWAFRuleRuleSets | func (c *Client) GetWAFRuleRuleSets(i *GetWAFRuleRuleSetsInput) (*Ruleset, error) {
if i.Service == "" {
return nil, ErrMissingService
}
if i.ID == "" {
return nil, ErrMissingWAFID
}
path := fmt.Sprintf("/service/%s/wafs/%s/ruleset", i.Service, i.ID)
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
}
var ruleset Ruleset
if err := jsonapi.UnmarshalPayload(resp.Body, &ruleset); err != nil {
return nil, err
}
return &ruleset, nil
} | go | func (c *Client) GetWAFRuleRuleSets(i *GetWAFRuleRuleSetsInput) (*Ruleset, error) {
if i.Service == "" {
return nil, ErrMissingService
}
if i.ID == "" {
return nil, ErrMissingWAFID
}
path := fmt.Sprintf("/service/%s/wafs/%s/ruleset", i.Service, i.ID)
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
}
var ruleset Ruleset
if err := jsonapi.UnmarshalPayload(resp.Body, &ruleset); err != nil {
return nil, err
}
return &ruleset, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetWAFRuleRuleSets",
"(",
"i",
"*",
"GetWAFRuleRuleSetsInput",
")",
"(",
"*",
"Ruleset",
",",
"error",
")",
"{",
"if",
"i",
".",
"Service",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"ErrMissingService",
"\n",
"}",
"\n\n",
"if",
"i",
".",
"ID",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"ErrMissingWAFID",
"\n",
"}",
"\n\n",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
".",
"Service",
",",
"i",
".",
"ID",
")",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"Get",
"(",
"path",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"ruleset",
"Ruleset",
"\n",
"if",
"err",
":=",
"jsonapi",
".",
"UnmarshalPayload",
"(",
"resp",
".",
"Body",
",",
"&",
"ruleset",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"ruleset",
",",
"nil",
"\n",
"}"
] | // GetWAFRuleRuleSets gets the VCL for rulesets associated with a firewall WAF. | [
"GetWAFRuleRuleSets",
"gets",
"the",
"VCL",
"for",
"rulesets",
"associated",
"with",
"a",
"firewall",
"WAF",
"."
] | f249287bd4fda366a7f324f45a2308e934198464 | https://github.com/sethvargo/go-fastly/blob/f249287bd4fda366a7f324f45a2308e934198464/fastly/waf.go#L520-L540 |
10,409 | sethvargo/go-fastly | fastly/waf.go | UpdateWAFRuleSets | func (c *Client) UpdateWAFRuleSets(i *UpdateWAFRuleRuleSetsInput) (*Ruleset, error) {
if i.Service == "" {
return nil, ErrMissingService
}
if i.ID == "" {
return nil, ErrMissingWAFID
}
path := fmt.Sprintf("/service/%s/wafs/%s/ruleset", i.Service, i.ID)
resp, err := c.PatchJSONAPI(path, i, nil)
if err != nil {
return nil, err
}
var ruleset Ruleset
if err := jsonapi.UnmarshalPayload(resp.Body, &ruleset); err != nil {
return nil, err
}
return &ruleset, nil
} | go | func (c *Client) UpdateWAFRuleSets(i *UpdateWAFRuleRuleSetsInput) (*Ruleset, error) {
if i.Service == "" {
return nil, ErrMissingService
}
if i.ID == "" {
return nil, ErrMissingWAFID
}
path := fmt.Sprintf("/service/%s/wafs/%s/ruleset", i.Service, i.ID)
resp, err := c.PatchJSONAPI(path, i, nil)
if err != nil {
return nil, err
}
var ruleset Ruleset
if err := jsonapi.UnmarshalPayload(resp.Body, &ruleset); err != nil {
return nil, err
}
return &ruleset, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"UpdateWAFRuleSets",
"(",
"i",
"*",
"UpdateWAFRuleRuleSetsInput",
")",
"(",
"*",
"Ruleset",
",",
"error",
")",
"{",
"if",
"i",
".",
"Service",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"ErrMissingService",
"\n",
"}",
"\n\n",
"if",
"i",
".",
"ID",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"ErrMissingWAFID",
"\n",
"}",
"\n\n",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
".",
"Service",
",",
"i",
".",
"ID",
")",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"PatchJSONAPI",
"(",
"path",
",",
"i",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"ruleset",
"Ruleset",
"\n",
"if",
"err",
":=",
"jsonapi",
".",
"UnmarshalPayload",
"(",
"resp",
".",
"Body",
",",
"&",
"ruleset",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"ruleset",
",",
"nil",
"\n",
"}"
] | // UpdateWAFRuleSets updates the rulesets for a role associated with a firewall WAF. | [
"UpdateWAFRuleSets",
"updates",
"the",
"rulesets",
"for",
"a",
"role",
"associated",
"with",
"a",
"firewall",
"WAF",
"."
] | f249287bd4fda366a7f324f45a2308e934198464 | https://github.com/sethvargo/go-fastly/blob/f249287bd4fda366a7f324f45a2308e934198464/fastly/waf.go#L551-L571 |
10,410 | sethvargo/go-fastly | fastly/waf.go | formatFilters | func (i *GetWAFRuleStatusesInput) formatFilters() map[string]string {
input := i.Filters
result := map[string]string{}
pairings := map[string]interface{}{
"filter[status]": input.Status,
"filter[rule][accuracy]": input.Accuracy,
"filter[rule][maturity]": input.Maturity,
"filter[rule][message]": input.Message,
"filter[rule][revision]": input.Revision,
"filter[rule][rule_id]": input.RuleID,
"filter[rule][tags]": input.TagID,
"filter[rule][tags][name]": input.TagName,
"filter[rule][version]": input.Version,
"include": input.Tags,
"page[size]": input.MaxResults,
"page[number]": input.Page, // starts at 1, not 0
}
// NOTE: This setup means we will not be able to send the zero value
// of any of these filters. It doesn't appear we would need to at present.
for key, value := range pairings {
switch t := reflect.TypeOf(value).String(); t {
case "string":
if value != "" {
result[key] = value.(string)
}
case "int":
if value != 0 {
result[key] = strconv.Itoa(value.(int))
}
case "[]int":
// convert ints to strings
toStrings := []string{}
values := value.([]int)
for _, i := range values {
toStrings = append(toStrings, strconv.Itoa(i))
}
// concat strings
if len(values) > 0 {
result[key] = strings.Join(toStrings, ",")
}
}
}
return result
} | go | func (i *GetWAFRuleStatusesInput) formatFilters() map[string]string {
input := i.Filters
result := map[string]string{}
pairings := map[string]interface{}{
"filter[status]": input.Status,
"filter[rule][accuracy]": input.Accuracy,
"filter[rule][maturity]": input.Maturity,
"filter[rule][message]": input.Message,
"filter[rule][revision]": input.Revision,
"filter[rule][rule_id]": input.RuleID,
"filter[rule][tags]": input.TagID,
"filter[rule][tags][name]": input.TagName,
"filter[rule][version]": input.Version,
"include": input.Tags,
"page[size]": input.MaxResults,
"page[number]": input.Page, // starts at 1, not 0
}
// NOTE: This setup means we will not be able to send the zero value
// of any of these filters. It doesn't appear we would need to at present.
for key, value := range pairings {
switch t := reflect.TypeOf(value).String(); t {
case "string":
if value != "" {
result[key] = value.(string)
}
case "int":
if value != 0 {
result[key] = strconv.Itoa(value.(int))
}
case "[]int":
// convert ints to strings
toStrings := []string{}
values := value.([]int)
for _, i := range values {
toStrings = append(toStrings, strconv.Itoa(i))
}
// concat strings
if len(values) > 0 {
result[key] = strings.Join(toStrings, ",")
}
}
}
return result
} | [
"func",
"(",
"i",
"*",
"GetWAFRuleStatusesInput",
")",
"formatFilters",
"(",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"input",
":=",
"i",
".",
"Filters",
"\n",
"result",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
"\n",
"pairings",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"input",
".",
"Status",
",",
"\"",
"\"",
":",
"input",
".",
"Accuracy",
",",
"\"",
"\"",
":",
"input",
".",
"Maturity",
",",
"\"",
"\"",
":",
"input",
".",
"Message",
",",
"\"",
"\"",
":",
"input",
".",
"Revision",
",",
"\"",
"\"",
":",
"input",
".",
"RuleID",
",",
"\"",
"\"",
":",
"input",
".",
"TagID",
",",
"\"",
"\"",
":",
"input",
".",
"TagName",
",",
"\"",
"\"",
":",
"input",
".",
"Version",
",",
"\"",
"\"",
":",
"input",
".",
"Tags",
",",
"\"",
"\"",
":",
"input",
".",
"MaxResults",
",",
"\"",
"\"",
":",
"input",
".",
"Page",
",",
"// starts at 1, not 0",
"}",
"\n",
"// NOTE: This setup means we will not be able to send the zero value",
"// of any of these filters. It doesn't appear we would need to at present.",
"for",
"key",
",",
"value",
":=",
"range",
"pairings",
"{",
"switch",
"t",
":=",
"reflect",
".",
"TypeOf",
"(",
"value",
")",
".",
"String",
"(",
")",
";",
"t",
"{",
"case",
"\"",
"\"",
":",
"if",
"value",
"!=",
"\"",
"\"",
"{",
"result",
"[",
"key",
"]",
"=",
"value",
".",
"(",
"string",
")",
"\n",
"}",
"\n",
"case",
"\"",
"\"",
":",
"if",
"value",
"!=",
"0",
"{",
"result",
"[",
"key",
"]",
"=",
"strconv",
".",
"Itoa",
"(",
"value",
".",
"(",
"int",
")",
")",
"\n",
"}",
"\n",
"case",
"\"",
"\"",
":",
"// convert ints to strings",
"toStrings",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"values",
":=",
"value",
".",
"(",
"[",
"]",
"int",
")",
"\n",
"for",
"_",
",",
"i",
":=",
"range",
"values",
"{",
"toStrings",
"=",
"append",
"(",
"toStrings",
",",
"strconv",
".",
"Itoa",
"(",
"i",
")",
")",
"\n",
"}",
"\n",
"// concat strings",
"if",
"len",
"(",
"values",
")",
">",
"0",
"{",
"result",
"[",
"key",
"]",
"=",
"strings",
".",
"Join",
"(",
"toStrings",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // formatFilters converts user input into query parameters for filtering
// Fastly results for rules in a WAF. | [
"formatFilters",
"converts",
"user",
"input",
"into",
"query",
"parameters",
"for",
"filtering",
"Fastly",
"results",
"for",
"rules",
"in",
"a",
"WAF",
"."
] | f249287bd4fda366a7f324f45a2308e934198464 | https://github.com/sethvargo/go-fastly/blob/f249287bd4fda366a7f324f45a2308e934198464/fastly/waf.go#L614-L657 |
10,411 | sethvargo/go-fastly | fastly/waf.go | GetWAFRuleStatuses | func (c *Client) GetWAFRuleStatuses(i *GetWAFRuleStatusesInput) (GetWAFRuleStatusesResponse, error) {
statusResponse := GetWAFRuleStatusesResponse{Rules: []*WAFRuleStatus{}}
if i.Service == "" {
return statusResponse, ErrMissingService
}
if i.WAF == "" {
return statusResponse, ErrMissingWAFID
}
path := fmt.Sprintf("/service/%s/wafs/%s/rule_statuses", i.Service, i.WAF)
filters := &RequestOptions{Params: i.formatFilters()}
resp, err := c.Get(path, filters)
if err != nil {
return statusResponse, err
}
err = c.interpretWAFRuleStatusesPage(&statusResponse, resp)
// NOTE: It's possible for statusResponse to be partially completed before an error
// was encountered, so the presence of a statusResponse doesn't preclude the presence of
// an error.
return statusResponse, err
} | go | func (c *Client) GetWAFRuleStatuses(i *GetWAFRuleStatusesInput) (GetWAFRuleStatusesResponse, error) {
statusResponse := GetWAFRuleStatusesResponse{Rules: []*WAFRuleStatus{}}
if i.Service == "" {
return statusResponse, ErrMissingService
}
if i.WAF == "" {
return statusResponse, ErrMissingWAFID
}
path := fmt.Sprintf("/service/%s/wafs/%s/rule_statuses", i.Service, i.WAF)
filters := &RequestOptions{Params: i.formatFilters()}
resp, err := c.Get(path, filters)
if err != nil {
return statusResponse, err
}
err = c.interpretWAFRuleStatusesPage(&statusResponse, resp)
// NOTE: It's possible for statusResponse to be partially completed before an error
// was encountered, so the presence of a statusResponse doesn't preclude the presence of
// an error.
return statusResponse, err
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetWAFRuleStatuses",
"(",
"i",
"*",
"GetWAFRuleStatusesInput",
")",
"(",
"GetWAFRuleStatusesResponse",
",",
"error",
")",
"{",
"statusResponse",
":=",
"GetWAFRuleStatusesResponse",
"{",
"Rules",
":",
"[",
"]",
"*",
"WAFRuleStatus",
"{",
"}",
"}",
"\n",
"if",
"i",
".",
"Service",
"==",
"\"",
"\"",
"{",
"return",
"statusResponse",
",",
"ErrMissingService",
"\n",
"}",
"\n",
"if",
"i",
".",
"WAF",
"==",
"\"",
"\"",
"{",
"return",
"statusResponse",
",",
"ErrMissingWAFID",
"\n",
"}",
"\n\n",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
".",
"Service",
",",
"i",
".",
"WAF",
")",
"\n",
"filters",
":=",
"&",
"RequestOptions",
"{",
"Params",
":",
"i",
".",
"formatFilters",
"(",
")",
"}",
"\n\n",
"resp",
",",
"err",
":=",
"c",
".",
"Get",
"(",
"path",
",",
"filters",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"statusResponse",
",",
"err",
"\n",
"}",
"\n",
"err",
"=",
"c",
".",
"interpretWAFRuleStatusesPage",
"(",
"&",
"statusResponse",
",",
"resp",
")",
"\n",
"// NOTE: It's possible for statusResponse to be partially completed before an error",
"// was encountered, so the presence of a statusResponse doesn't preclude the presence of",
"// an error.",
"return",
"statusResponse",
",",
"err",
"\n",
"}"
] | // GetWAFRuleStatuses fetches the status of a subset of rules associated with a WAF. | [
"GetWAFRuleStatuses",
"fetches",
"the",
"status",
"of",
"a",
"subset",
"of",
"rules",
"associated",
"with",
"a",
"WAF",
"."
] | f249287bd4fda366a7f324f45a2308e934198464 | https://github.com/sethvargo/go-fastly/blob/f249287bd4fda366a7f324f45a2308e934198464/fastly/waf.go#L660-L681 |
10,412 | sethvargo/go-fastly | fastly/waf.go | interpretWAFRuleStatusesPage | func (c *Client) interpretWAFRuleStatusesPage(answer *GetWAFRuleStatusesResponse, received *http.Response) error {
// before we pull the status info out of the response body, fetch
// pagination info from it:
pages, body, err := getPages(received.Body)
if err != nil {
return err
}
data, err := jsonapi.UnmarshalManyPayload(body, reflect.TypeOf(new(WAFRuleStatus)))
if err != nil {
return err
}
for i := range data {
typed, ok := data[i].(*WAFRuleStatus)
if !ok {
return fmt.Errorf("got back response of unexpected type")
}
answer.Rules = append(answer.Rules, typed)
}
if pages.Next != "" {
// NOTE: pages.Next URL includes filters already
resp, err := c.SimpleGet(pages.Next)
if err != nil {
return err
}
c.interpretWAFRuleStatusesPage(answer, resp)
}
return nil
} | go | func (c *Client) interpretWAFRuleStatusesPage(answer *GetWAFRuleStatusesResponse, received *http.Response) error {
// before we pull the status info out of the response body, fetch
// pagination info from it:
pages, body, err := getPages(received.Body)
if err != nil {
return err
}
data, err := jsonapi.UnmarshalManyPayload(body, reflect.TypeOf(new(WAFRuleStatus)))
if err != nil {
return err
}
for i := range data {
typed, ok := data[i].(*WAFRuleStatus)
if !ok {
return fmt.Errorf("got back response of unexpected type")
}
answer.Rules = append(answer.Rules, typed)
}
if pages.Next != "" {
// NOTE: pages.Next URL includes filters already
resp, err := c.SimpleGet(pages.Next)
if err != nil {
return err
}
c.interpretWAFRuleStatusesPage(answer, resp)
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"interpretWAFRuleStatusesPage",
"(",
"answer",
"*",
"GetWAFRuleStatusesResponse",
",",
"received",
"*",
"http",
".",
"Response",
")",
"error",
"{",
"// before we pull the status info out of the response body, fetch",
"// pagination info from it:",
"pages",
",",
"body",
",",
"err",
":=",
"getPages",
"(",
"received",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"data",
",",
"err",
":=",
"jsonapi",
".",
"UnmarshalManyPayload",
"(",
"body",
",",
"reflect",
".",
"TypeOf",
"(",
"new",
"(",
"WAFRuleStatus",
")",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"range",
"data",
"{",
"typed",
",",
"ok",
":=",
"data",
"[",
"i",
"]",
".",
"(",
"*",
"WAFRuleStatus",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"answer",
".",
"Rules",
"=",
"append",
"(",
"answer",
".",
"Rules",
",",
"typed",
")",
"\n",
"}",
"\n",
"if",
"pages",
".",
"Next",
"!=",
"\"",
"\"",
"{",
"// NOTE: pages.Next URL includes filters already",
"resp",
",",
"err",
":=",
"c",
".",
"SimpleGet",
"(",
"pages",
".",
"Next",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"c",
".",
"interpretWAFRuleStatusesPage",
"(",
"answer",
",",
"resp",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // interpretWAFRuleStatusesPage accepts a Fastly response for a set of WAF rule statuses
// and unmarshals the results. If there are more pages of results, it fetches the next
// page, adds that response to the array of results, and repeats until all results have
// been fetched. | [
"interpretWAFRuleStatusesPage",
"accepts",
"a",
"Fastly",
"response",
"for",
"a",
"set",
"of",
"WAF",
"rule",
"statuses",
"and",
"unmarshals",
"the",
"results",
".",
"If",
"there",
"are",
"more",
"pages",
"of",
"results",
"it",
"fetches",
"the",
"next",
"page",
"adds",
"that",
"response",
"to",
"the",
"array",
"of",
"results",
"and",
"repeats",
"until",
"all",
"results",
"have",
"been",
"fetched",
"."
] | f249287bd4fda366a7f324f45a2308e934198464 | https://github.com/sethvargo/go-fastly/blob/f249287bd4fda366a7f324f45a2308e934198464/fastly/waf.go#L687-L715 |
10,413 | sethvargo/go-fastly | fastly/waf.go | getPages | func getPages(body io.Reader) (paginationInfo, io.Reader, error) {
var buf bytes.Buffer
tee := io.TeeReader(body, &buf)
bodyBytes, err := ioutil.ReadAll(tee)
if err != nil {
return paginationInfo{}, nil, err
}
var pages linksResponse
json.Unmarshal(bodyBytes, &pages)
return pages.Links, bytes.NewReader(buf.Bytes()), nil
} | go | func getPages(body io.Reader) (paginationInfo, io.Reader, error) {
var buf bytes.Buffer
tee := io.TeeReader(body, &buf)
bodyBytes, err := ioutil.ReadAll(tee)
if err != nil {
return paginationInfo{}, nil, err
}
var pages linksResponse
json.Unmarshal(bodyBytes, &pages)
return pages.Links, bytes.NewReader(buf.Bytes()), nil
} | [
"func",
"getPages",
"(",
"body",
"io",
".",
"Reader",
")",
"(",
"paginationInfo",
",",
"io",
".",
"Reader",
",",
"error",
")",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"tee",
":=",
"io",
".",
"TeeReader",
"(",
"body",
",",
"&",
"buf",
")",
"\n\n",
"bodyBytes",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"tee",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"paginationInfo",
"{",
"}",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"pages",
"linksResponse",
"\n",
"json",
".",
"Unmarshal",
"(",
"bodyBytes",
",",
"&",
"pages",
")",
"\n",
"return",
"pages",
".",
"Links",
",",
"bytes",
".",
"NewReader",
"(",
"buf",
".",
"Bytes",
"(",
")",
")",
",",
"nil",
"\n",
"}"
] | // getPages parses a response to get the pagination data without destroying
// the reader we receive as "resp.Body"; this essentially copies resp.Body
// and returns it so we can use it again. | [
"getPages",
"parses",
"a",
"response",
"to",
"get",
"the",
"pagination",
"data",
"without",
"destroying",
"the",
"reader",
"we",
"receive",
"as",
"resp",
".",
"Body",
";",
"this",
"essentially",
"copies",
"resp",
".",
"Body",
"and",
"returns",
"it",
"so",
"we",
"can",
"use",
"it",
"again",
"."
] | f249287bd4fda366a7f324f45a2308e934198464 | https://github.com/sethvargo/go-fastly/blob/f249287bd4fda366a7f324f45a2308e934198464/fastly/waf.go#L740-L752 |
10,414 | sethvargo/go-fastly | fastly/waf.go | GetWAFRuleStatus | func (c *Client) GetWAFRuleStatus(i *GetWAFRuleStatusInput) (WAFRuleStatus, error) {
if i.ID == 0 {
return WAFRuleStatus{}, ErrMissingRuleID
}
if i.Service == "" {
return WAFRuleStatus{}, ErrMissingService
}
if i.WAF == "" {
return WAFRuleStatus{}, ErrMissingWAFID
}
path := fmt.Sprintf("/service/%s/wafs/%s/rules/%d/rule_status", i.Service, i.WAF, i.ID)
resp, err := c.Get(path, nil)
if err != nil {
return WAFRuleStatus{}, err
}
var status WAFRuleStatus
err = jsonapi.UnmarshalPayload(resp.Body, &status)
return status, err
} | go | func (c *Client) GetWAFRuleStatus(i *GetWAFRuleStatusInput) (WAFRuleStatus, error) {
if i.ID == 0 {
return WAFRuleStatus{}, ErrMissingRuleID
}
if i.Service == "" {
return WAFRuleStatus{}, ErrMissingService
}
if i.WAF == "" {
return WAFRuleStatus{}, ErrMissingWAFID
}
path := fmt.Sprintf("/service/%s/wafs/%s/rules/%d/rule_status", i.Service, i.WAF, i.ID)
resp, err := c.Get(path, nil)
if err != nil {
return WAFRuleStatus{}, err
}
var status WAFRuleStatus
err = jsonapi.UnmarshalPayload(resp.Body, &status)
return status, err
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetWAFRuleStatus",
"(",
"i",
"*",
"GetWAFRuleStatusInput",
")",
"(",
"WAFRuleStatus",
",",
"error",
")",
"{",
"if",
"i",
".",
"ID",
"==",
"0",
"{",
"return",
"WAFRuleStatus",
"{",
"}",
",",
"ErrMissingRuleID",
"\n",
"}",
"\n",
"if",
"i",
".",
"Service",
"==",
"\"",
"\"",
"{",
"return",
"WAFRuleStatus",
"{",
"}",
",",
"ErrMissingService",
"\n",
"}",
"\n",
"if",
"i",
".",
"WAF",
"==",
"\"",
"\"",
"{",
"return",
"WAFRuleStatus",
"{",
"}",
",",
"ErrMissingWAFID",
"\n",
"}",
"\n\n",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
".",
"Service",
",",
"i",
".",
"WAF",
",",
"i",
".",
"ID",
")",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"Get",
"(",
"path",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"WAFRuleStatus",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"status",
"WAFRuleStatus",
"\n",
"err",
"=",
"jsonapi",
".",
"UnmarshalPayload",
"(",
"resp",
".",
"Body",
",",
"&",
"status",
")",
"\n",
"return",
"status",
",",
"err",
"\n",
"}"
] | // GetWAFRuleStatus fetches the status of a single rule associated with a WAF. | [
"GetWAFRuleStatus",
"fetches",
"the",
"status",
"of",
"a",
"single",
"rule",
"associated",
"with",
"a",
"WAF",
"."
] | f249287bd4fda366a7f324f45a2308e934198464 | https://github.com/sethvargo/go-fastly/blob/f249287bd4fda366a7f324f45a2308e934198464/fastly/waf.go#L762-L782 |
10,415 | sethvargo/go-fastly | fastly/waf.go | validate | func (i UpdateWAFRuleStatusInput) validate() error {
if i.ID == "" {
return ErrMissingID
}
if i.RuleID == 0 {
return ErrMissingRuleID
}
if i.Service == "" {
return ErrMissingService
}
if i.WAF == "" {
return ErrMissingWAFID
}
if i.Status == "" {
return ErrMissingStatus
}
return nil
} | go | func (i UpdateWAFRuleStatusInput) validate() error {
if i.ID == "" {
return ErrMissingID
}
if i.RuleID == 0 {
return ErrMissingRuleID
}
if i.Service == "" {
return ErrMissingService
}
if i.WAF == "" {
return ErrMissingWAFID
}
if i.Status == "" {
return ErrMissingStatus
}
return nil
} | [
"func",
"(",
"i",
"UpdateWAFRuleStatusInput",
")",
"validate",
"(",
")",
"error",
"{",
"if",
"i",
".",
"ID",
"==",
"\"",
"\"",
"{",
"return",
"ErrMissingID",
"\n",
"}",
"\n",
"if",
"i",
".",
"RuleID",
"==",
"0",
"{",
"return",
"ErrMissingRuleID",
"\n",
"}",
"\n",
"if",
"i",
".",
"Service",
"==",
"\"",
"\"",
"{",
"return",
"ErrMissingService",
"\n",
"}",
"\n",
"if",
"i",
".",
"WAF",
"==",
"\"",
"\"",
"{",
"return",
"ErrMissingWAFID",
"\n",
"}",
"\n",
"if",
"i",
".",
"Status",
"==",
"\"",
"\"",
"{",
"return",
"ErrMissingStatus",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // validate makes sure the UpdateWAFRuleStatusInput instance has all
// fields we need to request a change. | [
"validate",
"makes",
"sure",
"the",
"UpdateWAFRuleStatusInput",
"instance",
"has",
"all",
"fields",
"we",
"need",
"to",
"request",
"a",
"change",
"."
] | f249287bd4fda366a7f324f45a2308e934198464 | https://github.com/sethvargo/go-fastly/blob/f249287bd4fda366a7f324f45a2308e934198464/fastly/waf.go#L795-L812 |
10,416 | sethvargo/go-fastly | fastly/waf.go | UpdateWAFRuleStatus | func (c *Client) UpdateWAFRuleStatus(i *UpdateWAFRuleStatusInput) (WAFRuleStatus, error) {
if err := i.validate(); err != nil {
return WAFRuleStatus{}, err
}
path := fmt.Sprintf("/service/%s/wafs/%s/rules/%d/rule_status", i.Service, i.WAF, i.RuleID)
var buf bytes.Buffer
err := jsonapi.MarshalPayload(&buf, i)
if err != nil {
return WAFRuleStatus{}, err
}
options := &RequestOptions{
Body: &buf,
Headers: map[string]string{
"Content-Type": jsonapi.MediaType,
"Accept": jsonapi.MediaType,
},
}
resp, err := c.Patch(path, options)
if err != nil {
return WAFRuleStatus{}, err
}
var status WAFRuleStatus
err = jsonapi.UnmarshalPayload(resp.Body, &status)
return status, err
} | go | func (c *Client) UpdateWAFRuleStatus(i *UpdateWAFRuleStatusInput) (WAFRuleStatus, error) {
if err := i.validate(); err != nil {
return WAFRuleStatus{}, err
}
path := fmt.Sprintf("/service/%s/wafs/%s/rules/%d/rule_status", i.Service, i.WAF, i.RuleID)
var buf bytes.Buffer
err := jsonapi.MarshalPayload(&buf, i)
if err != nil {
return WAFRuleStatus{}, err
}
options := &RequestOptions{
Body: &buf,
Headers: map[string]string{
"Content-Type": jsonapi.MediaType,
"Accept": jsonapi.MediaType,
},
}
resp, err := c.Patch(path, options)
if err != nil {
return WAFRuleStatus{}, err
}
var status WAFRuleStatus
err = jsonapi.UnmarshalPayload(resp.Body, &status)
return status, err
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"UpdateWAFRuleStatus",
"(",
"i",
"*",
"UpdateWAFRuleStatusInput",
")",
"(",
"WAFRuleStatus",
",",
"error",
")",
"{",
"if",
"err",
":=",
"i",
".",
"validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"WAFRuleStatus",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
".",
"Service",
",",
"i",
".",
"WAF",
",",
"i",
".",
"RuleID",
")",
"\n\n",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"err",
":=",
"jsonapi",
".",
"MarshalPayload",
"(",
"&",
"buf",
",",
"i",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"WAFRuleStatus",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"options",
":=",
"&",
"RequestOptions",
"{",
"Body",
":",
"&",
"buf",
",",
"Headers",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"jsonapi",
".",
"MediaType",
",",
"\"",
"\"",
":",
"jsonapi",
".",
"MediaType",
",",
"}",
",",
"}",
"\n\n",
"resp",
",",
"err",
":=",
"c",
".",
"Patch",
"(",
"path",
",",
"options",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"WAFRuleStatus",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"status",
"WAFRuleStatus",
"\n",
"err",
"=",
"jsonapi",
".",
"UnmarshalPayload",
"(",
"resp",
".",
"Body",
",",
"&",
"status",
")",
"\n",
"return",
"status",
",",
"err",
"\n",
"}"
] | // UpdateWAFRuleStatus changes the status of a single rule associated with a WAF. | [
"UpdateWAFRuleStatus",
"changes",
"the",
"status",
"of",
"a",
"single",
"rule",
"associated",
"with",
"a",
"WAF",
"."
] | f249287bd4fda366a7f324f45a2308e934198464 | https://github.com/sethvargo/go-fastly/blob/f249287bd4fda366a7f324f45a2308e934198464/fastly/waf.go#L815-L844 |
10,417 | sethvargo/go-fastly | fastly/waf.go | UpdateWAFConfigSet | func (c *Client) UpdateWAFConfigSet(i *UpdateWAFConfigSetInput) (UpdateWAFConfigSetResponse, error) {
if err := i.validate(); err != nil {
return UpdateWAFConfigSetResponse{}, err
}
var wafs []interface{}
for _, w := range i.WAFList {
wafs = append(wafs, &w)
}
path := fmt.Sprintf("/wafs/configuration_sets/%s/relationships/wafs", i.ConfigSetID)
resp, err := c.PatchJSONAPI(path, wafs, nil)
if err != nil {
return UpdateWAFConfigSetResponse{}, err
}
wafConfigSetResponse := UpdateWAFConfigSetResponse{}
err = c.interpretWAFCongfigSetResponse(&wafConfigSetResponse, resp)
if err != nil {
return UpdateWAFConfigSetResponse{}, err
}
return wafConfigSetResponse, nil
} | go | func (c *Client) UpdateWAFConfigSet(i *UpdateWAFConfigSetInput) (UpdateWAFConfigSetResponse, error) {
if err := i.validate(); err != nil {
return UpdateWAFConfigSetResponse{}, err
}
var wafs []interface{}
for _, w := range i.WAFList {
wafs = append(wafs, &w)
}
path := fmt.Sprintf("/wafs/configuration_sets/%s/relationships/wafs", i.ConfigSetID)
resp, err := c.PatchJSONAPI(path, wafs, nil)
if err != nil {
return UpdateWAFConfigSetResponse{}, err
}
wafConfigSetResponse := UpdateWAFConfigSetResponse{}
err = c.interpretWAFCongfigSetResponse(&wafConfigSetResponse, resp)
if err != nil {
return UpdateWAFConfigSetResponse{}, err
}
return wafConfigSetResponse, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"UpdateWAFConfigSet",
"(",
"i",
"*",
"UpdateWAFConfigSetInput",
")",
"(",
"UpdateWAFConfigSetResponse",
",",
"error",
")",
"{",
"if",
"err",
":=",
"i",
".",
"validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"UpdateWAFConfigSetResponse",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"var",
"wafs",
"[",
"]",
"interface",
"{",
"}",
"\n",
"for",
"_",
",",
"w",
":=",
"range",
"i",
".",
"WAFList",
"{",
"wafs",
"=",
"append",
"(",
"wafs",
",",
"&",
"w",
")",
"\n",
"}",
"\n\n",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
".",
"ConfigSetID",
")",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"PatchJSONAPI",
"(",
"path",
",",
"wafs",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"UpdateWAFConfigSetResponse",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"wafConfigSetResponse",
":=",
"UpdateWAFConfigSetResponse",
"{",
"}",
"\n\n",
"err",
"=",
"c",
".",
"interpretWAFCongfigSetResponse",
"(",
"&",
"wafConfigSetResponse",
",",
"resp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"UpdateWAFConfigSetResponse",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"wafConfigSetResponse",
",",
"nil",
"\n",
"}"
] | // UpdateWAFConfigSet updates a list of WAFs with the given configset | [
"UpdateWAFConfigSet",
"updates",
"a",
"list",
"of",
"WAFs",
"with",
"the",
"given",
"configset"
] | f249287bd4fda366a7f324f45a2308e934198464 | https://github.com/sethvargo/go-fastly/blob/f249287bd4fda366a7f324f45a2308e934198464/fastly/waf.go#L946-L969 |
10,418 | sethvargo/go-fastly | fastly/waf.go | interpretWAFCongfigSetResponse | func (c *Client) interpretWAFCongfigSetResponse(answer *UpdateWAFConfigSetResponse, received *http.Response) error {
pages, body, err := getPages(received.Body)
if err != nil {
return err
}
data, err := jsonapi.UnmarshalManyPayload(body, reflect.TypeOf([]ConfigSetWAFs{}))
if err != nil {
return err
}
for i := range data {
typed, ok := data[i].(*ConfigSetWAFs)
if !ok {
return fmt.Errorf("got back response of unexpected type")
}
answer.IDs = append(answer.IDs, *typed)
}
if pages.Next != "" {
resp, err := c.SimpleGet(pages.Next)
if err != nil {
return err
}
c.interpretWAFCongfigSetResponse(answer, resp)
}
return nil
} | go | func (c *Client) interpretWAFCongfigSetResponse(answer *UpdateWAFConfigSetResponse, received *http.Response) error {
pages, body, err := getPages(received.Body)
if err != nil {
return err
}
data, err := jsonapi.UnmarshalManyPayload(body, reflect.TypeOf([]ConfigSetWAFs{}))
if err != nil {
return err
}
for i := range data {
typed, ok := data[i].(*ConfigSetWAFs)
if !ok {
return fmt.Errorf("got back response of unexpected type")
}
answer.IDs = append(answer.IDs, *typed)
}
if pages.Next != "" {
resp, err := c.SimpleGet(pages.Next)
if err != nil {
return err
}
c.interpretWAFCongfigSetResponse(answer, resp)
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"interpretWAFCongfigSetResponse",
"(",
"answer",
"*",
"UpdateWAFConfigSetResponse",
",",
"received",
"*",
"http",
".",
"Response",
")",
"error",
"{",
"pages",
",",
"body",
",",
"err",
":=",
"getPages",
"(",
"received",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"data",
",",
"err",
":=",
"jsonapi",
".",
"UnmarshalManyPayload",
"(",
"body",
",",
"reflect",
".",
"TypeOf",
"(",
"[",
"]",
"ConfigSetWAFs",
"{",
"}",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"range",
"data",
"{",
"typed",
",",
"ok",
":=",
"data",
"[",
"i",
"]",
".",
"(",
"*",
"ConfigSetWAFs",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"answer",
".",
"IDs",
"=",
"append",
"(",
"answer",
".",
"IDs",
",",
"*",
"typed",
")",
"\n",
"}",
"\n\n",
"if",
"pages",
".",
"Next",
"!=",
"\"",
"\"",
"{",
"resp",
",",
"err",
":=",
"c",
".",
"SimpleGet",
"(",
"pages",
".",
"Next",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"c",
".",
"interpretWAFCongfigSetResponse",
"(",
"answer",
",",
"resp",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // interpretWAFCongfigSetResponse accepts a Fastly response containing a set of WAF ID's that
// where given to associate with the config set and unmarshals the results.
// If there are more pages of results, it fetches the next
// page, adds that response to the array of results, and repeats until all results have
// been fetched. | [
"interpretWAFCongfigSetResponse",
"accepts",
"a",
"Fastly",
"response",
"containing",
"a",
"set",
"of",
"WAF",
"ID",
"s",
"that",
"where",
"given",
"to",
"associate",
"with",
"the",
"config",
"set",
"and",
"unmarshals",
"the",
"results",
".",
"If",
"there",
"are",
"more",
"pages",
"of",
"results",
"it",
"fetches",
"the",
"next",
"page",
"adds",
"that",
"response",
"to",
"the",
"array",
"of",
"results",
"and",
"repeats",
"until",
"all",
"results",
"have",
"been",
"fetched",
"."
] | f249287bd4fda366a7f324f45a2308e934198464 | https://github.com/sethvargo/go-fastly/blob/f249287bd4fda366a7f324f45a2308e934198464/fastly/waf.go#L990-L1017 |
10,419 | sethvargo/go-fastly | fastly/response_object.go | ListResponseObjects | func (c *Client) ListResponseObjects(i *ListResponseObjectsInput) ([]*ResponseObject, error) {
if i.Service == "" {
return nil, ErrMissingService
}
if i.Version == 0 {
return nil, ErrMissingVersion
}
path := fmt.Sprintf("/service/%s/version/%d/response_object", i.Service, i.Version)
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
}
var bs []*ResponseObject
if err := decodeJSON(&bs, resp.Body); err != nil {
return nil, err
}
sort.Stable(responseObjectsByName(bs))
return bs, nil
} | go | func (c *Client) ListResponseObjects(i *ListResponseObjectsInput) ([]*ResponseObject, error) {
if i.Service == "" {
return nil, ErrMissingService
}
if i.Version == 0 {
return nil, ErrMissingVersion
}
path := fmt.Sprintf("/service/%s/version/%d/response_object", i.Service, i.Version)
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
}
var bs []*ResponseObject
if err := decodeJSON(&bs, resp.Body); err != nil {
return nil, err
}
sort.Stable(responseObjectsByName(bs))
return bs, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ListResponseObjects",
"(",
"i",
"*",
"ListResponseObjectsInput",
")",
"(",
"[",
"]",
"*",
"ResponseObject",
",",
"error",
")",
"{",
"if",
"i",
".",
"Service",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"ErrMissingService",
"\n",
"}",
"\n\n",
"if",
"i",
".",
"Version",
"==",
"0",
"{",
"return",
"nil",
",",
"ErrMissingVersion",
"\n",
"}",
"\n\n",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
".",
"Service",
",",
"i",
".",
"Version",
")",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"Get",
"(",
"path",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"bs",
"[",
"]",
"*",
"ResponseObject",
"\n",
"if",
"err",
":=",
"decodeJSON",
"(",
"&",
"bs",
",",
"resp",
".",
"Body",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"sort",
".",
"Stable",
"(",
"responseObjectsByName",
"(",
"bs",
")",
")",
"\n",
"return",
"bs",
",",
"nil",
"\n",
"}"
] | // ListResponseObjects returns the list of response objects for the
// configuration version. | [
"ListResponseObjects",
"returns",
"the",
"list",
"of",
"response",
"objects",
"for",
"the",
"configuration",
"version",
"."
] | f249287bd4fda366a7f324f45a2308e934198464 | https://github.com/sethvargo/go-fastly/blob/f249287bd4fda366a7f324f45a2308e934198464/fastly/response_object.go#L44-L65 |
10,420 | sethvargo/go-fastly | fastly/response_object.go | CreateResponseObject | func (c *Client) CreateResponseObject(i *CreateResponseObjectInput) (*ResponseObject, error) {
if i.Service == "" {
return nil, ErrMissingService
}
if i.Version == 0 {
return nil, ErrMissingVersion
}
path := fmt.Sprintf("/service/%s/version/%d/response_object", i.Service, i.Version)
resp, err := c.PostForm(path, i, nil)
if err != nil {
return nil, err
}
var b *ResponseObject
if err := decodeJSON(&b, resp.Body); err != nil {
return nil, err
}
return b, nil
} | go | func (c *Client) CreateResponseObject(i *CreateResponseObjectInput) (*ResponseObject, error) {
if i.Service == "" {
return nil, ErrMissingService
}
if i.Version == 0 {
return nil, ErrMissingVersion
}
path := fmt.Sprintf("/service/%s/version/%d/response_object", i.Service, i.Version)
resp, err := c.PostForm(path, i, nil)
if err != nil {
return nil, err
}
var b *ResponseObject
if err := decodeJSON(&b, resp.Body); err != nil {
return nil, err
}
return b, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"CreateResponseObject",
"(",
"i",
"*",
"CreateResponseObjectInput",
")",
"(",
"*",
"ResponseObject",
",",
"error",
")",
"{",
"if",
"i",
".",
"Service",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"ErrMissingService",
"\n",
"}",
"\n\n",
"if",
"i",
".",
"Version",
"==",
"0",
"{",
"return",
"nil",
",",
"ErrMissingVersion",
"\n",
"}",
"\n\n",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
".",
"Service",
",",
"i",
".",
"Version",
")",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"PostForm",
"(",
"path",
",",
"i",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"b",
"*",
"ResponseObject",
"\n",
"if",
"err",
":=",
"decodeJSON",
"(",
"&",
"b",
",",
"resp",
".",
"Body",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"b",
",",
"nil",
"\n",
"}"
] | // CreateResponseObject creates a new Fastly response object. | [
"CreateResponseObject",
"creates",
"a",
"new",
"Fastly",
"response",
"object",
"."
] | f249287bd4fda366a7f324f45a2308e934198464 | https://github.com/sethvargo/go-fastly/blob/f249287bd4fda366a7f324f45a2308e934198464/fastly/response_object.go#L85-L105 |
10,421 | sethvargo/go-fastly | fastly/response_object.go | GetResponseObject | func (c *Client) GetResponseObject(i *GetResponseObjectInput) (*ResponseObject, error) {
if i.Service == "" {
return nil, ErrMissingService
}
if i.Version == 0 {
return nil, ErrMissingVersion
}
if i.Name == "" {
return nil, ErrMissingName
}
path := fmt.Sprintf("/service/%s/version/%d/response_object/%s", i.Service, i.Version, i.Name)
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
}
var b *ResponseObject
if err := decodeJSON(&b, resp.Body); err != nil {
return nil, err
}
return b, nil
} | go | func (c *Client) GetResponseObject(i *GetResponseObjectInput) (*ResponseObject, error) {
if i.Service == "" {
return nil, ErrMissingService
}
if i.Version == 0 {
return nil, ErrMissingVersion
}
if i.Name == "" {
return nil, ErrMissingName
}
path := fmt.Sprintf("/service/%s/version/%d/response_object/%s", i.Service, i.Version, i.Name)
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
}
var b *ResponseObject
if err := decodeJSON(&b, resp.Body); err != nil {
return nil, err
}
return b, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetResponseObject",
"(",
"i",
"*",
"GetResponseObjectInput",
")",
"(",
"*",
"ResponseObject",
",",
"error",
")",
"{",
"if",
"i",
".",
"Service",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"ErrMissingService",
"\n",
"}",
"\n\n",
"if",
"i",
".",
"Version",
"==",
"0",
"{",
"return",
"nil",
",",
"ErrMissingVersion",
"\n",
"}",
"\n\n",
"if",
"i",
".",
"Name",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"ErrMissingName",
"\n",
"}",
"\n\n",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
".",
"Service",
",",
"i",
".",
"Version",
",",
"i",
".",
"Name",
")",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"Get",
"(",
"path",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"b",
"*",
"ResponseObject",
"\n",
"if",
"err",
":=",
"decodeJSON",
"(",
"&",
"b",
",",
"resp",
".",
"Body",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"b",
",",
"nil",
"\n",
"}"
] | // GetResponseObject gets the response object configuration with the given
// parameters. | [
"GetResponseObject",
"gets",
"the",
"response",
"object",
"configuration",
"with",
"the",
"given",
"parameters",
"."
] | f249287bd4fda366a7f324f45a2308e934198464 | https://github.com/sethvargo/go-fastly/blob/f249287bd4fda366a7f324f45a2308e934198464/fastly/response_object.go#L120-L144 |
10,422 | sethvargo/go-fastly | fastly/response_object.go | UpdateResponseObject | func (c *Client) UpdateResponseObject(i *UpdateResponseObjectInput) (*ResponseObject, error) {
if i.Service == "" {
return nil, ErrMissingService
}
if i.Version == 0 {
return nil, ErrMissingVersion
}
if i.Name == "" {
return nil, ErrMissingName
}
path := fmt.Sprintf("/service/%s/version/%d/response_object/%s", i.Service, i.Version, i.Name)
resp, err := c.PutForm(path, i, nil)
if err != nil {
return nil, err
}
var b *ResponseObject
if err := decodeJSON(&b, resp.Body); err != nil {
return nil, err
}
return b, nil
} | go | func (c *Client) UpdateResponseObject(i *UpdateResponseObjectInput) (*ResponseObject, error) {
if i.Service == "" {
return nil, ErrMissingService
}
if i.Version == 0 {
return nil, ErrMissingVersion
}
if i.Name == "" {
return nil, ErrMissingName
}
path := fmt.Sprintf("/service/%s/version/%d/response_object/%s", i.Service, i.Version, i.Name)
resp, err := c.PutForm(path, i, nil)
if err != nil {
return nil, err
}
var b *ResponseObject
if err := decodeJSON(&b, resp.Body); err != nil {
return nil, err
}
return b, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"UpdateResponseObject",
"(",
"i",
"*",
"UpdateResponseObjectInput",
")",
"(",
"*",
"ResponseObject",
",",
"error",
")",
"{",
"if",
"i",
".",
"Service",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"ErrMissingService",
"\n",
"}",
"\n\n",
"if",
"i",
".",
"Version",
"==",
"0",
"{",
"return",
"nil",
",",
"ErrMissingVersion",
"\n",
"}",
"\n\n",
"if",
"i",
".",
"Name",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"ErrMissingName",
"\n",
"}",
"\n\n",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
".",
"Service",
",",
"i",
".",
"Version",
",",
"i",
".",
"Name",
")",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"PutForm",
"(",
"path",
",",
"i",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"b",
"*",
"ResponseObject",
"\n",
"if",
"err",
":=",
"decodeJSON",
"(",
"&",
"b",
",",
"resp",
".",
"Body",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"b",
",",
"nil",
"\n",
"}"
] | // UpdateResponseObject updates a specific response object. | [
"UpdateResponseObject",
"updates",
"a",
"specific",
"response",
"object",
"."
] | f249287bd4fda366a7f324f45a2308e934198464 | https://github.com/sethvargo/go-fastly/blob/f249287bd4fda366a7f324f45a2308e934198464/fastly/response_object.go#L167-L191 |
10,423 | dchest/passwordreset | passwordreset.go | VerifyToken | func VerifyToken(token string, pwdvalFn func(string) ([]byte, error), secret []byte) (login string, err error) {
blen := base64.URLEncoding.DecodedLen(len(token))
// Avoid allocation if the token is too short
if blen <= 4+32 {
err = ErrMalformedToken
return
}
b := make([]byte, blen)
blen, err = base64.URLEncoding.Decode(b, []byte(token))
if err != nil {
return
}
// Decoded length may be bifferent from max length, which
// we allocated, so check it, and set new length for b
if blen <= 4+32 {
err = ErrMalformedToken
return
}
b = b[:blen]
data := b[:blen-32]
exp := time.Unix(int64(binary.BigEndian.Uint32(data[:4])), 0)
if exp.Before(time.Now()) {
err = ErrExpiredToken
return
}
login = string(data[4:])
pwdval, err := pwdvalFn(login)
if err != nil {
login = ""
return
}
sig := b[blen-32:]
sk := getUserSecretKey(pwdval, secret)
realSig := getSignature(data, sk)
if subtle.ConstantTimeCompare(realSig, sig) != 1 {
err = ErrWrongSignature
return
}
return
} | go | func VerifyToken(token string, pwdvalFn func(string) ([]byte, error), secret []byte) (login string, err error) {
blen := base64.URLEncoding.DecodedLen(len(token))
// Avoid allocation if the token is too short
if blen <= 4+32 {
err = ErrMalformedToken
return
}
b := make([]byte, blen)
blen, err = base64.URLEncoding.Decode(b, []byte(token))
if err != nil {
return
}
// Decoded length may be bifferent from max length, which
// we allocated, so check it, and set new length for b
if blen <= 4+32 {
err = ErrMalformedToken
return
}
b = b[:blen]
data := b[:blen-32]
exp := time.Unix(int64(binary.BigEndian.Uint32(data[:4])), 0)
if exp.Before(time.Now()) {
err = ErrExpiredToken
return
}
login = string(data[4:])
pwdval, err := pwdvalFn(login)
if err != nil {
login = ""
return
}
sig := b[blen-32:]
sk := getUserSecretKey(pwdval, secret)
realSig := getSignature(data, sk)
if subtle.ConstantTimeCompare(realSig, sig) != 1 {
err = ErrWrongSignature
return
}
return
} | [
"func",
"VerifyToken",
"(",
"token",
"string",
",",
"pwdvalFn",
"func",
"(",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
",",
"secret",
"[",
"]",
"byte",
")",
"(",
"login",
"string",
",",
"err",
"error",
")",
"{",
"blen",
":=",
"base64",
".",
"URLEncoding",
".",
"DecodedLen",
"(",
"len",
"(",
"token",
")",
")",
"\n",
"// Avoid allocation if the token is too short",
"if",
"blen",
"<=",
"4",
"+",
"32",
"{",
"err",
"=",
"ErrMalformedToken",
"\n",
"return",
"\n",
"}",
"\n",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"blen",
")",
"\n",
"blen",
",",
"err",
"=",
"base64",
".",
"URLEncoding",
".",
"Decode",
"(",
"b",
",",
"[",
"]",
"byte",
"(",
"token",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"// Decoded length may be bifferent from max length, which",
"// we allocated, so check it, and set new length for b",
"if",
"blen",
"<=",
"4",
"+",
"32",
"{",
"err",
"=",
"ErrMalformedToken",
"\n",
"return",
"\n",
"}",
"\n",
"b",
"=",
"b",
"[",
":",
"blen",
"]",
"\n\n",
"data",
":=",
"b",
"[",
":",
"blen",
"-",
"32",
"]",
"\n",
"exp",
":=",
"time",
".",
"Unix",
"(",
"int64",
"(",
"binary",
".",
"BigEndian",
".",
"Uint32",
"(",
"data",
"[",
":",
"4",
"]",
")",
")",
",",
"0",
")",
"\n",
"if",
"exp",
".",
"Before",
"(",
"time",
".",
"Now",
"(",
")",
")",
"{",
"err",
"=",
"ErrExpiredToken",
"\n",
"return",
"\n",
"}",
"\n",
"login",
"=",
"string",
"(",
"data",
"[",
"4",
":",
"]",
")",
"\n",
"pwdval",
",",
"err",
":=",
"pwdvalFn",
"(",
"login",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"login",
"=",
"\"",
"\"",
"\n",
"return",
"\n",
"}",
"\n",
"sig",
":=",
"b",
"[",
"blen",
"-",
"32",
":",
"]",
"\n",
"sk",
":=",
"getUserSecretKey",
"(",
"pwdval",
",",
"secret",
")",
"\n",
"realSig",
":=",
"getSignature",
"(",
"data",
",",
"sk",
")",
"\n",
"if",
"subtle",
".",
"ConstantTimeCompare",
"(",
"realSig",
",",
"sig",
")",
"!=",
"1",
"{",
"err",
"=",
"ErrWrongSignature",
"\n",
"return",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // VerifyToken verifies the given token with the password value returned by the
// given function and the given secret key, and returns login extracted from
// the valid token. If the token is not valid, the function returns an error.
//
// Function pwdvalFn must return the current password value for the login it
// receives in arguments, or an error. If it returns an error, VerifyToken
// returns the same error. | [
"VerifyToken",
"verifies",
"the",
"given",
"token",
"with",
"the",
"password",
"value",
"returned",
"by",
"the",
"given",
"function",
"and",
"the",
"given",
"secret",
"key",
"and",
"returns",
"login",
"extracted",
"from",
"the",
"valid",
"token",
".",
"If",
"the",
"token",
"is",
"not",
"valid",
"the",
"function",
"returns",
"an",
"error",
".",
"Function",
"pwdvalFn",
"must",
"return",
"the",
"current",
"password",
"value",
"for",
"the",
"login",
"it",
"receives",
"in",
"arguments",
"or",
"an",
"error",
".",
"If",
"it",
"returns",
"an",
"error",
"VerifyToken",
"returns",
"the",
"same",
"error",
"."
] | 642cf836ac8dfd4ddec7a28cbef7b00da0807812 | https://github.com/dchest/passwordreset/blob/642cf836ac8dfd4ddec7a28cbef7b00da0807812/passwordreset.go#L134-L174 |
10,424 | mitchellh/go-mruby | class.go | DefineClassMethod | func (c *Class) DefineClassMethod(name string, cb Func, as ArgSpec) {
insertMethod(c.mrb.state, c.class.c, name, cb)
cs := C.CString(name)
defer C.free(unsafe.Pointer(cs))
C.mrb_define_class_method(
c.mrb.state,
c.class,
cs,
C._go_mrb_func_t(),
C.mrb_aspec(as))
} | go | func (c *Class) DefineClassMethod(name string, cb Func, as ArgSpec) {
insertMethod(c.mrb.state, c.class.c, name, cb)
cs := C.CString(name)
defer C.free(unsafe.Pointer(cs))
C.mrb_define_class_method(
c.mrb.state,
c.class,
cs,
C._go_mrb_func_t(),
C.mrb_aspec(as))
} | [
"func",
"(",
"c",
"*",
"Class",
")",
"DefineClassMethod",
"(",
"name",
"string",
",",
"cb",
"Func",
",",
"as",
"ArgSpec",
")",
"{",
"insertMethod",
"(",
"c",
".",
"mrb",
".",
"state",
",",
"c",
".",
"class",
".",
"c",
",",
"name",
",",
"cb",
")",
"\n\n",
"cs",
":=",
"C",
".",
"CString",
"(",
"name",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"cs",
")",
")",
"\n\n",
"C",
".",
"mrb_define_class_method",
"(",
"c",
".",
"mrb",
".",
"state",
",",
"c",
".",
"class",
",",
"cs",
",",
"C",
".",
"_go_mrb_func_t",
"(",
")",
",",
"C",
".",
"mrb_aspec",
"(",
"as",
")",
")",
"\n",
"}"
] | // DefineClassMethod defines a class-level method on the given class. | [
"DefineClassMethod",
"defines",
"a",
"class",
"-",
"level",
"method",
"on",
"the",
"given",
"class",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/class.go#L17-L29 |
10,425 | mitchellh/go-mruby | class.go | DefineConst | func (c *Class) DefineConst(name string, value Value) {
cs := C.CString(name)
defer C.free(unsafe.Pointer(cs))
C.mrb_define_const(
c.mrb.state, c.class, cs, value.MrbValue(c.mrb).value)
} | go | func (c *Class) DefineConst(name string, value Value) {
cs := C.CString(name)
defer C.free(unsafe.Pointer(cs))
C.mrb_define_const(
c.mrb.state, c.class, cs, value.MrbValue(c.mrb).value)
} | [
"func",
"(",
"c",
"*",
"Class",
")",
"DefineConst",
"(",
"name",
"string",
",",
"value",
"Value",
")",
"{",
"cs",
":=",
"C",
".",
"CString",
"(",
"name",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"cs",
")",
")",
"\n\n",
"C",
".",
"mrb_define_const",
"(",
"c",
".",
"mrb",
".",
"state",
",",
"c",
".",
"class",
",",
"cs",
",",
"value",
".",
"MrbValue",
"(",
"c",
".",
"mrb",
")",
".",
"value",
")",
"\n",
"}"
] | // DefineConst defines a constant within this class. | [
"DefineConst",
"defines",
"a",
"constant",
"within",
"this",
"class",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/class.go#L32-L38 |
10,426 | mitchellh/go-mruby | class.go | New | func (c *Class) New(args ...Value) (*MrbValue, error) {
var argv []C.mrb_value
var argvPtr *C.mrb_value
if len(args) > 0 {
// Make the raw byte slice to hold our arguments we'll pass to C
argv = make([]C.mrb_value, len(args))
for i, arg := range args {
argv[i] = arg.MrbValue(c.mrb).value
}
argvPtr = &argv[0]
}
result := C.mrb_obj_new(c.mrb.state, c.class, C.mrb_int(len(argv)), argvPtr)
if exc := checkException(c.mrb.state); exc != nil {
return nil, exc
}
return newValue(c.mrb.state, result), nil
} | go | func (c *Class) New(args ...Value) (*MrbValue, error) {
var argv []C.mrb_value
var argvPtr *C.mrb_value
if len(args) > 0 {
// Make the raw byte slice to hold our arguments we'll pass to C
argv = make([]C.mrb_value, len(args))
for i, arg := range args {
argv[i] = arg.MrbValue(c.mrb).value
}
argvPtr = &argv[0]
}
result := C.mrb_obj_new(c.mrb.state, c.class, C.mrb_int(len(argv)), argvPtr)
if exc := checkException(c.mrb.state); exc != nil {
return nil, exc
}
return newValue(c.mrb.state, result), nil
} | [
"func",
"(",
"c",
"*",
"Class",
")",
"New",
"(",
"args",
"...",
"Value",
")",
"(",
"*",
"MrbValue",
",",
"error",
")",
"{",
"var",
"argv",
"[",
"]",
"C",
".",
"mrb_value",
"\n",
"var",
"argvPtr",
"*",
"C",
".",
"mrb_value",
"\n",
"if",
"len",
"(",
"args",
")",
">",
"0",
"{",
"// Make the raw byte slice to hold our arguments we'll pass to C",
"argv",
"=",
"make",
"(",
"[",
"]",
"C",
".",
"mrb_value",
",",
"len",
"(",
"args",
")",
")",
"\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
"{",
"argv",
"[",
"i",
"]",
"=",
"arg",
".",
"MrbValue",
"(",
"c",
".",
"mrb",
")",
".",
"value",
"\n",
"}",
"\n\n",
"argvPtr",
"=",
"&",
"argv",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"result",
":=",
"C",
".",
"mrb_obj_new",
"(",
"c",
".",
"mrb",
".",
"state",
",",
"c",
".",
"class",
",",
"C",
".",
"mrb_int",
"(",
"len",
"(",
"argv",
")",
")",
",",
"argvPtr",
")",
"\n",
"if",
"exc",
":=",
"checkException",
"(",
"c",
".",
"mrb",
".",
"state",
")",
";",
"exc",
"!=",
"nil",
"{",
"return",
"nil",
",",
"exc",
"\n",
"}",
"\n\n",
"return",
"newValue",
"(",
"c",
".",
"mrb",
".",
"state",
",",
"result",
")",
",",
"nil",
"\n",
"}"
] | // New instantiates the class with the given args. | [
"New",
"instantiates",
"the",
"class",
"with",
"the",
"given",
"args",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/class.go#L62-L81 |
10,427 | mitchellh/go-mruby | mruby.go | GetGlobalVariable | func (m *Mrb) GetGlobalVariable(name string) *MrbValue {
cs := C.CString(name)
defer C.free(unsafe.Pointer(cs))
return newValue(m.state, C._go_mrb_gv_get(m.state, C.mrb_intern_cstr(m.state, cs)))
} | go | func (m *Mrb) GetGlobalVariable(name string) *MrbValue {
cs := C.CString(name)
defer C.free(unsafe.Pointer(cs))
return newValue(m.state, C._go_mrb_gv_get(m.state, C.mrb_intern_cstr(m.state, cs)))
} | [
"func",
"(",
"m",
"*",
"Mrb",
")",
"GetGlobalVariable",
"(",
"name",
"string",
")",
"*",
"MrbValue",
"{",
"cs",
":=",
"C",
".",
"CString",
"(",
"name",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"cs",
")",
")",
"\n",
"return",
"newValue",
"(",
"m",
".",
"state",
",",
"C",
".",
"_go_mrb_gv_get",
"(",
"m",
".",
"state",
",",
"C",
".",
"mrb_intern_cstr",
"(",
"m",
".",
"state",
",",
"cs",
")",
")",
")",
"\n",
"}"
] | // GetGlobalVariable returns the value of the global variable by the given name. | [
"GetGlobalVariable",
"returns",
"the",
"value",
"of",
"the",
"global",
"variable",
"by",
"the",
"given",
"name",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/mruby.go#L17-L21 |
10,428 | mitchellh/go-mruby | mruby.go | SetGlobalVariable | func (m *Mrb) SetGlobalVariable(name string, value Value) {
cs := C.CString(name)
defer C.free(unsafe.Pointer(cs))
v := value.MrbValue(m)
C._go_mrb_gv_set(m.state, C.mrb_intern_cstr(m.state, cs), v.value)
} | go | func (m *Mrb) SetGlobalVariable(name string, value Value) {
cs := C.CString(name)
defer C.free(unsafe.Pointer(cs))
v := value.MrbValue(m)
C._go_mrb_gv_set(m.state, C.mrb_intern_cstr(m.state, cs), v.value)
} | [
"func",
"(",
"m",
"*",
"Mrb",
")",
"SetGlobalVariable",
"(",
"name",
"string",
",",
"value",
"Value",
")",
"{",
"cs",
":=",
"C",
".",
"CString",
"(",
"name",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"cs",
")",
")",
"\n\n",
"v",
":=",
"value",
".",
"MrbValue",
"(",
"m",
")",
"\n",
"C",
".",
"_go_mrb_gv_set",
"(",
"m",
".",
"state",
",",
"C",
".",
"mrb_intern_cstr",
"(",
"m",
".",
"state",
",",
"cs",
")",
",",
"v",
".",
"value",
")",
"\n",
"}"
] | // SetGlobalVariable sets the value of the global variable by the given name. | [
"SetGlobalVariable",
"sets",
"the",
"value",
"of",
"the",
"global",
"variable",
"by",
"the",
"given",
"name",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/mruby.go#L24-L30 |
10,429 | mitchellh/go-mruby | mruby.go | ArenaRestore | func (m *Mrb) ArenaRestore(idx ArenaIndex) {
C.mrb_gc_arena_restore(m.state, C.int(idx))
} | go | func (m *Mrb) ArenaRestore(idx ArenaIndex) {
C.mrb_gc_arena_restore(m.state, C.int(idx))
} | [
"func",
"(",
"m",
"*",
"Mrb",
")",
"ArenaRestore",
"(",
"idx",
"ArenaIndex",
")",
"{",
"C",
".",
"mrb_gc_arena_restore",
"(",
"m",
".",
"state",
",",
"C",
".",
"int",
"(",
"idx",
")",
")",
"\n",
"}"
] | // ArenaRestore restores the arena index so the objects between the save and this point
// can be garbage collected in the future.
//
// See ArenaSave for more documentation. | [
"ArenaRestore",
"restores",
"the",
"arena",
"index",
"so",
"the",
"objects",
"between",
"the",
"save",
"and",
"this",
"point",
"can",
"be",
"garbage",
"collected",
"in",
"the",
"future",
".",
"See",
"ArenaSave",
"for",
"more",
"documentation",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/mruby.go#L54-L56 |
10,430 | mitchellh/go-mruby | mruby.go | Close | func (m *Mrb) Close() {
// Delete all the methods from the state
stateMethodTable.Mutex.Lock()
delete(stateMethodTable.Map, m.state)
stateMethodTable.Mutex.Unlock()
// Close the state
C.mrb_close(m.state)
} | go | func (m *Mrb) Close() {
// Delete all the methods from the state
stateMethodTable.Mutex.Lock()
delete(stateMethodTable.Map, m.state)
stateMethodTable.Mutex.Unlock()
// Close the state
C.mrb_close(m.state)
} | [
"func",
"(",
"m",
"*",
"Mrb",
")",
"Close",
"(",
")",
"{",
"// Delete all the methods from the state",
"stateMethodTable",
".",
"Mutex",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"stateMethodTable",
".",
"Map",
",",
"m",
".",
"state",
")",
"\n",
"stateMethodTable",
".",
"Mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Close the state",
"C",
".",
"mrb_close",
"(",
"m",
".",
"state",
")",
"\n",
"}"
] | // Close a Mrb, this must be called to properly free resources, and
// should only be called once. | [
"Close",
"a",
"Mrb",
"this",
"must",
"be",
"called",
"to",
"properly",
"free",
"resources",
"and",
"should",
"only",
"be",
"called",
"once",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/mruby.go#L130-L138 |
10,431 | mitchellh/go-mruby | mruby.go | LoadString | func (m *Mrb) LoadString(code string) (*MrbValue, error) {
cs := C.CString(code)
defer C.free(unsafe.Pointer(cs))
value := C._go_mrb_load_string(m.state, cs)
if exc := checkException(m.state); exc != nil {
return nil, exc
}
return newValue(m.state, value), nil
} | go | func (m *Mrb) LoadString(code string) (*MrbValue, error) {
cs := C.CString(code)
defer C.free(unsafe.Pointer(cs))
value := C._go_mrb_load_string(m.state, cs)
if exc := checkException(m.state); exc != nil {
return nil, exc
}
return newValue(m.state, value), nil
} | [
"func",
"(",
"m",
"*",
"Mrb",
")",
"LoadString",
"(",
"code",
"string",
")",
"(",
"*",
"MrbValue",
",",
"error",
")",
"{",
"cs",
":=",
"C",
".",
"CString",
"(",
"code",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"cs",
")",
")",
"\n\n",
"value",
":=",
"C",
".",
"_go_mrb_load_string",
"(",
"m",
".",
"state",
",",
"cs",
")",
"\n",
"if",
"exc",
":=",
"checkException",
"(",
"m",
".",
"state",
")",
";",
"exc",
"!=",
"nil",
"{",
"return",
"nil",
",",
"exc",
"\n",
"}",
"\n\n",
"return",
"newValue",
"(",
"m",
".",
"state",
",",
"value",
")",
",",
"nil",
"\n",
"}"
] | // LoadString loads the given code, executes it, and returns its final
// value that it might return. | [
"LoadString",
"loads",
"the",
"given",
"code",
"executes",
"it",
"and",
"returns",
"its",
"final",
"value",
"that",
"it",
"might",
"return",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/mruby.go#L194-L204 |
10,432 | mitchellh/go-mruby | mruby.go | Run | func (m *Mrb) Run(v Value, self Value) (*MrbValue, error) {
if self == nil {
self = m.TopSelf()
}
mrbV := v.MrbValue(m)
mrbSelf := self.MrbValue(m)
proc := C._go_mrb_proc_ptr(mrbV.value)
value := C.mrb_run(m.state, proc, mrbSelf.value)
if exc := checkException(m.state); exc != nil {
return nil, exc
}
return newValue(m.state, value), nil
} | go | func (m *Mrb) Run(v Value, self Value) (*MrbValue, error) {
if self == nil {
self = m.TopSelf()
}
mrbV := v.MrbValue(m)
mrbSelf := self.MrbValue(m)
proc := C._go_mrb_proc_ptr(mrbV.value)
value := C.mrb_run(m.state, proc, mrbSelf.value)
if exc := checkException(m.state); exc != nil {
return nil, exc
}
return newValue(m.state, value), nil
} | [
"func",
"(",
"m",
"*",
"Mrb",
")",
"Run",
"(",
"v",
"Value",
",",
"self",
"Value",
")",
"(",
"*",
"MrbValue",
",",
"error",
")",
"{",
"if",
"self",
"==",
"nil",
"{",
"self",
"=",
"m",
".",
"TopSelf",
"(",
")",
"\n",
"}",
"\n\n",
"mrbV",
":=",
"v",
".",
"MrbValue",
"(",
"m",
")",
"\n",
"mrbSelf",
":=",
"self",
".",
"MrbValue",
"(",
"m",
")",
"\n\n",
"proc",
":=",
"C",
".",
"_go_mrb_proc_ptr",
"(",
"mrbV",
".",
"value",
")",
"\n",
"value",
":=",
"C",
".",
"mrb_run",
"(",
"m",
".",
"state",
",",
"proc",
",",
"mrbSelf",
".",
"value",
")",
"\n\n",
"if",
"exc",
":=",
"checkException",
"(",
"m",
".",
"state",
")",
";",
"exc",
"!=",
"nil",
"{",
"return",
"nil",
",",
"exc",
"\n",
"}",
"\n\n",
"return",
"newValue",
"(",
"m",
".",
"state",
",",
"value",
")",
",",
"nil",
"\n",
"}"
] | // Run executes the given value, which should be a proc type.
//
// If you're looking to execute code directly a string, look at LoadString.
//
// If self is nil, it is set to the top-level self. | [
"Run",
"executes",
"the",
"given",
"value",
"which",
"should",
"be",
"a",
"proc",
"type",
".",
"If",
"you",
"re",
"looking",
"to",
"execute",
"code",
"directly",
"a",
"string",
"look",
"at",
"LoadString",
".",
"If",
"self",
"is",
"nil",
"it",
"is",
"set",
"to",
"the",
"top",
"-",
"level",
"self",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/mruby.go#L211-L227 |
10,433 | mitchellh/go-mruby | mruby.go | Yield | func (m *Mrb) Yield(block Value, args ...Value) (*MrbValue, error) {
mrbBlock := block.MrbValue(m)
var argv []C.mrb_value
var argvPtr *C.mrb_value
if len(args) > 0 {
// Make the raw byte slice to hold our arguments we'll pass to C
argv = make([]C.mrb_value, len(args))
for i, arg := range args {
argv[i] = arg.MrbValue(m).value
}
argvPtr = &argv[0]
}
result := C._go_mrb_yield_argv(
m.state,
mrbBlock.value,
C.mrb_int(len(argv)),
argvPtr)
if exc := checkException(m.state); exc != nil {
return nil, exc
}
return newValue(m.state, result), nil
} | go | func (m *Mrb) Yield(block Value, args ...Value) (*MrbValue, error) {
mrbBlock := block.MrbValue(m)
var argv []C.mrb_value
var argvPtr *C.mrb_value
if len(args) > 0 {
// Make the raw byte slice to hold our arguments we'll pass to C
argv = make([]C.mrb_value, len(args))
for i, arg := range args {
argv[i] = arg.MrbValue(m).value
}
argvPtr = &argv[0]
}
result := C._go_mrb_yield_argv(
m.state,
mrbBlock.value,
C.mrb_int(len(argv)),
argvPtr)
if exc := checkException(m.state); exc != nil {
return nil, exc
}
return newValue(m.state, result), nil
} | [
"func",
"(",
"m",
"*",
"Mrb",
")",
"Yield",
"(",
"block",
"Value",
",",
"args",
"...",
"Value",
")",
"(",
"*",
"MrbValue",
",",
"error",
")",
"{",
"mrbBlock",
":=",
"block",
".",
"MrbValue",
"(",
"m",
")",
"\n\n",
"var",
"argv",
"[",
"]",
"C",
".",
"mrb_value",
"\n",
"var",
"argvPtr",
"*",
"C",
".",
"mrb_value",
"\n\n",
"if",
"len",
"(",
"args",
")",
">",
"0",
"{",
"// Make the raw byte slice to hold our arguments we'll pass to C",
"argv",
"=",
"make",
"(",
"[",
"]",
"C",
".",
"mrb_value",
",",
"len",
"(",
"args",
")",
")",
"\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
"{",
"argv",
"[",
"i",
"]",
"=",
"arg",
".",
"MrbValue",
"(",
"m",
")",
".",
"value",
"\n",
"}",
"\n\n",
"argvPtr",
"=",
"&",
"argv",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"result",
":=",
"C",
".",
"_go_mrb_yield_argv",
"(",
"m",
".",
"state",
",",
"mrbBlock",
".",
"value",
",",
"C",
".",
"mrb_int",
"(",
"len",
"(",
"argv",
")",
")",
",",
"argvPtr",
")",
"\n\n",
"if",
"exc",
":=",
"checkException",
"(",
"m",
".",
"state",
")",
";",
"exc",
"!=",
"nil",
"{",
"return",
"nil",
",",
"exc",
"\n",
"}",
"\n\n",
"return",
"newValue",
"(",
"m",
".",
"state",
",",
"result",
")",
",",
"nil",
"\n",
"}"
] | // Yield yields to a block with the given arguments.
//
// This should be called within the context of a Func. | [
"Yield",
"yields",
"to",
"a",
"block",
"with",
"the",
"given",
"arguments",
".",
"This",
"should",
"be",
"called",
"within",
"the",
"context",
"of",
"a",
"Func",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/mruby.go#L258-L285 |
10,434 | mitchellh/go-mruby | mruby.go | DefineModule | func (m *Mrb) DefineModule(name string) *Class {
cs := C.CString(name)
defer C.free(unsafe.Pointer(cs))
return newClass(m, C.mrb_define_module(m.state, cs))
} | go | func (m *Mrb) DefineModule(name string) *Class {
cs := C.CString(name)
defer C.free(unsafe.Pointer(cs))
return newClass(m, C.mrb_define_module(m.state, cs))
} | [
"func",
"(",
"m",
"*",
"Mrb",
")",
"DefineModule",
"(",
"name",
"string",
")",
"*",
"Class",
"{",
"cs",
":=",
"C",
".",
"CString",
"(",
"name",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"cs",
")",
")",
"\n",
"return",
"newClass",
"(",
"m",
",",
"C",
".",
"mrb_define_module",
"(",
"m",
".",
"state",
",",
"cs",
")",
")",
"\n",
"}"
] | // DefineModule defines a top-level module. | [
"DefineModule",
"defines",
"a",
"top",
"-",
"level",
"module",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/mruby.go#L326-L330 |
10,435 | mitchellh/go-mruby | mruby.go | TopSelf | func (m *Mrb) TopSelf() *MrbValue {
return newValue(m.state, C.mrb_obj_value(unsafe.Pointer(m.state.top_self)))
} | go | func (m *Mrb) TopSelf() *MrbValue {
return newValue(m.state, C.mrb_obj_value(unsafe.Pointer(m.state.top_self)))
} | [
"func",
"(",
"m",
"*",
"Mrb",
")",
"TopSelf",
"(",
")",
"*",
"MrbValue",
"{",
"return",
"newValue",
"(",
"m",
".",
"state",
",",
"C",
".",
"mrb_obj_value",
"(",
"unsafe",
".",
"Pointer",
"(",
"m",
".",
"state",
".",
"top_self",
")",
")",
")",
"\n",
"}"
] | // TopSelf returns the top-level `self` value. | [
"TopSelf",
"returns",
"the",
"top",
"-",
"level",
"self",
"value",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/mruby.go#L360-L362 |
10,436 | mitchellh/go-mruby | mruby.go | FixnumValue | func (m *Mrb) FixnumValue(v int) *MrbValue {
return newValue(m.state, C.mrb_fixnum_value(C.mrb_int(v)))
} | go | func (m *Mrb) FixnumValue(v int) *MrbValue {
return newValue(m.state, C.mrb_fixnum_value(C.mrb_int(v)))
} | [
"func",
"(",
"m",
"*",
"Mrb",
")",
"FixnumValue",
"(",
"v",
"int",
")",
"*",
"MrbValue",
"{",
"return",
"newValue",
"(",
"m",
".",
"state",
",",
"C",
".",
"mrb_fixnum_value",
"(",
"C",
".",
"mrb_int",
"(",
"v",
")",
")",
")",
"\n",
"}"
] | // FixnumValue returns a Value for a fixed number. | [
"FixnumValue",
"returns",
"a",
"Value",
"for",
"a",
"fixed",
"number",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/mruby.go#L380-L382 |
10,437 | mitchellh/go-mruby | mruby.go | StringValue | func (m *Mrb) StringValue(s string) *MrbValue {
cs := C.CString(s)
defer C.free(unsafe.Pointer(cs))
return newValue(m.state, C.mrb_str_new_cstr(m.state, cs))
} | go | func (m *Mrb) StringValue(s string) *MrbValue {
cs := C.CString(s)
defer C.free(unsafe.Pointer(cs))
return newValue(m.state, C.mrb_str_new_cstr(m.state, cs))
} | [
"func",
"(",
"m",
"*",
"Mrb",
")",
"StringValue",
"(",
"s",
"string",
")",
"*",
"MrbValue",
"{",
"cs",
":=",
"C",
".",
"CString",
"(",
"s",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"cs",
")",
")",
"\n",
"return",
"newValue",
"(",
"m",
".",
"state",
",",
"C",
".",
"mrb_str_new_cstr",
"(",
"m",
".",
"state",
",",
"cs",
")",
")",
"\n",
"}"
] | // StringValue returns a Value for a string. | [
"StringValue",
"returns",
"a",
"Value",
"for",
"a",
"string",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/mruby.go#L385-L389 |
10,438 | mitchellh/go-mruby | hash.go | Delete | func (h *Hash) Delete(key Value) (*MrbValue, error) {
keyVal := key.MrbValue(&Mrb{h.state}).value
result := C.mrb_hash_delete_key(h.state, h.value, keyVal)
val := newValue(h.state, result)
if val.Type() == TypeNil {
val = nil
}
return val, nil
} | go | func (h *Hash) Delete(key Value) (*MrbValue, error) {
keyVal := key.MrbValue(&Mrb{h.state}).value
result := C.mrb_hash_delete_key(h.state, h.value, keyVal)
val := newValue(h.state, result)
if val.Type() == TypeNil {
val = nil
}
return val, nil
} | [
"func",
"(",
"h",
"*",
"Hash",
")",
"Delete",
"(",
"key",
"Value",
")",
"(",
"*",
"MrbValue",
",",
"error",
")",
"{",
"keyVal",
":=",
"key",
".",
"MrbValue",
"(",
"&",
"Mrb",
"{",
"h",
".",
"state",
"}",
")",
".",
"value",
"\n",
"result",
":=",
"C",
".",
"mrb_hash_delete_key",
"(",
"h",
".",
"state",
",",
"h",
".",
"value",
",",
"keyVal",
")",
"\n\n",
"val",
":=",
"newValue",
"(",
"h",
".",
"state",
",",
"result",
")",
"\n",
"if",
"val",
".",
"Type",
"(",
")",
"==",
"TypeNil",
"{",
"val",
"=",
"nil",
"\n",
"}",
"\n\n",
"return",
"val",
",",
"nil",
"\n",
"}"
] | // Delete deletes a key from the hash, returning its existing value,
// or nil if there wasn't a value. | [
"Delete",
"deletes",
"a",
"key",
"from",
"the",
"hash",
"returning",
"its",
"existing",
"value",
"or",
"nil",
"if",
"there",
"wasn",
"t",
"a",
"value",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/hash.go#L15-L25 |
10,439 | mitchellh/go-mruby | hash.go | Get | func (h *Hash) Get(key Value) (*MrbValue, error) {
keyVal := key.MrbValue(&Mrb{h.state}).value
result := C.mrb_hash_get(h.state, h.value, keyVal)
return newValue(h.state, result), nil
} | go | func (h *Hash) Get(key Value) (*MrbValue, error) {
keyVal := key.MrbValue(&Mrb{h.state}).value
result := C.mrb_hash_get(h.state, h.value, keyVal)
return newValue(h.state, result), nil
} | [
"func",
"(",
"h",
"*",
"Hash",
")",
"Get",
"(",
"key",
"Value",
")",
"(",
"*",
"MrbValue",
",",
"error",
")",
"{",
"keyVal",
":=",
"key",
".",
"MrbValue",
"(",
"&",
"Mrb",
"{",
"h",
".",
"state",
"}",
")",
".",
"value",
"\n",
"result",
":=",
"C",
".",
"mrb_hash_get",
"(",
"h",
".",
"state",
",",
"h",
".",
"value",
",",
"keyVal",
")",
"\n",
"return",
"newValue",
"(",
"h",
".",
"state",
",",
"result",
")",
",",
"nil",
"\n",
"}"
] | // Get reads a value from the hash. | [
"Get",
"reads",
"a",
"value",
"from",
"the",
"hash",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/hash.go#L28-L32 |
10,440 | mitchellh/go-mruby | hash.go | Set | func (h *Hash) Set(key, val Value) error {
keyVal := key.MrbValue(&Mrb{h.state}).value
valVal := val.MrbValue(&Mrb{h.state}).value
C.mrb_hash_set(h.state, h.value, keyVal, valVal)
return nil
} | go | func (h *Hash) Set(key, val Value) error {
keyVal := key.MrbValue(&Mrb{h.state}).value
valVal := val.MrbValue(&Mrb{h.state}).value
C.mrb_hash_set(h.state, h.value, keyVal, valVal)
return nil
} | [
"func",
"(",
"h",
"*",
"Hash",
")",
"Set",
"(",
"key",
",",
"val",
"Value",
")",
"error",
"{",
"keyVal",
":=",
"key",
".",
"MrbValue",
"(",
"&",
"Mrb",
"{",
"h",
".",
"state",
"}",
")",
".",
"value",
"\n",
"valVal",
":=",
"val",
".",
"MrbValue",
"(",
"&",
"Mrb",
"{",
"h",
".",
"state",
"}",
")",
".",
"value",
"\n",
"C",
".",
"mrb_hash_set",
"(",
"h",
".",
"state",
",",
"h",
".",
"value",
",",
"keyVal",
",",
"valVal",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Set sets a value on the hash | [
"Set",
"sets",
"a",
"value",
"on",
"the",
"hash"
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/hash.go#L35-L40 |
10,441 | mitchellh/go-mruby | parser.go | NewParser | func NewParser(m *Mrb) *Parser {
p := C.mrb_parser_new(m.state)
// Set capture_errors to true so we don't go just printing things
// out to stdout.
C._go_mrb_parser_set_capture_errors(p, 1)
return &Parser{
mrb: m,
parser: p,
}
} | go | func NewParser(m *Mrb) *Parser {
p := C.mrb_parser_new(m.state)
// Set capture_errors to true so we don't go just printing things
// out to stdout.
C._go_mrb_parser_set_capture_errors(p, 1)
return &Parser{
mrb: m,
parser: p,
}
} | [
"func",
"NewParser",
"(",
"m",
"*",
"Mrb",
")",
"*",
"Parser",
"{",
"p",
":=",
"C",
".",
"mrb_parser_new",
"(",
"m",
".",
"state",
")",
"\n\n",
"// Set capture_errors to true so we don't go just printing things",
"// out to stdout.",
"C",
".",
"_go_mrb_parser_set_capture_errors",
"(",
"p",
",",
"1",
")",
"\n\n",
"return",
"&",
"Parser",
"{",
"mrb",
":",
"m",
",",
"parser",
":",
"p",
",",
"}",
"\n",
"}"
] | // NewParser initializes the resources for a parser.
//
// Make sure to Close the parser when you're done with it. | [
"NewParser",
"initializes",
"the",
"resources",
"for",
"a",
"parser",
".",
"Make",
"sure",
"to",
"Close",
"the",
"parser",
"when",
"you",
"re",
"done",
"with",
"it",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/parser.go#L23-L34 |
10,442 | mitchellh/go-mruby | parser.go | GenerateCode | func (p *Parser) GenerateCode() *MrbValue {
proc := C.mrb_generate_code(p.mrb.state, p.parser)
return newValue(p.mrb.state, C.mrb_obj_value(unsafe.Pointer(proc)))
} | go | func (p *Parser) GenerateCode() *MrbValue {
proc := C.mrb_generate_code(p.mrb.state, p.parser)
return newValue(p.mrb.state, C.mrb_obj_value(unsafe.Pointer(proc)))
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"GenerateCode",
"(",
")",
"*",
"MrbValue",
"{",
"proc",
":=",
"C",
".",
"mrb_generate_code",
"(",
"p",
".",
"mrb",
".",
"state",
",",
"p",
".",
"parser",
")",
"\n",
"return",
"newValue",
"(",
"p",
".",
"mrb",
".",
"state",
",",
"C",
".",
"mrb_obj_value",
"(",
"unsafe",
".",
"Pointer",
"(",
"proc",
")",
")",
")",
"\n",
"}"
] | // GenerateCode takes all the internal parser state and generates
// executable Ruby code, returning the callable proc. | [
"GenerateCode",
"takes",
"all",
"the",
"internal",
"parser",
"state",
"and",
"generates",
"executable",
"Ruby",
"code",
"returning",
"the",
"callable",
"proc",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/parser.go#L46-L49 |
10,443 | mitchellh/go-mruby | parser.go | Parse | func (p *Parser) Parse(code string, c *CompileContext) ([]*ParserMessage, error) {
// We set p.code so that the string doesn't get garbage collected
var s *C.char = C.CString(code)
p.code = code
p.parser.s = s
p.parser.send = C._go_mrb_calc_send(s)
var ctx *C.mrbc_context
if c != nil {
ctx = c.ctx
}
C.mrb_parser_parse(p.parser, ctx)
var warnings []*ParserMessage
if p.parser.nwarn > 0 {
nwarn := int(p.parser.nwarn)
warnings = make([]*ParserMessage, nwarn)
for i := 0; i < nwarn; i++ {
msg := p.parser.warn_buffer[i]
warnings[i] = &ParserMessage{
Col: int(msg.column),
Line: int(msg.lineno),
Message: C.GoString(msg.message),
}
}
}
if p.parser.nerr > 0 {
nerr := int(p.parser.nerr)
errors := make([]*ParserMessage, nerr)
for i := 0; i < nerr; i++ {
msg := p.parser.error_buffer[i]
errors[i] = &ParserMessage{
Col: int(msg.column),
Line: int(msg.lineno),
Message: C.GoString(msg.message),
}
}
return warnings, &ParserError{Errors: errors}
}
return warnings, nil
} | go | func (p *Parser) Parse(code string, c *CompileContext) ([]*ParserMessage, error) {
// We set p.code so that the string doesn't get garbage collected
var s *C.char = C.CString(code)
p.code = code
p.parser.s = s
p.parser.send = C._go_mrb_calc_send(s)
var ctx *C.mrbc_context
if c != nil {
ctx = c.ctx
}
C.mrb_parser_parse(p.parser, ctx)
var warnings []*ParserMessage
if p.parser.nwarn > 0 {
nwarn := int(p.parser.nwarn)
warnings = make([]*ParserMessage, nwarn)
for i := 0; i < nwarn; i++ {
msg := p.parser.warn_buffer[i]
warnings[i] = &ParserMessage{
Col: int(msg.column),
Line: int(msg.lineno),
Message: C.GoString(msg.message),
}
}
}
if p.parser.nerr > 0 {
nerr := int(p.parser.nerr)
errors := make([]*ParserMessage, nerr)
for i := 0; i < nerr; i++ {
msg := p.parser.error_buffer[i]
errors[i] = &ParserMessage{
Col: int(msg.column),
Line: int(msg.lineno),
Message: C.GoString(msg.message),
}
}
return warnings, &ParserError{Errors: errors}
}
return warnings, nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"Parse",
"(",
"code",
"string",
",",
"c",
"*",
"CompileContext",
")",
"(",
"[",
"]",
"*",
"ParserMessage",
",",
"error",
")",
"{",
"// We set p.code so that the string doesn't get garbage collected",
"var",
"s",
"*",
"C",
".",
"char",
"=",
"C",
".",
"CString",
"(",
"code",
")",
"\n",
"p",
".",
"code",
"=",
"code",
"\n",
"p",
".",
"parser",
".",
"s",
"=",
"s",
"\n",
"p",
".",
"parser",
".",
"send",
"=",
"C",
".",
"_go_mrb_calc_send",
"(",
"s",
")",
"\n\n",
"var",
"ctx",
"*",
"C",
".",
"mrbc_context",
"\n",
"if",
"c",
"!=",
"nil",
"{",
"ctx",
"=",
"c",
".",
"ctx",
"\n",
"}",
"\n",
"C",
".",
"mrb_parser_parse",
"(",
"p",
".",
"parser",
",",
"ctx",
")",
"\n\n",
"var",
"warnings",
"[",
"]",
"*",
"ParserMessage",
"\n",
"if",
"p",
".",
"parser",
".",
"nwarn",
">",
"0",
"{",
"nwarn",
":=",
"int",
"(",
"p",
".",
"parser",
".",
"nwarn",
")",
"\n",
"warnings",
"=",
"make",
"(",
"[",
"]",
"*",
"ParserMessage",
",",
"nwarn",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"nwarn",
";",
"i",
"++",
"{",
"msg",
":=",
"p",
".",
"parser",
".",
"warn_buffer",
"[",
"i",
"]",
"\n\n",
"warnings",
"[",
"i",
"]",
"=",
"&",
"ParserMessage",
"{",
"Col",
":",
"int",
"(",
"msg",
".",
"column",
")",
",",
"Line",
":",
"int",
"(",
"msg",
".",
"lineno",
")",
",",
"Message",
":",
"C",
".",
"GoString",
"(",
"msg",
".",
"message",
")",
",",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"p",
".",
"parser",
".",
"nerr",
">",
"0",
"{",
"nerr",
":=",
"int",
"(",
"p",
".",
"parser",
".",
"nerr",
")",
"\n",
"errors",
":=",
"make",
"(",
"[",
"]",
"*",
"ParserMessage",
",",
"nerr",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"nerr",
";",
"i",
"++",
"{",
"msg",
":=",
"p",
".",
"parser",
".",
"error_buffer",
"[",
"i",
"]",
"\n\n",
"errors",
"[",
"i",
"]",
"=",
"&",
"ParserMessage",
"{",
"Col",
":",
"int",
"(",
"msg",
".",
"column",
")",
",",
"Line",
":",
"int",
"(",
"msg",
".",
"lineno",
")",
",",
"Message",
":",
"C",
".",
"GoString",
"(",
"msg",
".",
"message",
")",
",",
"}",
"\n",
"}",
"\n\n",
"return",
"warnings",
",",
"&",
"ParserError",
"{",
"Errors",
":",
"errors",
"}",
"\n",
"}",
"\n\n",
"return",
"warnings",
",",
"nil",
"\n",
"}"
] | // Parse parses the code in the given context, and returns any warnings
// or errors from parsing.
//
// The CompileContext can be nil to not set a context. | [
"Parse",
"parses",
"the",
"code",
"in",
"the",
"given",
"context",
"and",
"returns",
"any",
"warnings",
"or",
"errors",
"from",
"parsing",
".",
"The",
"CompileContext",
"can",
"be",
"nil",
"to",
"not",
"set",
"a",
"context",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/parser.go#L55-L100 |
10,444 | mitchellh/go-mruby | args.go | ArgsArg | func ArgsArg(r, o int) ArgSpec {
return ArgSpec(C._go_MRB_ARGS_ARG(C.int(r), C.int(o)))
} | go | func ArgsArg(r, o int) ArgSpec {
return ArgSpec(C._go_MRB_ARGS_ARG(C.int(r), C.int(o)))
} | [
"func",
"ArgsArg",
"(",
"r",
",",
"o",
"int",
")",
"ArgSpec",
"{",
"return",
"ArgSpec",
"(",
"C",
".",
"_go_MRB_ARGS_ARG",
"(",
"C",
".",
"int",
"(",
"r",
")",
",",
"C",
".",
"int",
"(",
"o",
")",
")",
")",
"\n",
"}"
] | // ArgsArg says the given number of arguments are required and
// the second number is optional. | [
"ArgsArg",
"says",
"the",
"given",
"number",
"of",
"arguments",
"are",
"required",
"and",
"the",
"second",
"number",
"is",
"optional",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/args.go#L20-L22 |
10,445 | mitchellh/go-mruby | args.go | ArgsReq | func ArgsReq(n int) ArgSpec {
return ArgSpec(C._go_MRB_ARGS_REQ(C.int(n)))
} | go | func ArgsReq(n int) ArgSpec {
return ArgSpec(C._go_MRB_ARGS_REQ(C.int(n)))
} | [
"func",
"ArgsReq",
"(",
"n",
"int",
")",
"ArgSpec",
"{",
"return",
"ArgSpec",
"(",
"C",
".",
"_go_MRB_ARGS_REQ",
"(",
"C",
".",
"int",
"(",
"n",
")",
")",
")",
"\n",
"}"
] | // ArgsReq says that the given number of arguments are required. | [
"ArgsReq",
"says",
"that",
"the",
"given",
"number",
"of",
"arguments",
"are",
"required",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/args.go#L35-L37 |
10,446 | mitchellh/go-mruby | args.go | ArgsOpt | func ArgsOpt(n int) ArgSpec {
return ArgSpec(C._go_MRB_ARGS_OPT(C.int(n)))
} | go | func ArgsOpt(n int) ArgSpec {
return ArgSpec(C._go_MRB_ARGS_OPT(C.int(n)))
} | [
"func",
"ArgsOpt",
"(",
"n",
"int",
")",
"ArgSpec",
"{",
"return",
"ArgSpec",
"(",
"C",
".",
"_go_MRB_ARGS_OPT",
"(",
"C",
".",
"int",
"(",
"n",
")",
")",
")",
"\n",
"}"
] | // ArgsOpt says that the given number of arguments are optional. | [
"ArgsOpt",
"says",
"that",
"the",
"given",
"number",
"of",
"arguments",
"are",
"optional",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/args.go#L40-L42 |
10,447 | mitchellh/go-mruby | array.go | Len | func (v *Array) Len() int {
return int(C.mrb_ary_len(v.state, v.value))
} | go | func (v *Array) Len() int {
return int(C.mrb_ary_len(v.state, v.value))
} | [
"func",
"(",
"v",
"*",
"Array",
")",
"Len",
"(",
")",
"int",
"{",
"return",
"int",
"(",
"C",
".",
"mrb_ary_len",
"(",
"v",
".",
"state",
",",
"v",
".",
"value",
")",
")",
"\n",
"}"
] | // Len returns the length of the array. | [
"Len",
"returns",
"the",
"length",
"of",
"the",
"array",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/array.go#L14-L16 |
10,448 | mitchellh/go-mruby | decode.go | decodeStructHashGetter | func decodeStructHashGetter(mrb *Mrb, h *Hash) decodeStructGetter {
return func(key string) (*MrbValue, error) {
rbKey := mrb.StringValue(key)
return h.Get(rbKey)
}
} | go | func decodeStructHashGetter(mrb *Mrb, h *Hash) decodeStructGetter {
return func(key string) (*MrbValue, error) {
rbKey := mrb.StringValue(key)
return h.Get(rbKey)
}
} | [
"func",
"decodeStructHashGetter",
"(",
"mrb",
"*",
"Mrb",
",",
"h",
"*",
"Hash",
")",
"decodeStructGetter",
"{",
"return",
"func",
"(",
"key",
"string",
")",
"(",
"*",
"MrbValue",
",",
"error",
")",
"{",
"rbKey",
":=",
"mrb",
".",
"StringValue",
"(",
"key",
")",
"\n",
"return",
"h",
".",
"Get",
"(",
"rbKey",
")",
"\n",
"}",
"\n",
"}"
] | // decodeStructHashGetter is a decodeStructGetter that reads values from
// a hash. | [
"decodeStructHashGetter",
"is",
"a",
"decodeStructGetter",
"that",
"reads",
"values",
"from",
"a",
"hash",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/decode.go#L498-L503 |
10,449 | mitchellh/go-mruby | decode.go | decodeStructObjectMethods | func decodeStructObjectMethods(mrb *Mrb, v *MrbValue) decodeStructGetter {
return func(key string) (*MrbValue, error) {
return v.Call(key)
}
} | go | func decodeStructObjectMethods(mrb *Mrb, v *MrbValue) decodeStructGetter {
return func(key string) (*MrbValue, error) {
return v.Call(key)
}
} | [
"func",
"decodeStructObjectMethods",
"(",
"mrb",
"*",
"Mrb",
",",
"v",
"*",
"MrbValue",
")",
"decodeStructGetter",
"{",
"return",
"func",
"(",
"key",
"string",
")",
"(",
"*",
"MrbValue",
",",
"error",
")",
"{",
"return",
"v",
".",
"Call",
"(",
"key",
")",
"\n",
"}",
"\n",
"}"
] | // decodeStructObjectMethods is a decodeStructGetter that reads values from
// an object by calling methods. | [
"decodeStructObjectMethods",
"is",
"a",
"decodeStructGetter",
"that",
"reads",
"values",
"from",
"an",
"object",
"by",
"calling",
"methods",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/decode.go#L507-L511 |
10,450 | mitchellh/go-mruby | context.go | SetFilename | func (c *CompileContext) SetFilename(f string) {
c.filename = f
c.ctx.filename = C.CString(c.filename)
} | go | func (c *CompileContext) SetFilename(f string) {
c.filename = f
c.ctx.filename = C.CString(c.filename)
} | [
"func",
"(",
"c",
"*",
"CompileContext",
")",
"SetFilename",
"(",
"f",
"string",
")",
"{",
"c",
".",
"filename",
"=",
"f",
"\n",
"c",
".",
"ctx",
".",
"filename",
"=",
"C",
".",
"CString",
"(",
"c",
".",
"filename",
")",
"\n",
"}"
] | // SetFilename sets the filename associated with this compilation context.
//
// Code parsed under this context will be from this file. | [
"SetFilename",
"sets",
"the",
"filename",
"associated",
"with",
"this",
"compilation",
"context",
".",
"Code",
"parsed",
"under",
"this",
"context",
"will",
"be",
"from",
"this",
"file",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/context.go#L41-L44 |
10,451 | mitchellh/go-mruby | value.go | SetInstanceVariable | func (v *MrbValue) SetInstanceVariable(variable string, value *MrbValue) {
cs := C.CString(variable)
defer C.free(unsafe.Pointer(cs))
C._go_mrb_iv_set(v.state, v.value, C.mrb_intern_cstr(v.state, cs), value.value)
} | go | func (v *MrbValue) SetInstanceVariable(variable string, value *MrbValue) {
cs := C.CString(variable)
defer C.free(unsafe.Pointer(cs))
C._go_mrb_iv_set(v.state, v.value, C.mrb_intern_cstr(v.state, cs), value.value)
} | [
"func",
"(",
"v",
"*",
"MrbValue",
")",
"SetInstanceVariable",
"(",
"variable",
"string",
",",
"value",
"*",
"MrbValue",
")",
"{",
"cs",
":=",
"C",
".",
"CString",
"(",
"variable",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"cs",
")",
")",
"\n",
"C",
".",
"_go_mrb_iv_set",
"(",
"v",
".",
"state",
",",
"v",
".",
"value",
",",
"C",
".",
"mrb_intern_cstr",
"(",
"v",
".",
"state",
",",
"cs",
")",
",",
"value",
".",
"value",
")",
"\n",
"}"
] | // SetInstanceVariable sets an instance variable on this value. | [
"SetInstanceVariable",
"sets",
"an",
"instance",
"variable",
"on",
"this",
"value",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/value.go#L45-L49 |
10,452 | mitchellh/go-mruby | value.go | GetInstanceVariable | func (v *MrbValue) GetInstanceVariable(variable string) *MrbValue {
cs := C.CString(variable)
defer C.free(unsafe.Pointer(cs))
return newValue(v.state, C._go_mrb_iv_get(v.state, v.value, C.mrb_intern_cstr(v.state, cs)))
} | go | func (v *MrbValue) GetInstanceVariable(variable string) *MrbValue {
cs := C.CString(variable)
defer C.free(unsafe.Pointer(cs))
return newValue(v.state, C._go_mrb_iv_get(v.state, v.value, C.mrb_intern_cstr(v.state, cs)))
} | [
"func",
"(",
"v",
"*",
"MrbValue",
")",
"GetInstanceVariable",
"(",
"variable",
"string",
")",
"*",
"MrbValue",
"{",
"cs",
":=",
"C",
".",
"CString",
"(",
"variable",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"cs",
")",
")",
"\n",
"return",
"newValue",
"(",
"v",
".",
"state",
",",
"C",
".",
"_go_mrb_iv_get",
"(",
"v",
".",
"state",
",",
"v",
".",
"value",
",",
"C",
".",
"mrb_intern_cstr",
"(",
"v",
".",
"state",
",",
"cs",
")",
")",
")",
"\n",
"}"
] | // GetInstanceVariable gets an instance variable on this value. | [
"GetInstanceVariable",
"gets",
"an",
"instance",
"variable",
"on",
"this",
"value",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/value.go#L52-L56 |
10,453 | mitchellh/go-mruby | value.go | Call | func (v *MrbValue) Call(method string, args ...Value) (*MrbValue, error) {
return v.call(method, args, nil)
} | go | func (v *MrbValue) Call(method string, args ...Value) (*MrbValue, error) {
return v.call(method, args, nil)
} | [
"func",
"(",
"v",
"*",
"MrbValue",
")",
"Call",
"(",
"method",
"string",
",",
"args",
"...",
"Value",
")",
"(",
"*",
"MrbValue",
",",
"error",
")",
"{",
"return",
"v",
".",
"call",
"(",
"method",
",",
"args",
",",
"nil",
")",
"\n",
"}"
] | // Call calls a method with the given name and arguments on this
// value. | [
"Call",
"calls",
"a",
"method",
"with",
"the",
"given",
"name",
"and",
"arguments",
"on",
"this",
"value",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/value.go#L60-L62 |
10,454 | mitchellh/go-mruby | value.go | CallBlock | func (v *MrbValue) CallBlock(method string, args ...Value) (*MrbValue, error) {
if len(args) == 0 {
return nil, fmt.Errorf("args must be non-empty and have a proc at the end")
}
n := len(args)
return v.call(method, args[:n-1], args[n-1])
} | go | func (v *MrbValue) CallBlock(method string, args ...Value) (*MrbValue, error) {
if len(args) == 0 {
return nil, fmt.Errorf("args must be non-empty and have a proc at the end")
}
n := len(args)
return v.call(method, args[:n-1], args[n-1])
} | [
"func",
"(",
"v",
"*",
"MrbValue",
")",
"CallBlock",
"(",
"method",
"string",
",",
"args",
"...",
"Value",
")",
"(",
"*",
"MrbValue",
",",
"error",
")",
"{",
"if",
"len",
"(",
"args",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"n",
":=",
"len",
"(",
"args",
")",
"\n",
"return",
"v",
".",
"call",
"(",
"method",
",",
"args",
"[",
":",
"n",
"-",
"1",
"]",
",",
"args",
"[",
"n",
"-",
"1",
"]",
")",
"\n",
"}"
] | // CallBlock is the same as call except that it expects the last
// argument to be a Proc that will be passed into the function call.
// It is an error if args is empty or if there is no block on the end. | [
"CallBlock",
"is",
"the",
"same",
"as",
"call",
"except",
"that",
"it",
"expects",
"the",
"last",
"argument",
"to",
"be",
"a",
"Proc",
"that",
"will",
"be",
"passed",
"into",
"the",
"function",
"call",
".",
"It",
"is",
"an",
"error",
"if",
"args",
"is",
"empty",
"or",
"if",
"there",
"is",
"no",
"block",
"on",
"the",
"end",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/value.go#L67-L74 |
10,455 | mitchellh/go-mruby | value.go | IsDead | func (v *MrbValue) IsDead() bool {
return C.ushort(C._go_isdead(v.state, v.value)) != 0
} | go | func (v *MrbValue) IsDead() bool {
return C.ushort(C._go_isdead(v.state, v.value)) != 0
} | [
"func",
"(",
"v",
"*",
"MrbValue",
")",
"IsDead",
"(",
")",
"bool",
"{",
"return",
"C",
".",
"ushort",
"(",
"C",
".",
"_go_isdead",
"(",
"v",
".",
"state",
",",
"v",
".",
"value",
")",
")",
"!=",
"0",
"\n",
"}"
] | // IsDead tells you if an object has been collected by the GC or not. | [
"IsDead",
"tells",
"you",
"if",
"an",
"object",
"has",
"been",
"collected",
"by",
"the",
"GC",
"or",
"not",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/value.go#L119-L121 |
10,456 | mitchellh/go-mruby | value.go | SetProcTargetClass | func (v *MrbValue) SetProcTargetClass(c *Class) {
proc := C._go_mrb_proc_ptr(v.value)
proc.target_class = c.class
} | go | func (v *MrbValue) SetProcTargetClass(c *Class) {
proc := C._go_mrb_proc_ptr(v.value)
proc.target_class = c.class
} | [
"func",
"(",
"v",
"*",
"MrbValue",
")",
"SetProcTargetClass",
"(",
"c",
"*",
"Class",
")",
"{",
"proc",
":=",
"C",
".",
"_go_mrb_proc_ptr",
"(",
"v",
".",
"value",
")",
"\n",
"proc",
".",
"target_class",
"=",
"c",
".",
"class",
"\n",
"}"
] | // SetProcTargetClass sets the target class where a proc will be executed
// when this value is a proc. | [
"SetProcTargetClass",
"sets",
"the",
"target",
"class",
"where",
"a",
"proc",
"will",
"be",
"executed",
"when",
"this",
"value",
"is",
"a",
"proc",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/value.go#L140-L143 |
10,457 | mitchellh/go-mruby | value.go | Type | func (v *MrbValue) Type() ValueType {
if C._go_mrb_nil_p(v.value) == 1 {
return TypeNil
}
return ValueType(C._go_mrb_type(v.value))
} | go | func (v *MrbValue) Type() ValueType {
if C._go_mrb_nil_p(v.value) == 1 {
return TypeNil
}
return ValueType(C._go_mrb_type(v.value))
} | [
"func",
"(",
"v",
"*",
"MrbValue",
")",
"Type",
"(",
")",
"ValueType",
"{",
"if",
"C",
".",
"_go_mrb_nil_p",
"(",
"v",
".",
"value",
")",
"==",
"1",
"{",
"return",
"TypeNil",
"\n",
"}",
"\n\n",
"return",
"ValueType",
"(",
"C",
".",
"_go_mrb_type",
"(",
"v",
".",
"value",
")",
")",
"\n",
"}"
] | // Type returns the ValueType of the MrbValue. See the constants table. | [
"Type",
"returns",
"the",
"ValueType",
"of",
"the",
"MrbValue",
".",
"See",
"the",
"constants",
"table",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/value.go#L146-L152 |
10,458 | mitchellh/go-mruby | value.go | String | func (v *MrbValue) String() string {
value := C.mrb_obj_as_string(v.state, v.value)
result := C.GoString(C.mrb_string_value_ptr(v.state, value))
return result
} | go | func (v *MrbValue) String() string {
value := C.mrb_obj_as_string(v.state, v.value)
result := C.GoString(C.mrb_string_value_ptr(v.state, value))
return result
} | [
"func",
"(",
"v",
"*",
"MrbValue",
")",
"String",
"(",
")",
"string",
"{",
"value",
":=",
"C",
".",
"mrb_obj_as_string",
"(",
"v",
".",
"state",
",",
"v",
".",
"value",
")",
"\n",
"result",
":=",
"C",
".",
"GoString",
"(",
"C",
".",
"mrb_string_value_ptr",
"(",
"v",
".",
"state",
",",
"value",
")",
")",
"\n",
"return",
"result",
"\n",
"}"
] | // String returns the "to_s" result of this value. | [
"String",
"returns",
"the",
"to_s",
"result",
"of",
"this",
"value",
"."
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/value.go#L207-L211 |
10,459 | mitchellh/go-mruby | value.go | MrbValue | func (s String) MrbValue(m *Mrb) *MrbValue {
return m.StringValue(string(s))
} | go | func (s String) MrbValue(m *Mrb) *MrbValue {
return m.StringValue(string(s))
} | [
"func",
"(",
"s",
"String",
")",
"MrbValue",
"(",
"m",
"*",
"Mrb",
")",
"*",
"MrbValue",
"{",
"return",
"m",
".",
"StringValue",
"(",
"string",
"(",
"s",
")",
")",
"\n",
"}"
] | // MrbValue returns the native MRB value | [
"MrbValue",
"returns",
"the",
"native",
"MRB",
"value"
] | cd6a04a6ea57d3ecdf60ec703c927fb4984569ff | https://github.com/mitchellh/go-mruby/blob/cd6a04a6ea57d3ecdf60ec703c927fb4984569ff/value.go#L242-L244 |
10,460 | multiformats/go-multistream | client.go | SelectProtoOrFail | func SelectProtoOrFail(proto string, rwc io.ReadWriteCloser) error {
err := handshake(rwc)
if err != nil {
return err
}
return trySelect(proto, rwc)
} | go | func SelectProtoOrFail(proto string, rwc io.ReadWriteCloser) error {
err := handshake(rwc)
if err != nil {
return err
}
return trySelect(proto, rwc)
} | [
"func",
"SelectProtoOrFail",
"(",
"proto",
"string",
",",
"rwc",
"io",
".",
"ReadWriteCloser",
")",
"error",
"{",
"err",
":=",
"handshake",
"(",
"rwc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"trySelect",
"(",
"proto",
",",
"rwc",
")",
"\n",
"}"
] | // SelectProtoOrFail performs the initial multistream handshake
// to inform the muxer of the protocol that will be used to communicate
// on this ReadWriteCloser. It returns an error if, for example,
// the muxer does not know how to handle this protocol. | [
"SelectProtoOrFail",
"performs",
"the",
"initial",
"multistream",
"handshake",
"to",
"inform",
"the",
"muxer",
"of",
"the",
"protocol",
"that",
"will",
"be",
"used",
"to",
"communicate",
"on",
"this",
"ReadWriteCloser",
".",
"It",
"returns",
"an",
"error",
"if",
"for",
"example",
"the",
"muxer",
"does",
"not",
"know",
"how",
"to",
"handle",
"this",
"protocol",
"."
] | 7fe63401b47b8ee414fc16619e08a6abc1c5cf2b | https://github.com/multiformats/go-multistream/blob/7fe63401b47b8ee414fc16619e08a6abc1c5cf2b/client.go#L16-L23 |
10,461 | multiformats/go-multistream | client.go | SelectOneOf | func SelectOneOf(protos []string, rwc io.ReadWriteCloser) (string, error) {
err := handshake(rwc)
if err != nil {
return "", err
}
for _, p := range protos {
err := trySelect(p, rwc)
switch err {
case nil:
return p, nil
case ErrNotSupported:
default:
return "", err
}
}
return "", ErrNotSupported
} | go | func SelectOneOf(protos []string, rwc io.ReadWriteCloser) (string, error) {
err := handshake(rwc)
if err != nil {
return "", err
}
for _, p := range protos {
err := trySelect(p, rwc)
switch err {
case nil:
return p, nil
case ErrNotSupported:
default:
return "", err
}
}
return "", ErrNotSupported
} | [
"func",
"SelectOneOf",
"(",
"protos",
"[",
"]",
"string",
",",
"rwc",
"io",
".",
"ReadWriteCloser",
")",
"(",
"string",
",",
"error",
")",
"{",
"err",
":=",
"handshake",
"(",
"rwc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"p",
":=",
"range",
"protos",
"{",
"err",
":=",
"trySelect",
"(",
"p",
",",
"rwc",
")",
"\n",
"switch",
"err",
"{",
"case",
"nil",
":",
"return",
"p",
",",
"nil",
"\n",
"case",
"ErrNotSupported",
":",
"default",
":",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"ErrNotSupported",
"\n",
"}"
] | // SelectOneOf will perform handshakes with the protocols on the given slice
// until it finds one which is supported by the muxer. | [
"SelectOneOf",
"will",
"perform",
"handshakes",
"with",
"the",
"protocols",
"on",
"the",
"given",
"slice",
"until",
"it",
"finds",
"one",
"which",
"is",
"supported",
"by",
"the",
"muxer",
"."
] | 7fe63401b47b8ee414fc16619e08a6abc1c5cf2b | https://github.com/multiformats/go-multistream/blob/7fe63401b47b8ee414fc16619e08a6abc1c5cf2b/client.go#L27-L44 |
10,462 | multiformats/go-multistream | lazyClient.go | NewMSSelect | func NewMSSelect(c io.ReadWriteCloser, proto string) Multistream {
return &lazyClientConn{
protos: []string{ProtocolID, proto},
con: c,
}
} | go | func NewMSSelect(c io.ReadWriteCloser, proto string) Multistream {
return &lazyClientConn{
protos: []string{ProtocolID, proto},
con: c,
}
} | [
"func",
"NewMSSelect",
"(",
"c",
"io",
".",
"ReadWriteCloser",
",",
"proto",
"string",
")",
"Multistream",
"{",
"return",
"&",
"lazyClientConn",
"{",
"protos",
":",
"[",
"]",
"string",
"{",
"ProtocolID",
",",
"proto",
"}",
",",
"con",
":",
"c",
",",
"}",
"\n",
"}"
] | // NewMSSelect returns a new Multistream which is able to perform
// protocol selection with a MultistreamMuxer. | [
"NewMSSelect",
"returns",
"a",
"new",
"Multistream",
"which",
"is",
"able",
"to",
"perform",
"protocol",
"selection",
"with",
"a",
"MultistreamMuxer",
"."
] | 7fe63401b47b8ee414fc16619e08a6abc1c5cf2b | https://github.com/multiformats/go-multistream/blob/7fe63401b47b8ee414fc16619e08a6abc1c5cf2b/lazyClient.go#L19-L24 |
10,463 | multiformats/go-multistream | lazyClient.go | NewMultistream | func NewMultistream(c io.ReadWriteCloser, proto string) Multistream {
return &lazyClientConn{
protos: []string{proto},
con: c,
}
} | go | func NewMultistream(c io.ReadWriteCloser, proto string) Multistream {
return &lazyClientConn{
protos: []string{proto},
con: c,
}
} | [
"func",
"NewMultistream",
"(",
"c",
"io",
".",
"ReadWriteCloser",
",",
"proto",
"string",
")",
"Multistream",
"{",
"return",
"&",
"lazyClientConn",
"{",
"protos",
":",
"[",
"]",
"string",
"{",
"proto",
"}",
",",
"con",
":",
"c",
",",
"}",
"\n",
"}"
] | // NewMultistream returns a multistream for the given protocol. This will not
// perform any protocol selection. If you are using a MultistreamMuxer, use
// NewMSSelect. | [
"NewMultistream",
"returns",
"a",
"multistream",
"for",
"the",
"given",
"protocol",
".",
"This",
"will",
"not",
"perform",
"any",
"protocol",
"selection",
".",
"If",
"you",
"are",
"using",
"a",
"MultistreamMuxer",
"use",
"NewMSSelect",
"."
] | 7fe63401b47b8ee414fc16619e08a6abc1c5cf2b | https://github.com/multiformats/go-multistream/blob/7fe63401b47b8ee414fc16619e08a6abc1c5cf2b/lazyClient.go#L29-L34 |
10,464 | multiformats/go-multistream | lazyClient.go | Read | func (l *lazyClientConn) Read(b []byte) (int, error) {
l.rhandshakeOnce.Do(func() {
go l.whandshakeOnce.Do(l.doWriteHandshake)
l.doReadHandshake()
})
if l.rerr != nil {
return 0, l.rerr
}
if len(b) == 0 {
return 0, nil
}
return l.con.Read(b)
} | go | func (l *lazyClientConn) Read(b []byte) (int, error) {
l.rhandshakeOnce.Do(func() {
go l.whandshakeOnce.Do(l.doWriteHandshake)
l.doReadHandshake()
})
if l.rerr != nil {
return 0, l.rerr
}
if len(b) == 0 {
return 0, nil
}
return l.con.Read(b)
} | [
"func",
"(",
"l",
"*",
"lazyClientConn",
")",
"Read",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"l",
".",
"rhandshakeOnce",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"go",
"l",
".",
"whandshakeOnce",
".",
"Do",
"(",
"l",
".",
"doWriteHandshake",
")",
"\n",
"l",
".",
"doReadHandshake",
"(",
")",
"\n",
"}",
")",
"\n",
"if",
"l",
".",
"rerr",
"!=",
"nil",
"{",
"return",
"0",
",",
"l",
".",
"rerr",
"\n",
"}",
"\n",
"if",
"len",
"(",
"b",
")",
"==",
"0",
"{",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"l",
".",
"con",
".",
"Read",
"(",
"b",
")",
"\n",
"}"
] | // Read reads data from the io.ReadWriteCloser.
//
// If the protocol hasn't yet been negotiated, this method triggers the write
// half of the handshake and then waits for the read half to complete.
//
// It returns an error if the read half of the handshake fails. | [
"Read",
"reads",
"data",
"from",
"the",
"io",
".",
"ReadWriteCloser",
".",
"If",
"the",
"protocol",
"hasn",
"t",
"yet",
"been",
"negotiated",
"this",
"method",
"triggers",
"the",
"write",
"half",
"of",
"the",
"handshake",
"and",
"then",
"waits",
"for",
"the",
"read",
"half",
"to",
"complete",
".",
"It",
"returns",
"an",
"error",
"if",
"the",
"read",
"half",
"of",
"the",
"handshake",
"fails",
"."
] | 7fe63401b47b8ee414fc16619e08a6abc1c5cf2b | https://github.com/multiformats/go-multistream/blob/7fe63401b47b8ee414fc16619e08a6abc1c5cf2b/lazyClient.go#L64-L77 |
10,465 | multiformats/go-multistream | multistream.go | Ls | func Ls(rw io.ReadWriter) ([]string, error) {
err := delimWriteBuffered(rw, []byte("ls"))
if err != nil {
return nil, err
}
n, err := binary.ReadUvarint(&byteReader{rw})
if err != nil {
return nil, err
}
var out []string
for i := uint64(0); i < n; i++ {
val, err := lpReadBuf(rw)
if err != nil {
return nil, err
}
out = append(out, string(val))
}
return out, nil
} | go | func Ls(rw io.ReadWriter) ([]string, error) {
err := delimWriteBuffered(rw, []byte("ls"))
if err != nil {
return nil, err
}
n, err := binary.ReadUvarint(&byteReader{rw})
if err != nil {
return nil, err
}
var out []string
for i := uint64(0); i < n; i++ {
val, err := lpReadBuf(rw)
if err != nil {
return nil, err
}
out = append(out, string(val))
}
return out, nil
} | [
"func",
"Ls",
"(",
"rw",
"io",
".",
"ReadWriter",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"err",
":=",
"delimWriteBuffered",
"(",
"rw",
",",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"n",
",",
"err",
":=",
"binary",
".",
"ReadUvarint",
"(",
"&",
"byteReader",
"{",
"rw",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"out",
"[",
"]",
"string",
"\n",
"for",
"i",
":=",
"uint64",
"(",
"0",
")",
";",
"i",
"<",
"n",
";",
"i",
"++",
"{",
"val",
",",
"err",
":=",
"lpReadBuf",
"(",
"rw",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"out",
"=",
"append",
"(",
"out",
",",
"string",
"(",
"val",
")",
")",
"\n",
"}",
"\n\n",
"return",
"out",
",",
"nil",
"\n",
"}"
] | // Ls is a Multistream muxer command which returns the list of handler names
// available on a muxer. | [
"Ls",
"is",
"a",
"Multistream",
"muxer",
"command",
"which",
"returns",
"the",
"list",
"of",
"handler",
"names",
"available",
"on",
"a",
"muxer",
"."
] | 7fe63401b47b8ee414fc16619e08a6abc1c5cf2b | https://github.com/multiformats/go-multistream/blob/7fe63401b47b8ee414fc16619e08a6abc1c5cf2b/multistream.go#L87-L108 |
10,466 | multiformats/go-multistream | multistream.go | AddHandler | func (msm *MultistreamMuxer) AddHandler(protocol string, handler HandlerFunc) {
msm.AddHandlerWithFunc(protocol, fulltextMatch(protocol), handler)
} | go | func (msm *MultistreamMuxer) AddHandler(protocol string, handler HandlerFunc) {
msm.AddHandlerWithFunc(protocol, fulltextMatch(protocol), handler)
} | [
"func",
"(",
"msm",
"*",
"MultistreamMuxer",
")",
"AddHandler",
"(",
"protocol",
"string",
",",
"handler",
"HandlerFunc",
")",
"{",
"msm",
".",
"AddHandlerWithFunc",
"(",
"protocol",
",",
"fulltextMatch",
"(",
"protocol",
")",
",",
"handler",
")",
"\n",
"}"
] | // AddHandler attaches a new protocol handler to the muxer. | [
"AddHandler",
"attaches",
"a",
"new",
"protocol",
"handler",
"to",
"the",
"muxer",
"."
] | 7fe63401b47b8ee414fc16619e08a6abc1c5cf2b | https://github.com/multiformats/go-multistream/blob/7fe63401b47b8ee414fc16619e08a6abc1c5cf2b/multistream.go#L117-L119 |
10,467 | multiformats/go-multistream | multistream.go | AddHandlerWithFunc | func (msm *MultistreamMuxer) AddHandlerWithFunc(protocol string, match func(string) bool, handler HandlerFunc) {
msm.handlerlock.Lock()
defer msm.handlerlock.Unlock()
msm.removeHandler(protocol)
msm.handlers = append(msm.handlers, Handler{
MatchFunc: match,
Handle: handler,
AddName: protocol,
})
} | go | func (msm *MultistreamMuxer) AddHandlerWithFunc(protocol string, match func(string) bool, handler HandlerFunc) {
msm.handlerlock.Lock()
defer msm.handlerlock.Unlock()
msm.removeHandler(protocol)
msm.handlers = append(msm.handlers, Handler{
MatchFunc: match,
Handle: handler,
AddName: protocol,
})
} | [
"func",
"(",
"msm",
"*",
"MultistreamMuxer",
")",
"AddHandlerWithFunc",
"(",
"protocol",
"string",
",",
"match",
"func",
"(",
"string",
")",
"bool",
",",
"handler",
"HandlerFunc",
")",
"{",
"msm",
".",
"handlerlock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"msm",
".",
"handlerlock",
".",
"Unlock",
"(",
")",
"\n\n",
"msm",
".",
"removeHandler",
"(",
"protocol",
")",
"\n",
"msm",
".",
"handlers",
"=",
"append",
"(",
"msm",
".",
"handlers",
",",
"Handler",
"{",
"MatchFunc",
":",
"match",
",",
"Handle",
":",
"handler",
",",
"AddName",
":",
"protocol",
",",
"}",
")",
"\n",
"}"
] | // AddHandlerWithFunc attaches a new protocol handler to the muxer with a match.
// If the match function returns true for a given protocol tag, the protocol
// will be selected even if the handler name and protocol tags are different. | [
"AddHandlerWithFunc",
"attaches",
"a",
"new",
"protocol",
"handler",
"to",
"the",
"muxer",
"with",
"a",
"match",
".",
"If",
"the",
"match",
"function",
"returns",
"true",
"for",
"a",
"given",
"protocol",
"tag",
"the",
"protocol",
"will",
"be",
"selected",
"even",
"if",
"the",
"handler",
"name",
"and",
"protocol",
"tags",
"are",
"different",
"."
] | 7fe63401b47b8ee414fc16619e08a6abc1c5cf2b | https://github.com/multiformats/go-multistream/blob/7fe63401b47b8ee414fc16619e08a6abc1c5cf2b/multistream.go#L124-L134 |
10,468 | multiformats/go-multistream | multistream.go | RemoveHandler | func (msm *MultistreamMuxer) RemoveHandler(protocol string) {
msm.handlerlock.Lock()
defer msm.handlerlock.Unlock()
msm.removeHandler(protocol)
} | go | func (msm *MultistreamMuxer) RemoveHandler(protocol string) {
msm.handlerlock.Lock()
defer msm.handlerlock.Unlock()
msm.removeHandler(protocol)
} | [
"func",
"(",
"msm",
"*",
"MultistreamMuxer",
")",
"RemoveHandler",
"(",
"protocol",
"string",
")",
"{",
"msm",
".",
"handlerlock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"msm",
".",
"handlerlock",
".",
"Unlock",
"(",
")",
"\n\n",
"msm",
".",
"removeHandler",
"(",
"protocol",
")",
"\n",
"}"
] | // RemoveHandler removes the handler with the given name from the muxer. | [
"RemoveHandler",
"removes",
"the",
"handler",
"with",
"the",
"given",
"name",
"from",
"the",
"muxer",
"."
] | 7fe63401b47b8ee414fc16619e08a6abc1c5cf2b | https://github.com/multiformats/go-multistream/blob/7fe63401b47b8ee414fc16619e08a6abc1c5cf2b/multistream.go#L137-L142 |
10,469 | multiformats/go-multistream | multistream.go | Protocols | func (msm *MultistreamMuxer) Protocols() []string {
msm.handlerlock.RLock()
defer msm.handlerlock.RUnlock()
var out []string
for _, h := range msm.handlers {
out = append(out, h.AddName)
}
return out
} | go | func (msm *MultistreamMuxer) Protocols() []string {
msm.handlerlock.RLock()
defer msm.handlerlock.RUnlock()
var out []string
for _, h := range msm.handlers {
out = append(out, h.AddName)
}
return out
} | [
"func",
"(",
"msm",
"*",
"MultistreamMuxer",
")",
"Protocols",
"(",
")",
"[",
"]",
"string",
"{",
"msm",
".",
"handlerlock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"msm",
".",
"handlerlock",
".",
"RUnlock",
"(",
")",
"\n\n",
"var",
"out",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"h",
":=",
"range",
"msm",
".",
"handlers",
"{",
"out",
"=",
"append",
"(",
"out",
",",
"h",
".",
"AddName",
")",
"\n",
"}",
"\n\n",
"return",
"out",
"\n",
"}"
] | // Protocols returns the list of handler-names added to this this muxer. | [
"Protocols",
"returns",
"the",
"list",
"of",
"handler",
"-",
"names",
"added",
"to",
"this",
"this",
"muxer",
"."
] | 7fe63401b47b8ee414fc16619e08a6abc1c5cf2b | https://github.com/multiformats/go-multistream/blob/7fe63401b47b8ee414fc16619e08a6abc1c5cf2b/multistream.go#L154-L164 |
10,470 | multiformats/go-multistream | multistream.go | NegotiateLazy | func (msm *MultistreamMuxer) NegotiateLazy(rwc io.ReadWriteCloser) (Multistream, string, HandlerFunc, error) {
pval := make(chan string, 1)
writeErr := make(chan error, 1)
defer close(pval)
lzc := &lazyServerConn{
con: rwc,
}
started := make(chan struct{})
go lzc.waitForHandshake.Do(func() {
close(started)
defer close(writeErr)
if err := delimWriteBuffered(rwc, []byte(ProtocolID)); err != nil {
lzc.werr = err
writeErr <- err
return
}
for proto := range pval {
if err := delimWriteBuffered(rwc, []byte(proto)); err != nil {
lzc.werr = err
writeErr <- err
return
}
}
})
<-started
line, err := ReadNextToken(rwc)
if err != nil {
return nil, "", nil, err
}
if line != ProtocolID {
rwc.Close()
return nil, "", nil, ErrIncorrectVersion
}
loop:
for {
// Now read and respond to commands until they send a valid protocol id
tok, err := ReadNextToken(rwc)
if err != nil {
rwc.Close()
return nil, "", nil, err
}
switch tok {
case "ls":
select {
case pval <- "ls":
case err := <-writeErr:
rwc.Close()
return nil, "", nil, err
}
default:
h := msm.findHandler(tok)
if h == nil {
select {
case pval <- "na":
case err := <-writeErr:
rwc.Close()
return nil, "", nil, err
}
continue loop
}
select {
case pval <- tok:
case <-writeErr:
// explicitly ignore this error. It will be returned to any
// writers and if we don't plan on writing anything, we still
// want to complete the handshake
}
// hand off processing to the sub-protocol handler
return lzc, tok, h.Handle, nil
}
}
} | go | func (msm *MultistreamMuxer) NegotiateLazy(rwc io.ReadWriteCloser) (Multistream, string, HandlerFunc, error) {
pval := make(chan string, 1)
writeErr := make(chan error, 1)
defer close(pval)
lzc := &lazyServerConn{
con: rwc,
}
started := make(chan struct{})
go lzc.waitForHandshake.Do(func() {
close(started)
defer close(writeErr)
if err := delimWriteBuffered(rwc, []byte(ProtocolID)); err != nil {
lzc.werr = err
writeErr <- err
return
}
for proto := range pval {
if err := delimWriteBuffered(rwc, []byte(proto)); err != nil {
lzc.werr = err
writeErr <- err
return
}
}
})
<-started
line, err := ReadNextToken(rwc)
if err != nil {
return nil, "", nil, err
}
if line != ProtocolID {
rwc.Close()
return nil, "", nil, ErrIncorrectVersion
}
loop:
for {
// Now read and respond to commands until they send a valid protocol id
tok, err := ReadNextToken(rwc)
if err != nil {
rwc.Close()
return nil, "", nil, err
}
switch tok {
case "ls":
select {
case pval <- "ls":
case err := <-writeErr:
rwc.Close()
return nil, "", nil, err
}
default:
h := msm.findHandler(tok)
if h == nil {
select {
case pval <- "na":
case err := <-writeErr:
rwc.Close()
return nil, "", nil, err
}
continue loop
}
select {
case pval <- tok:
case <-writeErr:
// explicitly ignore this error. It will be returned to any
// writers and if we don't plan on writing anything, we still
// want to complete the handshake
}
// hand off processing to the sub-protocol handler
return lzc, tok, h.Handle, nil
}
}
} | [
"func",
"(",
"msm",
"*",
"MultistreamMuxer",
")",
"NegotiateLazy",
"(",
"rwc",
"io",
".",
"ReadWriteCloser",
")",
"(",
"Multistream",
",",
"string",
",",
"HandlerFunc",
",",
"error",
")",
"{",
"pval",
":=",
"make",
"(",
"chan",
"string",
",",
"1",
")",
"\n",
"writeErr",
":=",
"make",
"(",
"chan",
"error",
",",
"1",
")",
"\n",
"defer",
"close",
"(",
"pval",
")",
"\n\n",
"lzc",
":=",
"&",
"lazyServerConn",
"{",
"con",
":",
"rwc",
",",
"}",
"\n\n",
"started",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"go",
"lzc",
".",
"waitForHandshake",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"close",
"(",
"started",
")",
"\n\n",
"defer",
"close",
"(",
"writeErr",
")",
"\n\n",
"if",
"err",
":=",
"delimWriteBuffered",
"(",
"rwc",
",",
"[",
"]",
"byte",
"(",
"ProtocolID",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"lzc",
".",
"werr",
"=",
"err",
"\n",
"writeErr",
"<-",
"err",
"\n",
"return",
"\n",
"}",
"\n\n",
"for",
"proto",
":=",
"range",
"pval",
"{",
"if",
"err",
":=",
"delimWriteBuffered",
"(",
"rwc",
",",
"[",
"]",
"byte",
"(",
"proto",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"lzc",
".",
"werr",
"=",
"err",
"\n",
"writeErr",
"<-",
"err",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}",
")",
"\n",
"<-",
"started",
"\n\n",
"line",
",",
"err",
":=",
"ReadNextToken",
"(",
"rwc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"\"",
"\"",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"line",
"!=",
"ProtocolID",
"{",
"rwc",
".",
"Close",
"(",
")",
"\n",
"return",
"nil",
",",
"\"",
"\"",
",",
"nil",
",",
"ErrIncorrectVersion",
"\n",
"}",
"\n\n",
"loop",
":",
"for",
"{",
"// Now read and respond to commands until they send a valid protocol id",
"tok",
",",
"err",
":=",
"ReadNextToken",
"(",
"rwc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"rwc",
".",
"Close",
"(",
")",
"\n",
"return",
"nil",
",",
"\"",
"\"",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"switch",
"tok",
"{",
"case",
"\"",
"\"",
":",
"select",
"{",
"case",
"pval",
"<-",
"\"",
"\"",
":",
"case",
"err",
":=",
"<-",
"writeErr",
":",
"rwc",
".",
"Close",
"(",
")",
"\n",
"return",
"nil",
",",
"\"",
"\"",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"default",
":",
"h",
":=",
"msm",
".",
"findHandler",
"(",
"tok",
")",
"\n",
"if",
"h",
"==",
"nil",
"{",
"select",
"{",
"case",
"pval",
"<-",
"\"",
"\"",
":",
"case",
"err",
":=",
"<-",
"writeErr",
":",
"rwc",
".",
"Close",
"(",
")",
"\n",
"return",
"nil",
",",
"\"",
"\"",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"continue",
"loop",
"\n",
"}",
"\n\n",
"select",
"{",
"case",
"pval",
"<-",
"tok",
":",
"case",
"<-",
"writeErr",
":",
"// explicitly ignore this error. It will be returned to any",
"// writers and if we don't plan on writing anything, we still",
"// want to complete the handshake",
"}",
"\n\n",
"// hand off processing to the sub-protocol handler",
"return",
"lzc",
",",
"tok",
",",
"h",
".",
"Handle",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // NegotiateLazy performs protocol selection and returns
// a multistream, the protocol used, the handler and an error. It is lazy
// because the write-handshake is performed on a subroutine, allowing this
// to return before that handshake is completed. | [
"NegotiateLazy",
"performs",
"protocol",
"selection",
"and",
"returns",
"a",
"multistream",
"the",
"protocol",
"used",
"the",
"handler",
"and",
"an",
"error",
".",
"It",
"is",
"lazy",
"because",
"the",
"write",
"-",
"handshake",
"is",
"performed",
"on",
"a",
"subroutine",
"allowing",
"this",
"to",
"return",
"before",
"that",
"handshake",
"is",
"completed",
"."
] | 7fe63401b47b8ee414fc16619e08a6abc1c5cf2b | https://github.com/multiformats/go-multistream/blob/7fe63401b47b8ee414fc16619e08a6abc1c5cf2b/multistream.go#L187-L269 |
10,471 | multiformats/go-multistream | multistream.go | Ls | func (msm *MultistreamMuxer) Ls(w io.Writer) error {
buf := new(bytes.Buffer)
msm.handlerlock.RLock()
err := writeUvarint(buf, uint64(len(msm.handlers)))
if err != nil {
return err
}
for _, h := range msm.handlers {
err := delimWrite(buf, []byte(h.AddName))
if err != nil {
msm.handlerlock.RUnlock()
return err
}
}
msm.handlerlock.RUnlock()
ll := make([]byte, 16)
nw := binary.PutUvarint(ll, uint64(buf.Len()))
r := io.MultiReader(bytes.NewReader(ll[:nw]), buf)
_, err = io.Copy(w, r)
return err
} | go | func (msm *MultistreamMuxer) Ls(w io.Writer) error {
buf := new(bytes.Buffer)
msm.handlerlock.RLock()
err := writeUvarint(buf, uint64(len(msm.handlers)))
if err != nil {
return err
}
for _, h := range msm.handlers {
err := delimWrite(buf, []byte(h.AddName))
if err != nil {
msm.handlerlock.RUnlock()
return err
}
}
msm.handlerlock.RUnlock()
ll := make([]byte, 16)
nw := binary.PutUvarint(ll, uint64(buf.Len()))
r := io.MultiReader(bytes.NewReader(ll[:nw]), buf)
_, err = io.Copy(w, r)
return err
} | [
"func",
"(",
"msm",
"*",
"MultistreamMuxer",
")",
"Ls",
"(",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"buf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n\n",
"msm",
".",
"handlerlock",
".",
"RLock",
"(",
")",
"\n",
"err",
":=",
"writeUvarint",
"(",
"buf",
",",
"uint64",
"(",
"len",
"(",
"msm",
".",
"handlers",
")",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"h",
":=",
"range",
"msm",
".",
"handlers",
"{",
"err",
":=",
"delimWrite",
"(",
"buf",
",",
"[",
"]",
"byte",
"(",
"h",
".",
"AddName",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"msm",
".",
"handlerlock",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"msm",
".",
"handlerlock",
".",
"RUnlock",
"(",
")",
"\n\n",
"ll",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"16",
")",
"\n",
"nw",
":=",
"binary",
".",
"PutUvarint",
"(",
"ll",
",",
"uint64",
"(",
"buf",
".",
"Len",
"(",
")",
")",
")",
"\n\n",
"r",
":=",
"io",
".",
"MultiReader",
"(",
"bytes",
".",
"NewReader",
"(",
"ll",
"[",
":",
"nw",
"]",
")",
",",
"buf",
")",
"\n\n",
"_",
",",
"err",
"=",
"io",
".",
"Copy",
"(",
"w",
",",
"r",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Ls implements the "ls" command which writes the list of
// supported protocols to the given Writer. | [
"Ls",
"implements",
"the",
"ls",
"command",
"which",
"writes",
"the",
"list",
"of",
"supported",
"protocols",
"to",
"the",
"given",
"Writer",
"."
] | 7fe63401b47b8ee414fc16619e08a6abc1c5cf2b | https://github.com/multiformats/go-multistream/blob/7fe63401b47b8ee414fc16619e08a6abc1c5cf2b/multistream.go#L328-L353 |
10,472 | multiformats/go-multistream | multistream.go | ReadNextToken | func ReadNextToken(rw io.ReadWriter) (string, error) {
tok, err := ReadNextTokenBytes(rw)
if err != nil {
return "", err
}
return string(tok), nil
} | go | func ReadNextToken(rw io.ReadWriter) (string, error) {
tok, err := ReadNextTokenBytes(rw)
if err != nil {
return "", err
}
return string(tok), nil
} | [
"func",
"ReadNextToken",
"(",
"rw",
"io",
".",
"ReadWriter",
")",
"(",
"string",
",",
"error",
")",
"{",
"tok",
",",
"err",
":=",
"ReadNextTokenBytes",
"(",
"rw",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"string",
"(",
"tok",
")",
",",
"nil",
"\n",
"}"
] | // ReadNextToken extracts a token from a ReadWriter. It is used during
// protocol negotiation and returns a string. | [
"ReadNextToken",
"extracts",
"a",
"token",
"from",
"a",
"ReadWriter",
".",
"It",
"is",
"used",
"during",
"protocol",
"negotiation",
"and",
"returns",
"a",
"string",
"."
] | 7fe63401b47b8ee414fc16619e08a6abc1c5cf2b | https://github.com/multiformats/go-multistream/blob/7fe63401b47b8ee414fc16619e08a6abc1c5cf2b/multistream.go#L368-L375 |
10,473 | multiformats/go-multistream | multistream.go | ReadNextTokenBytes | func ReadNextTokenBytes(rw io.ReadWriter) ([]byte, error) {
data, err := lpReadBuf(rw)
switch err {
case nil:
return data, nil
case ErrTooLarge:
err := delimWriteBuffered(rw, []byte("messages over 64k are not allowed"))
if err != nil {
return nil, err
}
return nil, ErrTooLarge
default:
return nil, err
}
} | go | func ReadNextTokenBytes(rw io.ReadWriter) ([]byte, error) {
data, err := lpReadBuf(rw)
switch err {
case nil:
return data, nil
case ErrTooLarge:
err := delimWriteBuffered(rw, []byte("messages over 64k are not allowed"))
if err != nil {
return nil, err
}
return nil, ErrTooLarge
default:
return nil, err
}
} | [
"func",
"ReadNextTokenBytes",
"(",
"rw",
"io",
".",
"ReadWriter",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"lpReadBuf",
"(",
"rw",
")",
"\n",
"switch",
"err",
"{",
"case",
"nil",
":",
"return",
"data",
",",
"nil",
"\n",
"case",
"ErrTooLarge",
":",
"err",
":=",
"delimWriteBuffered",
"(",
"rw",
",",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"nil",
",",
"ErrTooLarge",
"\n",
"default",
":",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}"
] | // ReadNextTokenBytes extracts a token from a ReadWriter. It is used
// during protocol negotiation and returns a byte slice. | [
"ReadNextTokenBytes",
"extracts",
"a",
"token",
"from",
"a",
"ReadWriter",
".",
"It",
"is",
"used",
"during",
"protocol",
"negotiation",
"and",
"returns",
"a",
"byte",
"slice",
"."
] | 7fe63401b47b8ee414fc16619e08a6abc1c5cf2b | https://github.com/multiformats/go-multistream/blob/7fe63401b47b8ee414fc16619e08a6abc1c5cf2b/multistream.go#L379-L393 |
10,474 | kataras/go-template | loader.go | Directory | func (t *Loader) Directory(dir string, fileExtension string) *BinaryLoader {
if dir == "" {
dir = DefaultDirectory // the default templates dir
}
if fileExtension == "" {
fileExtension = DefaultExtension
} else if fileExtension[0] != '.' { // if missing the start dot
fileExtension = "." + fileExtension
}
t.Dir = dir
t.Extension = fileExtension
return &BinaryLoader{Loader: t}
} | go | func (t *Loader) Directory(dir string, fileExtension string) *BinaryLoader {
if dir == "" {
dir = DefaultDirectory // the default templates dir
}
if fileExtension == "" {
fileExtension = DefaultExtension
} else if fileExtension[0] != '.' { // if missing the start dot
fileExtension = "." + fileExtension
}
t.Dir = dir
t.Extension = fileExtension
return &BinaryLoader{Loader: t}
} | [
"func",
"(",
"t",
"*",
"Loader",
")",
"Directory",
"(",
"dir",
"string",
",",
"fileExtension",
"string",
")",
"*",
"BinaryLoader",
"{",
"if",
"dir",
"==",
"\"",
"\"",
"{",
"dir",
"=",
"DefaultDirectory",
"// the default templates dir",
"\n",
"}",
"\n",
"if",
"fileExtension",
"==",
"\"",
"\"",
"{",
"fileExtension",
"=",
"DefaultExtension",
"\n",
"}",
"else",
"if",
"fileExtension",
"[",
"0",
"]",
"!=",
"'.'",
"{",
"// if missing the start dot",
"fileExtension",
"=",
"\"",
"\"",
"+",
"fileExtension",
"\n",
"}",
"\n\n",
"t",
".",
"Dir",
"=",
"dir",
"\n",
"t",
".",
"Extension",
"=",
"fileExtension",
"\n\n",
"return",
"&",
"BinaryLoader",
"{",
"Loader",
":",
"t",
"}",
"\n",
"}"
] | // Directory sets the directory to load from
// returns the Binary location which is optional | [
"Directory",
"sets",
"the",
"directory",
"to",
"load",
"from",
"returns",
"the",
"Binary",
"location",
"which",
"is",
"optional"
] | a4a986b413e8d88ebd894b4a3e327314069f2439 | https://github.com/kataras/go-template/blob/a4a986b413e8d88ebd894b4a3e327314069f2439/loader.go#L40-L54 |
10,475 | kataras/go-template | loader.go | Binary | func (t *BinaryLoader) Binary(assetFn func(name string) ([]byte, error), namesFn func() []string) {
if assetFn == nil || namesFn == nil {
return
}
t.AssetFn = assetFn
t.NamesFn = namesFn
// if extension is not static(setted by .Directory)
if t.Extension == "" {
if names := namesFn(); len(names) > 0 {
t.Extension = filepath.Ext(names[0]) // we need the extension to get the correct template engine on the Render method
}
}
} | go | func (t *BinaryLoader) Binary(assetFn func(name string) ([]byte, error), namesFn func() []string) {
if assetFn == nil || namesFn == nil {
return
}
t.AssetFn = assetFn
t.NamesFn = namesFn
// if extension is not static(setted by .Directory)
if t.Extension == "" {
if names := namesFn(); len(names) > 0 {
t.Extension = filepath.Ext(names[0]) // we need the extension to get the correct template engine on the Render method
}
}
} | [
"func",
"(",
"t",
"*",
"BinaryLoader",
")",
"Binary",
"(",
"assetFn",
"func",
"(",
"name",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
",",
"namesFn",
"func",
"(",
")",
"[",
"]",
"string",
")",
"{",
"if",
"assetFn",
"==",
"nil",
"||",
"namesFn",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"t",
".",
"AssetFn",
"=",
"assetFn",
"\n",
"t",
".",
"NamesFn",
"=",
"namesFn",
"\n",
"// if extension is not static(setted by .Directory)",
"if",
"t",
".",
"Extension",
"==",
"\"",
"\"",
"{",
"if",
"names",
":=",
"namesFn",
"(",
")",
";",
"len",
"(",
"names",
")",
">",
"0",
"{",
"t",
".",
"Extension",
"=",
"filepath",
".",
"Ext",
"(",
"names",
"[",
"0",
"]",
")",
"// we need the extension to get the correct template engine on the Render method",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Binary optionally, called after Loader.Directory, used when files are distributed inside the app executable
// sets the AssetFn and NamesFn | [
"Binary",
"optionally",
"called",
"after",
"Loader",
".",
"Directory",
"used",
"when",
"files",
"are",
"distributed",
"inside",
"the",
"app",
"executable",
"sets",
"the",
"AssetFn",
"and",
"NamesFn"
] | a4a986b413e8d88ebd894b4a3e327314069f2439 | https://github.com/kataras/go-template/blob/a4a986b413e8d88ebd894b4a3e327314069f2439/loader.go#L58-L71 |
10,476 | kataras/go-template | loader.go | IsBinary | func (t *Loader) IsBinary() bool {
return t.AssetFn != nil && t.NamesFn != nil
} | go | func (t *Loader) IsBinary() bool {
return t.AssetFn != nil && t.NamesFn != nil
} | [
"func",
"(",
"t",
"*",
"Loader",
")",
"IsBinary",
"(",
")",
"bool",
"{",
"return",
"t",
".",
"AssetFn",
"!=",
"nil",
"&&",
"t",
".",
"NamesFn",
"!=",
"nil",
"\n",
"}"
] | // IsBinary returns true if .Binary is called and AssetFn and NamesFn are setted | [
"IsBinary",
"returns",
"true",
"if",
".",
"Binary",
"is",
"called",
"and",
"AssetFn",
"and",
"NamesFn",
"are",
"setted"
] | a4a986b413e8d88ebd894b4a3e327314069f2439 | https://github.com/kataras/go-template/blob/a4a986b413e8d88ebd894b4a3e327314069f2439/loader.go#L74-L76 |
10,477 | kataras/go-template | loader.go | LoadEngine | func (t *Loader) LoadEngine(e Engine) error {
if t.Dir == "" {
return errMissingDirectoryOrAssets
}
if t.IsBinary() {
// don't try to put abs path here
// fixes: http://support.iris-go.com/d/22-template-binary-problem-in-v6
return e.LoadAssets(t.Dir, t.Extension, t.AssetFn, t.NamesFn)
}
// fixes when user tries to execute the binary from a temp location while the templates are relatively located
absDir, err := filepath.Abs(t.Dir)
// panic here of course.
if err != nil {
panic("couldn't find the dir in the relative dir: '" + t.Dir +
"' neither as absolute: '" + absDir + "'\n" + err.Error())
}
return e.LoadDirectory(absDir, t.Extension)
} | go | func (t *Loader) LoadEngine(e Engine) error {
if t.Dir == "" {
return errMissingDirectoryOrAssets
}
if t.IsBinary() {
// don't try to put abs path here
// fixes: http://support.iris-go.com/d/22-template-binary-problem-in-v6
return e.LoadAssets(t.Dir, t.Extension, t.AssetFn, t.NamesFn)
}
// fixes when user tries to execute the binary from a temp location while the templates are relatively located
absDir, err := filepath.Abs(t.Dir)
// panic here of course.
if err != nil {
panic("couldn't find the dir in the relative dir: '" + t.Dir +
"' neither as absolute: '" + absDir + "'\n" + err.Error())
}
return e.LoadDirectory(absDir, t.Extension)
} | [
"func",
"(",
"t",
"*",
"Loader",
")",
"LoadEngine",
"(",
"e",
"Engine",
")",
"error",
"{",
"if",
"t",
".",
"Dir",
"==",
"\"",
"\"",
"{",
"return",
"errMissingDirectoryOrAssets",
"\n",
"}",
"\n\n",
"if",
"t",
".",
"IsBinary",
"(",
")",
"{",
"// don't try to put abs path here",
"// fixes: http://support.iris-go.com/d/22-template-binary-problem-in-v6",
"return",
"e",
".",
"LoadAssets",
"(",
"t",
".",
"Dir",
",",
"t",
".",
"Extension",
",",
"t",
".",
"AssetFn",
",",
"t",
".",
"NamesFn",
")",
"\n",
"}",
"\n\n",
"// fixes when user tries to execute the binary from a temp location while the templates are relatively located",
"absDir",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"t",
".",
"Dir",
")",
"\n",
"// panic here of course.",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
"+",
"t",
".",
"Dir",
"+",
"\"",
"\"",
"+",
"absDir",
"+",
"\"",
"\\n",
"\"",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"e",
".",
"LoadDirectory",
"(",
"absDir",
",",
"t",
".",
"Extension",
")",
"\n",
"}"
] | // LoadEngine receives a template Engine and calls its LoadAssets or the LoadDirectory with the loader's locations | [
"LoadEngine",
"receives",
"a",
"template",
"Engine",
"and",
"calls",
"its",
"LoadAssets",
"or",
"the",
"LoadDirectory",
"with",
"the",
"loader",
"s",
"locations"
] | a4a986b413e8d88ebd894b4a3e327314069f2439 | https://github.com/kataras/go-template/blob/a4a986b413e8d88ebd894b4a3e327314069f2439/loader.go#L81-L100 |
10,478 | kataras/go-template | handlebars/handlebars.go | New | func New(cfg ...Config) *Engine {
c := DefaultConfig()
if len(cfg) > 0 {
c = cfg[0]
}
// cuz mergo has a little bug on maps
if c.Helpers == nil {
c.Helpers = make(map[string]interface{}, 0)
}
e := &Engine{Config: c, templateCache: make(map[string]*raymond.Template, 0)}
raymond.RegisterHelper("render", func(partial string, binding interface{}) raymond.SafeString {
contents, err := e.executeTemplateBuf(partial, binding)
if err != nil {
return raymond.SafeString("Template with name: " + partial + " couldn't not be found.")
}
return raymond.SafeString(contents)
})
return e
} | go | func New(cfg ...Config) *Engine {
c := DefaultConfig()
if len(cfg) > 0 {
c = cfg[0]
}
// cuz mergo has a little bug on maps
if c.Helpers == nil {
c.Helpers = make(map[string]interface{}, 0)
}
e := &Engine{Config: c, templateCache: make(map[string]*raymond.Template, 0)}
raymond.RegisterHelper("render", func(partial string, binding interface{}) raymond.SafeString {
contents, err := e.executeTemplateBuf(partial, binding)
if err != nil {
return raymond.SafeString("Template with name: " + partial + " couldn't not be found.")
}
return raymond.SafeString(contents)
})
return e
} | [
"func",
"New",
"(",
"cfg",
"...",
"Config",
")",
"*",
"Engine",
"{",
"c",
":=",
"DefaultConfig",
"(",
")",
"\n",
"if",
"len",
"(",
"cfg",
")",
">",
"0",
"{",
"c",
"=",
"cfg",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"// cuz mergo has a little bug on maps",
"if",
"c",
".",
"Helpers",
"==",
"nil",
"{",
"c",
".",
"Helpers",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"0",
")",
"\n",
"}",
"\n\n",
"e",
":=",
"&",
"Engine",
"{",
"Config",
":",
"c",
",",
"templateCache",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"raymond",
".",
"Template",
",",
"0",
")",
"}",
"\n\n",
"raymond",
".",
"RegisterHelper",
"(",
"\"",
"\"",
",",
"func",
"(",
"partial",
"string",
",",
"binding",
"interface",
"{",
"}",
")",
"raymond",
".",
"SafeString",
"{",
"contents",
",",
"err",
":=",
"e",
".",
"executeTemplateBuf",
"(",
"partial",
",",
"binding",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"raymond",
".",
"SafeString",
"(",
"\"",
"\"",
"+",
"partial",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"raymond",
".",
"SafeString",
"(",
"contents",
")",
"\n",
"}",
")",
"\n\n",
"return",
"e",
"\n",
"}"
] | // New creates and returns the Handlebars template engine | [
"New",
"creates",
"and",
"returns",
"the",
"Handlebars",
"template",
"engine"
] | a4a986b413e8d88ebd894b4a3e327314069f2439 | https://github.com/kataras/go-template/blob/a4a986b413e8d88ebd894b4a3e327314069f2439/handlebars/handlebars.go#L31-L53 |
10,479 | kataras/go-template | handlebars/handlebars.go | LoadDirectory | func (e *Engine) LoadDirectory(dir string, extension string) error {
// register the global helpers on the first load
if len(e.templateCache) == 0 && e.Config.Helpers != nil {
raymond.RegisterHelpers(e.Config.Helpers)
}
// the render works like {{ render "myfile.html" theContext.PartialContext}}
// instead of the html/template engine which works like {{ render "myfile.html"}} and accepts the parent binding, with handlebars we can't do that because of lack of runtime helpers (dublicate error)
e.mu.Lock()
defer e.mu.Unlock()
var templateErr error
filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if info == nil || info.IsDir() {
return nil
}
rel, err := filepath.Rel(dir, path)
if err != nil {
return err
}
ext := filepath.Ext(rel)
if ext == extension {
buf, err := ioutil.ReadFile(path)
contents := string(buf)
if err != nil {
templateErr = err
return err
}
name := filepath.ToSlash(rel)
tmpl, err := raymond.Parse(contents)
if err != nil {
templateErr = err
return err
}
e.templateCache[name] = tmpl
}
return nil
})
return templateErr
} | go | func (e *Engine) LoadDirectory(dir string, extension string) error {
// register the global helpers on the first load
if len(e.templateCache) == 0 && e.Config.Helpers != nil {
raymond.RegisterHelpers(e.Config.Helpers)
}
// the render works like {{ render "myfile.html" theContext.PartialContext}}
// instead of the html/template engine which works like {{ render "myfile.html"}} and accepts the parent binding, with handlebars we can't do that because of lack of runtime helpers (dublicate error)
e.mu.Lock()
defer e.mu.Unlock()
var templateErr error
filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if info == nil || info.IsDir() {
return nil
}
rel, err := filepath.Rel(dir, path)
if err != nil {
return err
}
ext := filepath.Ext(rel)
if ext == extension {
buf, err := ioutil.ReadFile(path)
contents := string(buf)
if err != nil {
templateErr = err
return err
}
name := filepath.ToSlash(rel)
tmpl, err := raymond.Parse(contents)
if err != nil {
templateErr = err
return err
}
e.templateCache[name] = tmpl
}
return nil
})
return templateErr
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"LoadDirectory",
"(",
"dir",
"string",
",",
"extension",
"string",
")",
"error",
"{",
"// register the global helpers on the first load",
"if",
"len",
"(",
"e",
".",
"templateCache",
")",
"==",
"0",
"&&",
"e",
".",
"Config",
".",
"Helpers",
"!=",
"nil",
"{",
"raymond",
".",
"RegisterHelpers",
"(",
"e",
".",
"Config",
".",
"Helpers",
")",
"\n\n",
"}",
"\n\n",
"// the render works like {{ render \"myfile.html\" theContext.PartialContext}}",
"// instead of the html/template engine which works like {{ render \"myfile.html\"}} and accepts the parent binding, with handlebars we can't do that because of lack of runtime helpers (dublicate error)",
"e",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"e",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"var",
"templateErr",
"error",
"\n",
"filepath",
".",
"Walk",
"(",
"dir",
",",
"func",
"(",
"path",
"string",
",",
"info",
"os",
".",
"FileInfo",
",",
"err",
"error",
")",
"error",
"{",
"if",
"info",
"==",
"nil",
"||",
"info",
".",
"IsDir",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"rel",
",",
"err",
":=",
"filepath",
".",
"Rel",
"(",
"dir",
",",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"ext",
":=",
"filepath",
".",
"Ext",
"(",
"rel",
")",
"\n",
"if",
"ext",
"==",
"extension",
"{",
"buf",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"path",
")",
"\n",
"contents",
":=",
"string",
"(",
"buf",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"templateErr",
"=",
"err",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"name",
":=",
"filepath",
".",
"ToSlash",
"(",
"rel",
")",
"\n\n",
"tmpl",
",",
"err",
":=",
"raymond",
".",
"Parse",
"(",
"contents",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"templateErr",
"=",
"err",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"e",
".",
"templateCache",
"[",
"name",
"]",
"=",
"tmpl",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n\n",
"return",
"templateErr",
"\n",
"}"
] | // LoadDirectory builds the handlebars templates | [
"LoadDirectory",
"builds",
"the",
"handlebars",
"templates"
] | a4a986b413e8d88ebd894b4a3e327314069f2439 | https://github.com/kataras/go-template/blob/a4a986b413e8d88ebd894b4a3e327314069f2439/handlebars/handlebars.go#L61-L107 |
10,480 | kataras/go-template | amber/amber.go | New | func New(cfg ...Config) *Engine {
c := DefaultConfig()
if len(cfg) > 0 {
c = cfg[0]
}
// cuz mergo has a little bug on maps
if c.Funcs == nil {
c.Funcs = make(map[string]interface{}, 0)
}
return &Engine{Config: c}
} | go | func New(cfg ...Config) *Engine {
c := DefaultConfig()
if len(cfg) > 0 {
c = cfg[0]
}
// cuz mergo has a little bug on maps
if c.Funcs == nil {
c.Funcs = make(map[string]interface{}, 0)
}
return &Engine{Config: c}
} | [
"func",
"New",
"(",
"cfg",
"...",
"Config",
")",
"*",
"Engine",
"{",
"c",
":=",
"DefaultConfig",
"(",
")",
"\n",
"if",
"len",
"(",
"cfg",
")",
">",
"0",
"{",
"c",
"=",
"cfg",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"// cuz mergo has a little bug on maps",
"if",
"c",
".",
"Funcs",
"==",
"nil",
"{",
"c",
".",
"Funcs",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"0",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"Engine",
"{",
"Config",
":",
"c",
"}",
"\n",
"}"
] | // New creates and returns a new amber engine | [
"New",
"creates",
"and",
"returns",
"a",
"new",
"amber",
"engine"
] | a4a986b413e8d88ebd894b4a3e327314069f2439 | https://github.com/kataras/go-template/blob/a4a986b413e8d88ebd894b4a3e327314069f2439/amber/amber.go#L22-L34 |
10,481 | kataras/go-template | amber/amber.go | LoadDirectory | func (e *Engine) LoadDirectory(directory string, extension string) error {
opt := amber.DirOptions{}
opt.Recursive = true
// prepare the global amber funcs
funcs := template.FuncMap{}
for k, v := range amber.FuncMap { // add the amber's default funcs
funcs[k] = v
}
if e.Config.Funcs != nil { // add the config's funcs
for k, v := range e.Config.Funcs {
funcs[k] = v
}
}
amber.FuncMap = funcs //set the funcs
opt.Ext = extension
templates, err := amber.CompileDir(directory, opt, amber.DefaultOptions) // this returns the map with stripped extension, we want extension so we copy the map
if err == nil {
e.mu.Lock()
defer e.mu.Unlock()
e.templateCache = make(map[string]*template.Template)
for k, v := range templates {
name := filepath.ToSlash(k + opt.Ext)
e.templateCache[name] = v
delete(templates, k)
}
}
return err
} | go | func (e *Engine) LoadDirectory(directory string, extension string) error {
opt := amber.DirOptions{}
opt.Recursive = true
// prepare the global amber funcs
funcs := template.FuncMap{}
for k, v := range amber.FuncMap { // add the amber's default funcs
funcs[k] = v
}
if e.Config.Funcs != nil { // add the config's funcs
for k, v := range e.Config.Funcs {
funcs[k] = v
}
}
amber.FuncMap = funcs //set the funcs
opt.Ext = extension
templates, err := amber.CompileDir(directory, opt, amber.DefaultOptions) // this returns the map with stripped extension, we want extension so we copy the map
if err == nil {
e.mu.Lock()
defer e.mu.Unlock()
e.templateCache = make(map[string]*template.Template)
for k, v := range templates {
name := filepath.ToSlash(k + opt.Ext)
e.templateCache[name] = v
delete(templates, k)
}
}
return err
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"LoadDirectory",
"(",
"directory",
"string",
",",
"extension",
"string",
")",
"error",
"{",
"opt",
":=",
"amber",
".",
"DirOptions",
"{",
"}",
"\n",
"opt",
".",
"Recursive",
"=",
"true",
"\n\n",
"// prepare the global amber funcs",
"funcs",
":=",
"template",
".",
"FuncMap",
"{",
"}",
"\n\n",
"for",
"k",
",",
"v",
":=",
"range",
"amber",
".",
"FuncMap",
"{",
"// add the amber's default funcs",
"funcs",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"if",
"e",
".",
"Config",
".",
"Funcs",
"!=",
"nil",
"{",
"// add the config's funcs",
"for",
"k",
",",
"v",
":=",
"range",
"e",
".",
"Config",
".",
"Funcs",
"{",
"funcs",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n\n",
"amber",
".",
"FuncMap",
"=",
"funcs",
"//set the funcs",
"\n",
"opt",
".",
"Ext",
"=",
"extension",
"\n\n",
"templates",
",",
"err",
":=",
"amber",
".",
"CompileDir",
"(",
"directory",
",",
"opt",
",",
"amber",
".",
"DefaultOptions",
")",
"// this returns the map with stripped extension, we want extension so we copy the map",
"\n",
"if",
"err",
"==",
"nil",
"{",
"e",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"e",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"e",
".",
"templateCache",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"template",
".",
"Template",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"templates",
"{",
"name",
":=",
"filepath",
".",
"ToSlash",
"(",
"k",
"+",
"opt",
".",
"Ext",
")",
"\n",
"e",
".",
"templateCache",
"[",
"name",
"]",
"=",
"v",
"\n",
"delete",
"(",
"templates",
",",
"k",
")",
"\n",
"}",
"\n\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // LoadDirectory builds the amber templates | [
"LoadDirectory",
"builds",
"the",
"amber",
"templates"
] | a4a986b413e8d88ebd894b4a3e327314069f2439 | https://github.com/kataras/go-template/blob/a4a986b413e8d88ebd894b4a3e327314069f2439/amber/amber.go#L42-L75 |
10,482 | kataras/go-template | amber/amber.go | LoadAssets | func (e *Engine) LoadAssets(virtualDirectory string, virtualExtension string, assetFn func(name string) ([]byte, error), namesFn func() []string) error {
e.templateCache = make(map[string]*template.Template)
// prepare the global amber funcs
funcs := template.FuncMap{}
for k, v := range amber.FuncMap { // add the amber's default funcs
funcs[k] = v
}
if e.Config.Funcs != nil { // add the config's funcs
for k, v := range e.Config.Funcs {
funcs[k] = v
}
}
if len(virtualDirectory) > 0 {
if virtualDirectory[0] == '.' { // first check for .wrong
virtualDirectory = virtualDirectory[1:]
}
if virtualDirectory[0] == '/' || virtualDirectory[0] == filepath.Separator { // second check for /something, (or ./something if we had dot on 0 it will be removed
virtualDirectory = virtualDirectory[1:]
}
}
amber.FuncMap = funcs //set the funcs
e.mu.Lock()
defer e.mu.Unlock()
names := namesFn()
for _, path := range names {
if !strings.HasPrefix(path, virtualDirectory) {
continue
}
ext := filepath.Ext(path)
if ext == virtualExtension {
rel, err := filepath.Rel(virtualDirectory, path)
if err != nil {
return err
}
buf, err := assetFn(path)
if err != nil {
return err
}
name := filepath.ToSlash(rel)
tmpl, err := amber.CompileData(buf, name, amber.DefaultOptions)
if err != nil {
return err
}
e.templateCache[name] = tmpl
}
}
return nil
} | go | func (e *Engine) LoadAssets(virtualDirectory string, virtualExtension string, assetFn func(name string) ([]byte, error), namesFn func() []string) error {
e.templateCache = make(map[string]*template.Template)
// prepare the global amber funcs
funcs := template.FuncMap{}
for k, v := range amber.FuncMap { // add the amber's default funcs
funcs[k] = v
}
if e.Config.Funcs != nil { // add the config's funcs
for k, v := range e.Config.Funcs {
funcs[k] = v
}
}
if len(virtualDirectory) > 0 {
if virtualDirectory[0] == '.' { // first check for .wrong
virtualDirectory = virtualDirectory[1:]
}
if virtualDirectory[0] == '/' || virtualDirectory[0] == filepath.Separator { // second check for /something, (or ./something if we had dot on 0 it will be removed
virtualDirectory = virtualDirectory[1:]
}
}
amber.FuncMap = funcs //set the funcs
e.mu.Lock()
defer e.mu.Unlock()
names := namesFn()
for _, path := range names {
if !strings.HasPrefix(path, virtualDirectory) {
continue
}
ext := filepath.Ext(path)
if ext == virtualExtension {
rel, err := filepath.Rel(virtualDirectory, path)
if err != nil {
return err
}
buf, err := assetFn(path)
if err != nil {
return err
}
name := filepath.ToSlash(rel)
tmpl, err := amber.CompileData(buf, name, amber.DefaultOptions)
if err != nil {
return err
}
e.templateCache[name] = tmpl
}
}
return nil
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"LoadAssets",
"(",
"virtualDirectory",
"string",
",",
"virtualExtension",
"string",
",",
"assetFn",
"func",
"(",
"name",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
",",
"namesFn",
"func",
"(",
")",
"[",
"]",
"string",
")",
"error",
"{",
"e",
".",
"templateCache",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"template",
".",
"Template",
")",
"\n",
"// prepare the global amber funcs",
"funcs",
":=",
"template",
".",
"FuncMap",
"{",
"}",
"\n\n",
"for",
"k",
",",
"v",
":=",
"range",
"amber",
".",
"FuncMap",
"{",
"// add the amber's default funcs",
"funcs",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"if",
"e",
".",
"Config",
".",
"Funcs",
"!=",
"nil",
"{",
"// add the config's funcs",
"for",
"k",
",",
"v",
":=",
"range",
"e",
".",
"Config",
".",
"Funcs",
"{",
"funcs",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"virtualDirectory",
")",
">",
"0",
"{",
"if",
"virtualDirectory",
"[",
"0",
"]",
"==",
"'.'",
"{",
"// first check for .wrong",
"virtualDirectory",
"=",
"virtualDirectory",
"[",
"1",
":",
"]",
"\n",
"}",
"\n",
"if",
"virtualDirectory",
"[",
"0",
"]",
"==",
"'/'",
"||",
"virtualDirectory",
"[",
"0",
"]",
"==",
"filepath",
".",
"Separator",
"{",
"// second check for /something, (or ./something if we had dot on 0 it will be removed",
"virtualDirectory",
"=",
"virtualDirectory",
"[",
"1",
":",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"amber",
".",
"FuncMap",
"=",
"funcs",
"//set the funcs",
"\n\n",
"e",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"e",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"names",
":=",
"namesFn",
"(",
")",
"\n\n",
"for",
"_",
",",
"path",
":=",
"range",
"names",
"{",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"path",
",",
"virtualDirectory",
")",
"{",
"continue",
"\n",
"}",
"\n",
"ext",
":=",
"filepath",
".",
"Ext",
"(",
"path",
")",
"\n",
"if",
"ext",
"==",
"virtualExtension",
"{",
"rel",
",",
"err",
":=",
"filepath",
".",
"Rel",
"(",
"virtualDirectory",
",",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"buf",
",",
"err",
":=",
"assetFn",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"name",
":=",
"filepath",
".",
"ToSlash",
"(",
"rel",
")",
"\n",
"tmpl",
",",
"err",
":=",
"amber",
".",
"CompileData",
"(",
"buf",
",",
"name",
",",
"amber",
".",
"DefaultOptions",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"e",
".",
"templateCache",
"[",
"name",
"]",
"=",
"tmpl",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // LoadAssets builds the templates from binary assets | [
"LoadAssets",
"builds",
"the",
"templates",
"from",
"binary",
"assets"
] | a4a986b413e8d88ebd894b4a3e327314069f2439 | https://github.com/kataras/go-template/blob/a4a986b413e8d88ebd894b4a3e327314069f2439/amber/amber.go#L78-L136 |
10,483 | kataras/go-template | mux.go | LoadAll | func (entries Entries) LoadAll() error {
for i, n := 0, len(entries); i < n; i++ {
if err := entries[i].LoadEngine(); err != nil {
return err
}
}
return nil
} | go | func (entries Entries) LoadAll() error {
for i, n := 0, len(entries); i < n; i++ {
if err := entries[i].LoadEngine(); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"entries",
"Entries",
")",
"LoadAll",
"(",
")",
"error",
"{",
"for",
"i",
",",
"n",
":=",
"0",
",",
"len",
"(",
"entries",
")",
";",
"i",
"<",
"n",
";",
"i",
"++",
"{",
"if",
"err",
":=",
"entries",
"[",
"i",
"]",
".",
"LoadEngine",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // LoadAll loads all template engines entries, returns the first error | [
"LoadAll",
"loads",
"all",
"template",
"engines",
"entries",
"returns",
"the",
"first",
"error"
] | a4a986b413e8d88ebd894b4a3e327314069f2439 | https://github.com/kataras/go-template/blob/a4a986b413e8d88ebd894b4a3e327314069f2439/mux.go#L50-L57 |
10,484 | kataras/go-template | mux.go | Find | func (entries Entries) Find(filename string) *Entry {
extension := filepath.Ext(filename)
// Read-Only no locks needed, at serve/runtime-time the library is not supposed to add new template engines
for i, n := 0, len(entries); i < n; i++ {
e := entries[i]
if e.Loader.Extension == extension {
return e
}
}
return nil
} | go | func (entries Entries) Find(filename string) *Entry {
extension := filepath.Ext(filename)
// Read-Only no locks needed, at serve/runtime-time the library is not supposed to add new template engines
for i, n := 0, len(entries); i < n; i++ {
e := entries[i]
if e.Loader.Extension == extension {
return e
}
}
return nil
} | [
"func",
"(",
"entries",
"Entries",
")",
"Find",
"(",
"filename",
"string",
")",
"*",
"Entry",
"{",
"extension",
":=",
"filepath",
".",
"Ext",
"(",
"filename",
")",
"\n",
"// Read-Only no locks needed, at serve/runtime-time the library is not supposed to add new template engines",
"for",
"i",
",",
"n",
":=",
"0",
",",
"len",
"(",
"entries",
")",
";",
"i",
"<",
"n",
";",
"i",
"++",
"{",
"e",
":=",
"entries",
"[",
"i",
"]",
"\n",
"if",
"e",
".",
"Loader",
".",
"Extension",
"==",
"extension",
"{",
"return",
"e",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Find receives a filename, gets its extension and returns the template engine responsible for that file extension | [
"Find",
"receives",
"a",
"filename",
"gets",
"its",
"extension",
"and",
"returns",
"the",
"template",
"engine",
"responsible",
"for",
"that",
"file",
"extension"
] | a4a986b413e8d88ebd894b4a3e327314069f2439 | https://github.com/kataras/go-template/blob/a4a986b413e8d88ebd894b4a3e327314069f2439/mux.go#L60-L70 |
10,485 | kataras/go-template | mux.go | UseFuncMap | func (m *Mux) UseFuncMap(funcMap map[string]interface{}) *Mux {
if len(funcMap) == 0 {
return m
}
for k, v := range m.SharedFuncs {
m.SharedFuncs[k] = v
}
// if template engine is already added (but not loaded)
// then it's valid to add these funcs there.
for i, n := 0, len(m.Entries); i < n; i++ {
// add the shared funcs if template engine supports funcs.
m.SetFuncMapToEngine(funcMap, m.Entries[i].Engine)
}
return m
} | go | func (m *Mux) UseFuncMap(funcMap map[string]interface{}) *Mux {
if len(funcMap) == 0 {
return m
}
for k, v := range m.SharedFuncs {
m.SharedFuncs[k] = v
}
// if template engine is already added (but not loaded)
// then it's valid to add these funcs there.
for i, n := 0, len(m.Entries); i < n; i++ {
// add the shared funcs if template engine supports funcs.
m.SetFuncMapToEngine(funcMap, m.Entries[i].Engine)
}
return m
} | [
"func",
"(",
"m",
"*",
"Mux",
")",
"UseFuncMap",
"(",
"funcMap",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"*",
"Mux",
"{",
"if",
"len",
"(",
"funcMap",
")",
"==",
"0",
"{",
"return",
"m",
"\n",
"}",
"\n\n",
"for",
"k",
",",
"v",
":=",
"range",
"m",
".",
"SharedFuncs",
"{",
"m",
".",
"SharedFuncs",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"// if template engine is already added (but not loaded)",
"// then it's valid to add these funcs there.",
"for",
"i",
",",
"n",
":=",
"0",
",",
"len",
"(",
"m",
".",
"Entries",
")",
";",
"i",
"<",
"n",
";",
"i",
"++",
"{",
"// add the shared funcs if template engine supports funcs.",
"m",
".",
"SetFuncMapToEngine",
"(",
"funcMap",
",",
"m",
".",
"Entries",
"[",
"i",
"]",
".",
"Engine",
")",
"\n",
"}",
"\n\n",
"return",
"m",
"\n",
"}"
] | // UseFuncMap adds shared template funcs to the Mux
// these funcs are applied to all template engines
//
// Should be called not called after Load. | [
"UseFuncMap",
"adds",
"shared",
"template",
"funcs",
"to",
"the",
"Mux",
"these",
"funcs",
"are",
"applied",
"to",
"all",
"template",
"engines",
"Should",
"be",
"called",
"not",
"called",
"after",
"Load",
"."
] | a4a986b413e8d88ebd894b4a3e327314069f2439 | https://github.com/kataras/go-template/blob/a4a986b413e8d88ebd894b4a3e327314069f2439/mux.go#L111-L128 |
10,486 | kataras/go-template | mux.go | AddEngine | func (m *Mux) AddEngine(e Engine) *Loader {
// add the shared funcs
m.SetFuncMapToEngine(m.SharedFuncs, e)
entry := &Entry{Engine: e, Loader: NewLoader()}
m.Entries = append(m.Entries, entry)
// returns the entry's Loader(pointer)
return entry.Loader
} | go | func (m *Mux) AddEngine(e Engine) *Loader {
// add the shared funcs
m.SetFuncMapToEngine(m.SharedFuncs, e)
entry := &Entry{Engine: e, Loader: NewLoader()}
m.Entries = append(m.Entries, entry)
// returns the entry's Loader(pointer)
return entry.Loader
} | [
"func",
"(",
"m",
"*",
"Mux",
")",
"AddEngine",
"(",
"e",
"Engine",
")",
"*",
"Loader",
"{",
"// add the shared funcs",
"m",
".",
"SetFuncMapToEngine",
"(",
"m",
".",
"SharedFuncs",
",",
"e",
")",
"\n\n",
"entry",
":=",
"&",
"Entry",
"{",
"Engine",
":",
"e",
",",
"Loader",
":",
"NewLoader",
"(",
")",
"}",
"\n\n",
"m",
".",
"Entries",
"=",
"append",
"(",
"m",
".",
"Entries",
",",
"entry",
")",
"\n",
"// returns the entry's Loader(pointer)",
"return",
"entry",
".",
"Loader",
"\n",
"}"
] | // AddEngine adds but not loads a template engine, returns the entry's Loader | [
"AddEngine",
"adds",
"but",
"not",
"loads",
"a",
"template",
"engine",
"returns",
"the",
"entry",
"s",
"Loader"
] | a4a986b413e8d88ebd894b4a3e327314069f2439 | https://github.com/kataras/go-template/blob/a4a986b413e8d88ebd894b4a3e327314069f2439/mux.go#L165-L174 |
10,487 | kataras/go-template | django/config.go | DefaultConfig | func DefaultConfig() Config {
return Config{
Filters: make(map[string]FilterFunction),
Globals: make(map[string]interface{}, 0),
DebugTemplates: false,
}
} | go | func DefaultConfig() Config {
return Config{
Filters: make(map[string]FilterFunction),
Globals: make(map[string]interface{}, 0),
DebugTemplates: false,
}
} | [
"func",
"DefaultConfig",
"(",
")",
"Config",
"{",
"return",
"Config",
"{",
"Filters",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"FilterFunction",
")",
",",
"Globals",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"0",
")",
",",
"DebugTemplates",
":",
"false",
",",
"}",
"\n",
"}"
] | // DefaultConfig returns the default configuration for the django template engine | [
"DefaultConfig",
"returns",
"the",
"default",
"configuration",
"for",
"the",
"django",
"template",
"engine"
] | a4a986b413e8d88ebd894b4a3e327314069f2439 | https://github.com/kataras/go-template/blob/a4a986b413e8d88ebd894b4a3e327314069f2439/django/config.go#L26-L32 |
10,488 | kataras/go-template | pug/pug.go | New | func New(cfg ...Config) *html.Engine {
c := DefaultConfig()
if len(cfg) > 0 {
c = cfg[0]
}
// pass the Pug/Jade configs to the html's configuration
s := html.New(html.Config(c))
s.Middleware = jade.Parse
return s
} | go | func New(cfg ...Config) *html.Engine {
c := DefaultConfig()
if len(cfg) > 0 {
c = cfg[0]
}
// pass the Pug/Jade configs to the html's configuration
s := html.New(html.Config(c))
s.Middleware = jade.Parse
return s
} | [
"func",
"New",
"(",
"cfg",
"...",
"Config",
")",
"*",
"html",
".",
"Engine",
"{",
"c",
":=",
"DefaultConfig",
"(",
")",
"\n",
"if",
"len",
"(",
"cfg",
")",
">",
"0",
"{",
"c",
"=",
"cfg",
"[",
"0",
"]",
"\n",
"}",
"\n",
"// pass the Pug/Jade configs to the html's configuration",
"s",
":=",
"html",
".",
"New",
"(",
"html",
".",
"Config",
"(",
"c",
")",
")",
"\n",
"s",
".",
"Middleware",
"=",
"jade",
".",
"Parse",
"\n",
"return",
"s",
"\n",
"}"
] | // New creates and returns the Pug template engine | [
"New",
"creates",
"and",
"returns",
"the",
"Pug",
"template",
"engine"
] | a4a986b413e8d88ebd894b4a3e327314069f2439 | https://github.com/kataras/go-template/blob/a4a986b413e8d88ebd894b4a3e327314069f2439/pug/pug.go#L10-L20 |
10,489 | kataras/go-template | django/django.go | convertFilters | func (p *Engine) convertFilters() map[string]pongo2.FilterFunction {
filters := make(map[string]pongo2.FilterFunction, len(p.Config.Filters))
for k, v := range p.Config.Filters {
func(filterName string, filterFunc FilterFunction) {
fn := pongo2.FilterFunction(func(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
theOut, theErr := filterFunc((*Value)(in), (*Value)(param))
return (*pongo2.Value)(theOut), (*pongo2.Error)(theErr)
})
filters[filterName] = fn
}(k, v)
}
return filters
} | go | func (p *Engine) convertFilters() map[string]pongo2.FilterFunction {
filters := make(map[string]pongo2.FilterFunction, len(p.Config.Filters))
for k, v := range p.Config.Filters {
func(filterName string, filterFunc FilterFunction) {
fn := pongo2.FilterFunction(func(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
theOut, theErr := filterFunc((*Value)(in), (*Value)(param))
return (*pongo2.Value)(theOut), (*pongo2.Error)(theErr)
})
filters[filterName] = fn
}(k, v)
}
return filters
} | [
"func",
"(",
"p",
"*",
"Engine",
")",
"convertFilters",
"(",
")",
"map",
"[",
"string",
"]",
"pongo2",
".",
"FilterFunction",
"{",
"filters",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"pongo2",
".",
"FilterFunction",
",",
"len",
"(",
"p",
".",
"Config",
".",
"Filters",
")",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"p",
".",
"Config",
".",
"Filters",
"{",
"func",
"(",
"filterName",
"string",
",",
"filterFunc",
"FilterFunction",
")",
"{",
"fn",
":=",
"pongo2",
".",
"FilterFunction",
"(",
"func",
"(",
"in",
"*",
"pongo2",
".",
"Value",
",",
"param",
"*",
"pongo2",
".",
"Value",
")",
"(",
"*",
"pongo2",
".",
"Value",
",",
"*",
"pongo2",
".",
"Error",
")",
"{",
"theOut",
",",
"theErr",
":=",
"filterFunc",
"(",
"(",
"*",
"Value",
")",
"(",
"in",
")",
",",
"(",
"*",
"Value",
")",
"(",
"param",
")",
")",
"\n",
"return",
"(",
"*",
"pongo2",
".",
"Value",
")",
"(",
"theOut",
")",
",",
"(",
"*",
"pongo2",
".",
"Error",
")",
"(",
"theErr",
")",
"\n",
"}",
")",
"\n",
"filters",
"[",
"filterName",
"]",
"=",
"fn",
"\n",
"}",
"(",
"k",
",",
"v",
")",
"\n",
"}",
"\n",
"return",
"filters",
"\n",
"}"
] | // this exists because of moving the pongo2 to the vendors without conflictitions if users
// wants to register pongo2 filters they can use this django.FilterFunc to do so. | [
"this",
"exists",
"because",
"of",
"moving",
"the",
"pongo2",
"to",
"the",
"vendors",
"without",
"conflictitions",
"if",
"users",
"wants",
"to",
"register",
"pongo2",
"filters",
"they",
"can",
"use",
"this",
"django",
".",
"FilterFunc",
"to",
"do",
"so",
"."
] | a4a986b413e8d88ebd894b4a3e327314069f2439 | https://github.com/kataras/go-template/blob/a4a986b413e8d88ebd894b4a3e327314069f2439/django/django.go#L56-L68 |
10,490 | kataras/go-template | django/django.go | ExecuteWriter | func (p *Engine) ExecuteWriter(out io.Writer, name string, binding interface{}, options ...map[string]interface{}) error {
if tmpl := p.fromCache(name); tmpl != nil {
return tmpl.ExecuteWriter(getPongoContext(binding), out)
}
return fmt.Errorf("[IRIS TEMPLATES] Template with name %s doesn't exists in the dir", name)
} | go | func (p *Engine) ExecuteWriter(out io.Writer, name string, binding interface{}, options ...map[string]interface{}) error {
if tmpl := p.fromCache(name); tmpl != nil {
return tmpl.ExecuteWriter(getPongoContext(binding), out)
}
return fmt.Errorf("[IRIS TEMPLATES] Template with name %s doesn't exists in the dir", name)
} | [
"func",
"(",
"p",
"*",
"Engine",
")",
"ExecuteWriter",
"(",
"out",
"io",
".",
"Writer",
",",
"name",
"string",
",",
"binding",
"interface",
"{",
"}",
",",
"options",
"...",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"tmpl",
":=",
"p",
".",
"fromCache",
"(",
"name",
")",
";",
"tmpl",
"!=",
"nil",
"{",
"return",
"tmpl",
".",
"ExecuteWriter",
"(",
"getPongoContext",
"(",
"binding",
")",
",",
"out",
")",
"\n",
"}",
"\n\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}"
] | // ExecuteWriter executes a templates and write its results to the out writer
// layout here is useless | [
"ExecuteWriter",
"executes",
"a",
"templates",
"and",
"write",
"its",
"results",
"to",
"the",
"out",
"writer",
"layout",
"here",
"is",
"useless"
] | a4a986b413e8d88ebd894b4a3e327314069f2439 | https://github.com/kataras/go-template/blob/a4a986b413e8d88ebd894b4a3e327314069f2439/django/django.go#L217-L223 |
10,491 | kataras/go-template | html/config.go | DefaultConfig | func DefaultConfig() Config {
return Config{
Left: "{{",
Right: "}}",
Layout: "",
Funcs: make(map[string]interface{}, 0),
LayoutFuncs: make(map[string]interface{}, 0),
}
} | go | func DefaultConfig() Config {
return Config{
Left: "{{",
Right: "}}",
Layout: "",
Funcs: make(map[string]interface{}, 0),
LayoutFuncs: make(map[string]interface{}, 0),
}
} | [
"func",
"DefaultConfig",
"(",
")",
"Config",
"{",
"return",
"Config",
"{",
"Left",
":",
"\"",
"\"",
",",
"Right",
":",
"\"",
"\"",
",",
"Layout",
":",
"\"",
"\"",
",",
"Funcs",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"0",
")",
",",
"LayoutFuncs",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"0",
")",
",",
"}",
"\n",
"}"
] | // DefaultConfig returns the default configs for the html template engine | [
"DefaultConfig",
"returns",
"the",
"default",
"configs",
"for",
"the",
"html",
"template",
"engine"
] | a4a986b413e8d88ebd894b4a3e327314069f2439 | https://github.com/kataras/go-template/blob/a4a986b413e8d88ebd894b4a3e327314069f2439/html/config.go#L13-L21 |
10,492 | kataras/go-template | engine.go | GetGzipOption | func GetGzipOption(defaultValue bool, options map[string]interface{}) bool {
gzipOpt := options["gzip"] // we only need that, so don't create new map to keep the options.
if b, isBool := gzipOpt.(bool); isBool {
return b
}
return defaultValue
} | go | func GetGzipOption(defaultValue bool, options map[string]interface{}) bool {
gzipOpt := options["gzip"] // we only need that, so don't create new map to keep the options.
if b, isBool := gzipOpt.(bool); isBool {
return b
}
return defaultValue
} | [
"func",
"GetGzipOption",
"(",
"defaultValue",
"bool",
",",
"options",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"bool",
"{",
"gzipOpt",
":=",
"options",
"[",
"\"",
"\"",
"]",
"// we only need that, so don't create new map to keep the options.",
"\n",
"if",
"b",
",",
"isBool",
":=",
"gzipOpt",
".",
"(",
"bool",
")",
";",
"isBool",
"{",
"return",
"b",
"\n",
"}",
"\n",
"return",
"defaultValue",
"\n",
"}"
] | // GetGzipOption receives a default value and the render options map and returns if gzip is enabled for this render action | [
"GetGzipOption",
"receives",
"a",
"default",
"value",
"and",
"the",
"render",
"options",
"map",
"and",
"returns",
"if",
"gzip",
"is",
"enabled",
"for",
"this",
"render",
"action"
] | a4a986b413e8d88ebd894b4a3e327314069f2439 | https://github.com/kataras/go-template/blob/a4a986b413e8d88ebd894b4a3e327314069f2439/engine.go#L45-L51 |
10,493 | kataras/go-template | engine.go | GetCharsetOption | func GetCharsetOption(defaultValue string, options map[string]interface{}) string {
charsetOpt := options["charset"]
if s, isString := charsetOpt.(string); isString {
return s
}
return defaultValue
} | go | func GetCharsetOption(defaultValue string, options map[string]interface{}) string {
charsetOpt := options["charset"]
if s, isString := charsetOpt.(string); isString {
return s
}
return defaultValue
} | [
"func",
"GetCharsetOption",
"(",
"defaultValue",
"string",
",",
"options",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"string",
"{",
"charsetOpt",
":=",
"options",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"s",
",",
"isString",
":=",
"charsetOpt",
".",
"(",
"string",
")",
";",
"isString",
"{",
"return",
"s",
"\n",
"}",
"\n",
"return",
"defaultValue",
"\n",
"}"
] | // GetCharsetOption receives a default value and the render options map and returns the correct charset for this render action | [
"GetCharsetOption",
"receives",
"a",
"default",
"value",
"and",
"the",
"render",
"options",
"map",
"and",
"returns",
"the",
"correct",
"charset",
"for",
"this",
"render",
"action"
] | a4a986b413e8d88ebd894b4a3e327314069f2439 | https://github.com/kataras/go-template/blob/a4a986b413e8d88ebd894b4a3e327314069f2439/engine.go#L54-L60 |
10,494 | kataras/go-template | html/html.go | New | func New(cfg ...Config) *Engine {
c := DefaultConfig()
if len(cfg) > 0 {
c = cfg[0]
}
// cuz mergo has a little bug on maps
if c.Funcs == nil {
c.Funcs = make(map[string]interface{}, 0)
}
if c.LayoutFuncs == nil {
c.LayoutFuncs = make(map[string]interface{}, 0)
}
e := &Engine{Config: c}
return e
} | go | func New(cfg ...Config) *Engine {
c := DefaultConfig()
if len(cfg) > 0 {
c = cfg[0]
}
// cuz mergo has a little bug on maps
if c.Funcs == nil {
c.Funcs = make(map[string]interface{}, 0)
}
if c.LayoutFuncs == nil {
c.LayoutFuncs = make(map[string]interface{}, 0)
}
e := &Engine{Config: c}
return e
} | [
"func",
"New",
"(",
"cfg",
"...",
"Config",
")",
"*",
"Engine",
"{",
"c",
":=",
"DefaultConfig",
"(",
")",
"\n",
"if",
"len",
"(",
"cfg",
")",
">",
"0",
"{",
"c",
"=",
"cfg",
"[",
"0",
"]",
"\n",
"}",
"\n",
"// cuz mergo has a little bug on maps",
"if",
"c",
".",
"Funcs",
"==",
"nil",
"{",
"c",
".",
"Funcs",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"0",
")",
"\n",
"}",
"\n",
"if",
"c",
".",
"LayoutFuncs",
"==",
"nil",
"{",
"c",
".",
"LayoutFuncs",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"0",
")",
"\n",
"}",
"\n",
"e",
":=",
"&",
"Engine",
"{",
"Config",
":",
"c",
"}",
"\n",
"return",
"e",
"\n",
"}"
] | // New creates and returns the HTMLTemplate template engine | [
"New",
"creates",
"and",
"returns",
"the",
"HTMLTemplate",
"template",
"engine"
] | a4a986b413e8d88ebd894b4a3e327314069f2439 | https://github.com/kataras/go-template/blob/a4a986b413e8d88ebd894b4a3e327314069f2439/html/html.go#L48-L62 |
10,495 | kataras/go-template | markdown/markdown.go | LoadDirectory | func (e *Engine) LoadDirectory(dir string, extension string) error {
e.mu.Lock()
defer e.mu.Unlock()
var templateErr error
// Walk the supplied directory and compile any files that match our extension list.
filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if info == nil || info.IsDir() {
} else {
rel, err := filepath.Rel(dir, path)
if err != nil {
templateErr = err
return err
}
ext := filepath.Ext(rel)
if ext == extension {
buf, err := ioutil.ReadFile(path)
if err != nil {
templateErr = err
return err
}
buf = blackfriday.MarkdownCommon(buf)
if e.Config.Sanitize {
buf = bluemonday.UGCPolicy().SanitizeBytes(buf)
}
if err != nil {
templateErr = err
return err
}
name := filepath.ToSlash(rel)
e.templateCache[name] = buf
}
}
return nil
})
return templateErr
} | go | func (e *Engine) LoadDirectory(dir string, extension string) error {
e.mu.Lock()
defer e.mu.Unlock()
var templateErr error
// Walk the supplied directory and compile any files that match our extension list.
filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if info == nil || info.IsDir() {
} else {
rel, err := filepath.Rel(dir, path)
if err != nil {
templateErr = err
return err
}
ext := filepath.Ext(rel)
if ext == extension {
buf, err := ioutil.ReadFile(path)
if err != nil {
templateErr = err
return err
}
buf = blackfriday.MarkdownCommon(buf)
if e.Config.Sanitize {
buf = bluemonday.UGCPolicy().SanitizeBytes(buf)
}
if err != nil {
templateErr = err
return err
}
name := filepath.ToSlash(rel)
e.templateCache[name] = buf
}
}
return nil
})
return templateErr
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"LoadDirectory",
"(",
"dir",
"string",
",",
"extension",
"string",
")",
"error",
"{",
"e",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"e",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"var",
"templateErr",
"error",
"\n",
"// Walk the supplied directory and compile any files that match our extension list.",
"filepath",
".",
"Walk",
"(",
"dir",
",",
"func",
"(",
"path",
"string",
",",
"info",
"os",
".",
"FileInfo",
",",
"err",
"error",
")",
"error",
"{",
"if",
"info",
"==",
"nil",
"||",
"info",
".",
"IsDir",
"(",
")",
"{",
"}",
"else",
"{",
"rel",
",",
"err",
":=",
"filepath",
".",
"Rel",
"(",
"dir",
",",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"templateErr",
"=",
"err",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"ext",
":=",
"filepath",
".",
"Ext",
"(",
"rel",
")",
"\n\n",
"if",
"ext",
"==",
"extension",
"{",
"buf",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"templateErr",
"=",
"err",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"buf",
"=",
"blackfriday",
".",
"MarkdownCommon",
"(",
"buf",
")",
"\n",
"if",
"e",
".",
"Config",
".",
"Sanitize",
"{",
"buf",
"=",
"bluemonday",
".",
"UGCPolicy",
"(",
")",
".",
"SanitizeBytes",
"(",
"buf",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"templateErr",
"=",
"err",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"name",
":=",
"filepath",
".",
"ToSlash",
"(",
"rel",
")",
"\n",
"e",
".",
"templateCache",
"[",
"name",
"]",
"=",
"buf",
"\n\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n\n",
"return",
"templateErr",
"\n\n",
"}"
] | // LoadDirectory builds the markdown templates | [
"LoadDirectory",
"builds",
"the",
"markdown",
"templates"
] | a4a986b413e8d88ebd894b4a3e327314069f2439 | https://github.com/kataras/go-template/blob/a4a986b413e8d88ebd894b4a3e327314069f2439/markdown/markdown.go#L38-L83 |
10,496 | micro/util | go/lib/addr/addr.go | IPs | func IPs() []string {
ifaces, err := net.Interfaces()
if err != nil {
return nil
}
var ipAddrs []string
for _, i := range ifaces {
addrs, err := i.Addrs()
if err != nil {
continue
}
for _, addr := range addrs {
var ip net.IP
switch v := addr.(type) {
case *net.IPNet:
ip = v.IP
case *net.IPAddr:
ip = v.IP
}
if ip == nil {
continue
}
ip = ip.To4()
if ip == nil {
continue
}
ipAddrs = append(ipAddrs, ip.String())
}
}
return ipAddrs
} | go | func IPs() []string {
ifaces, err := net.Interfaces()
if err != nil {
return nil
}
var ipAddrs []string
for _, i := range ifaces {
addrs, err := i.Addrs()
if err != nil {
continue
}
for _, addr := range addrs {
var ip net.IP
switch v := addr.(type) {
case *net.IPNet:
ip = v.IP
case *net.IPAddr:
ip = v.IP
}
if ip == nil {
continue
}
ip = ip.To4()
if ip == nil {
continue
}
ipAddrs = append(ipAddrs, ip.String())
}
}
return ipAddrs
} | [
"func",
"IPs",
"(",
")",
"[",
"]",
"string",
"{",
"ifaces",
",",
"err",
":=",
"net",
".",
"Interfaces",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"var",
"ipAddrs",
"[",
"]",
"string",
"\n\n",
"for",
"_",
",",
"i",
":=",
"range",
"ifaces",
"{",
"addrs",
",",
"err",
":=",
"i",
".",
"Addrs",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"continue",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"addr",
":=",
"range",
"addrs",
"{",
"var",
"ip",
"net",
".",
"IP",
"\n",
"switch",
"v",
":=",
"addr",
".",
"(",
"type",
")",
"{",
"case",
"*",
"net",
".",
"IPNet",
":",
"ip",
"=",
"v",
".",
"IP",
"\n",
"case",
"*",
"net",
".",
"IPAddr",
":",
"ip",
"=",
"v",
".",
"IP",
"\n",
"}",
"\n\n",
"if",
"ip",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n\n",
"ip",
"=",
"ip",
".",
"To4",
"(",
")",
"\n",
"if",
"ip",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n\n",
"ipAddrs",
"=",
"append",
"(",
"ipAddrs",
",",
"ip",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"ipAddrs",
"\n",
"}"
] | // IPs returns all known ips | [
"IPs",
"returns",
"all",
"known",
"ips"
] | b9d497e656ef2a7ae781bd909cfc938144a653ff | https://github.com/micro/util/blob/b9d497e656ef2a7ae781bd909cfc938144a653ff/go/lib/addr/addr.go#L83-L120 |
10,497 | cloudfoundry/dropsonde | dropsonde_marshaller/dropsonde_marshaller.go | NewDropsondeMarshaller | func NewDropsondeMarshaller(logger *gosteno.Logger) *DropsondeMarshaller {
messageCounts := make(map[events.Envelope_EventType]*uint64)
for key := range events.Envelope_EventType_name {
var count uint64
messageCounts[events.Envelope_EventType(key)] = &count
}
return &DropsondeMarshaller{
logger: logger,
messageCounts: messageCounts,
}
} | go | func NewDropsondeMarshaller(logger *gosteno.Logger) *DropsondeMarshaller {
messageCounts := make(map[events.Envelope_EventType]*uint64)
for key := range events.Envelope_EventType_name {
var count uint64
messageCounts[events.Envelope_EventType(key)] = &count
}
return &DropsondeMarshaller{
logger: logger,
messageCounts: messageCounts,
}
} | [
"func",
"NewDropsondeMarshaller",
"(",
"logger",
"*",
"gosteno",
".",
"Logger",
")",
"*",
"DropsondeMarshaller",
"{",
"messageCounts",
":=",
"make",
"(",
"map",
"[",
"events",
".",
"Envelope_EventType",
"]",
"*",
"uint64",
")",
"\n",
"for",
"key",
":=",
"range",
"events",
".",
"Envelope_EventType_name",
"{",
"var",
"count",
"uint64",
"\n",
"messageCounts",
"[",
"events",
".",
"Envelope_EventType",
"(",
"key",
")",
"]",
"=",
"&",
"count",
"\n",
"}",
"\n",
"return",
"&",
"DropsondeMarshaller",
"{",
"logger",
":",
"logger",
",",
"messageCounts",
":",
"messageCounts",
",",
"}",
"\n",
"}"
] | // NewDropsondeMarshaller instantiates a DropsondeMarshaller and logs to the
// provided logger. | [
"NewDropsondeMarshaller",
"instantiates",
"a",
"DropsondeMarshaller",
"and",
"logs",
"to",
"the",
"provided",
"logger",
"."
] | a5c24343b09d7b811567b68cf18c7aa2a34a798a | https://github.com/cloudfoundry/dropsonde/blob/a5c24343b09d7b811567b68cf18c7aa2a34a798a/dropsonde_marshaller/dropsonde_marshaller.go#L50-L60 |
10,498 | cloudfoundry/dropsonde | dropsonde_marshaller/dropsonde_marshaller.go | Run | func (u *DropsondeMarshaller) Run(inputChan <-chan *events.Envelope, outputChan chan<- []byte) {
for message := range inputChan {
messageBytes, err := proto.Marshal(message)
if err != nil {
u.logger.Errorf("dropsondeMarshaller: marshal error %v", err)
metrics.BatchIncrementCounter("dropsondeMarshaller.marshalErrors")
continue
}
u.incrementMessageCount(message.GetEventType())
outputChan <- messageBytes
}
} | go | func (u *DropsondeMarshaller) Run(inputChan <-chan *events.Envelope, outputChan chan<- []byte) {
for message := range inputChan {
messageBytes, err := proto.Marshal(message)
if err != nil {
u.logger.Errorf("dropsondeMarshaller: marshal error %v", err)
metrics.BatchIncrementCounter("dropsondeMarshaller.marshalErrors")
continue
}
u.incrementMessageCount(message.GetEventType())
outputChan <- messageBytes
}
} | [
"func",
"(",
"u",
"*",
"DropsondeMarshaller",
")",
"Run",
"(",
"inputChan",
"<-",
"chan",
"*",
"events",
".",
"Envelope",
",",
"outputChan",
"chan",
"<-",
"[",
"]",
"byte",
")",
"{",
"for",
"message",
":=",
"range",
"inputChan",
"{",
"messageBytes",
",",
"err",
":=",
"proto",
".",
"Marshal",
"(",
"message",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"u",
".",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"metrics",
".",
"BatchIncrementCounter",
"(",
"\"",
"\"",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"u",
".",
"incrementMessageCount",
"(",
"message",
".",
"GetEventType",
"(",
")",
")",
"\n",
"outputChan",
"<-",
"messageBytes",
"\n",
"}",
"\n",
"}"
] | // Run reads Envelopes from inputChan, marshals them to Protocol Buffer format,
// and emits the binary messages onto outputChan. It operates one message at a
// time, and will block if outputChan is not read. | [
"Run",
"reads",
"Envelopes",
"from",
"inputChan",
"marshals",
"them",
"to",
"Protocol",
"Buffer",
"format",
"and",
"emits",
"the",
"binary",
"messages",
"onto",
"outputChan",
".",
"It",
"operates",
"one",
"message",
"at",
"a",
"time",
"and",
"will",
"block",
"if",
"outputChan",
"is",
"not",
"read",
"."
] | a5c24343b09d7b811567b68cf18c7aa2a34a798a | https://github.com/cloudfoundry/dropsonde/blob/a5c24343b09d7b811567b68cf18c7aa2a34a798a/dropsonde_marshaller/dropsonde_marshaller.go#L65-L78 |
10,499 | cloudfoundry/dropsonde | signature/signature_verifier.go | SignMessage | func SignMessage(message, secret []byte) []byte {
signature := generateSignature(message, secret)
return append(signature, message...)
} | go | func SignMessage(message, secret []byte) []byte {
signature := generateSignature(message, secret)
return append(signature, message...)
} | [
"func",
"SignMessage",
"(",
"message",
",",
"secret",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"signature",
":=",
"generateSignature",
"(",
"message",
",",
"secret",
")",
"\n",
"return",
"append",
"(",
"signature",
",",
"message",
"...",
")",
"\n",
"}"
] | // SignMessage returns a message signed with the provided secret, with the
// signature prepended to the original message. | [
"SignMessage",
"returns",
"a",
"message",
"signed",
"with",
"the",
"provided",
"secret",
"with",
"the",
"signature",
"prepended",
"to",
"the",
"original",
"message",
"."
] | a5c24343b09d7b811567b68cf18c7aa2a34a798a | https://github.com/cloudfoundry/dropsonde/blob/a5c24343b09d7b811567b68cf18c7aa2a34a798a/signature/signature_verifier.go#L63-L66 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.