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
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
7,500
aporeto-inc/trireme-lib
policy/policy.go
SetIPAddresses
func (p *PUPolicy) SetIPAddresses(l ExtendedMap) { p.Lock() defer p.Unlock() p.ips = l }
go
func (p *PUPolicy) SetIPAddresses(l ExtendedMap) { p.Lock() defer p.Unlock() p.ips = l }
[ "func", "(", "p", "*", "PUPolicy", ")", "SetIPAddresses", "(", "l", "ExtendedMap", ")", "{", "p", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Unlock", "(", ")", "\n\n", "p", ".", "ips", "=", "l", "\n", "}" ]
// SetIPAddresses sets the IP addresses for the processing unit
[ "SetIPAddresses", "sets", "the", "IP", "addresses", "for", "the", "processing", "unit" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/policy/policy.go#L283-L288
7,501
aporeto-inc/trireme-lib
policy/policy.go
ExposedServices
func (p *PUPolicy) ExposedServices() ApplicationServicesList { p.Lock() defer p.Unlock() return p.exposedServices }
go
func (p *PUPolicy) ExposedServices() ApplicationServicesList { p.Lock() defer p.Unlock() return p.exposedServices }
[ "func", "(", "p", "*", "PUPolicy", ")", "ExposedServices", "(", ")", "ApplicationServicesList", "{", "p", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Unlock", "(", ")", "\n\n", "return", "p", ".", "exposedServices", "\n", "}" ]
// ExposedServices returns the exposed services
[ "ExposedServices", "returns", "the", "exposed", "services" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/policy/policy.go#L291-L296
7,502
aporeto-inc/trireme-lib
policy/policy.go
DependentServices
func (p *PUPolicy) DependentServices() ApplicationServicesList { p.Lock() defer p.Unlock() return p.dependentServices }
go
func (p *PUPolicy) DependentServices() ApplicationServicesList { p.Lock() defer p.Unlock() return p.dependentServices }
[ "func", "(", "p", "*", "PUPolicy", ")", "DependentServices", "(", ")", "ApplicationServicesList", "{", "p", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Unlock", "(", ")", "\n\n", "return", "p", ".", "dependentServices", "\n", "}" ]
// DependentServices returns the external services.
[ "DependentServices", "returns", "the", "external", "services", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/policy/policy.go#L299-L304
7,503
aporeto-inc/trireme-lib
policy/policy.go
ServicesListeningPort
func (p *PUPolicy) ServicesListeningPort() string { p.Lock() defer p.Unlock() return strconv.Itoa(p.servicesListeningPort) }
go
func (p *PUPolicy) ServicesListeningPort() string { p.Lock() defer p.Unlock() return strconv.Itoa(p.servicesListeningPort) }
[ "func", "(", "p", "*", "PUPolicy", ")", "ServicesListeningPort", "(", ")", "string", "{", "p", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Unlock", "(", ")", "\n\n", "return", "strconv", ".", "Itoa", "(", "p", ".", "servicesListeningPort", ")", ...
// ServicesListeningPort returns the port that should be used by the proxies.
[ "ServicesListeningPort", "returns", "the", "port", "that", "should", "be", "used", "by", "the", "proxies", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/policy/policy.go#L307-L312
7,504
aporeto-inc/trireme-lib
policy/policy.go
UpdateDNSNetworks
func (p *PUPolicy) UpdateDNSNetworks(networks DNSRuleList) { p.Lock() defer p.Unlock() p.DNSACLs = make(DNSRuleList, len(networks)) copy(p.DNSACLs, networks) }
go
func (p *PUPolicy) UpdateDNSNetworks(networks DNSRuleList) { p.Lock() defer p.Unlock() p.DNSACLs = make(DNSRuleList, len(networks)) copy(p.DNSACLs, networks) }
[ "func", "(", "p", "*", "PUPolicy", ")", "UpdateDNSNetworks", "(", "networks", "DNSRuleList", ")", "{", "p", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Unlock", "(", ")", "\n\n", "p", ".", "DNSACLs", "=", "make", "(", "DNSRuleList", ",", "len", ...
// UpdateDNSNetworks updates the set of FQDN names allowed by the policy
[ "UpdateDNSNetworks", "updates", "the", "set", "of", "FQDN", "names", "allowed", "by", "the", "policy" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/policy/policy.go#L315-L322
7,505
aporeto-inc/trireme-lib
policy/policy.go
UpdateServiceCertificates
func (p *PUPolicy) UpdateServiceCertificates(cert, key string) { p.Lock() defer p.Unlock() p.servicesCertificate = cert p.servicesPrivateKey = key }
go
func (p *PUPolicy) UpdateServiceCertificates(cert, key string) { p.Lock() defer p.Unlock() p.servicesCertificate = cert p.servicesPrivateKey = key }
[ "func", "(", "p", "*", "PUPolicy", ")", "UpdateServiceCertificates", "(", "cert", ",", "key", "string", ")", "{", "p", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Unlock", "(", ")", "\n\n", "p", ".", "servicesCertificate", "=", "cert", "\n", "p"...
// UpdateServiceCertificates updates the certificate and private key of the policy
[ "UpdateServiceCertificates", "updates", "the", "certificate", "and", "private", "key", "of", "the", "policy" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/policy/policy.go#L325-L331
7,506
aporeto-inc/trireme-lib
policy/policy.go
ServiceCertificates
func (p *PUPolicy) ServiceCertificates() (string, string, string) { p.Lock() defer p.Unlock() return p.servicesCertificate, p.servicesPrivateKey, p.servicesCA }
go
func (p *PUPolicy) ServiceCertificates() (string, string, string) { p.Lock() defer p.Unlock() return p.servicesCertificate, p.servicesPrivateKey, p.servicesCA }
[ "func", "(", "p", "*", "PUPolicy", ")", "ServiceCertificates", "(", ")", "(", "string", ",", "string", ",", "string", ")", "{", "p", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Unlock", "(", ")", "\n\n", "return", "p", ".", "servicesCertificate"...
// ServiceCertificates returns the service certificate.
[ "ServiceCertificates", "returns", "the", "service", "certificate", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/policy/policy.go#L334-L339
7,507
aporeto-inc/trireme-lib
policy/policy.go
Scopes
func (p *PUPolicy) Scopes() []string { p.Lock() defer p.Unlock() return p.scopes }
go
func (p *PUPolicy) Scopes() []string { p.Lock() defer p.Unlock() return p.scopes }
[ "func", "(", "p", "*", "PUPolicy", ")", "Scopes", "(", ")", "[", "]", "string", "{", "p", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Unlock", "(", ")", "\n\n", "return", "p", ".", "scopes", "\n", "}" ]
// Scopes returns the scopes of the policy.
[ "Scopes", "returns", "the", "scopes", "of", "the", "policy", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/policy/policy.go#L342-L347
7,508
aporeto-inc/trireme-lib
policy/policy.go
ToPublicPolicy
func (p *PUPolicy) ToPublicPolicy() *PUPolicyPublic { p.Lock() defer p.Unlock() return &PUPolicyPublic{ ManagementID: p.managementID, TriremeAction: p.triremeAction, ApplicationACLs: p.applicationACLs.Copy(), NetworkACLs: p.networkACLs.Copy(), DNSACLs: p.DNSA...
go
func (p *PUPolicy) ToPublicPolicy() *PUPolicyPublic { p.Lock() defer p.Unlock() return &PUPolicyPublic{ ManagementID: p.managementID, TriremeAction: p.triremeAction, ApplicationACLs: p.applicationACLs.Copy(), NetworkACLs: p.networkACLs.Copy(), DNSACLs: p.DNSA...
[ "func", "(", "p", "*", "PUPolicy", ")", "ToPublicPolicy", "(", ")", "*", "PUPolicyPublic", "{", "p", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Unlock", "(", ")", "\n\n", "return", "&", "PUPolicyPublic", "{", "ManagementID", ":", "p", ".", "man...
// ToPublicPolicy converts the object to a marshallable object.
[ "ToPublicPolicy", "converts", "the", "object", "to", "a", "marshallable", "object", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/policy/policy.go#L350-L373
7,509
aporeto-inc/trireme-lib
policy/policy.go
ToPrivatePolicy
func (p *PUPolicyPublic) ToPrivatePolicy(convert bool) (*PUPolicy, error) { var err error exposedServices := ApplicationServicesList{} for _, e := range p.ExposedServices { if convert { e.UserAuthorizationHandler, err = usertokens.NewVerifier(e.UserAuthorizationHandler) if err != nil { return nil, fmt.E...
go
func (p *PUPolicyPublic) ToPrivatePolicy(convert bool) (*PUPolicy, error) { var err error exposedServices := ApplicationServicesList{} for _, e := range p.ExposedServices { if convert { e.UserAuthorizationHandler, err = usertokens.NewVerifier(e.UserAuthorizationHandler) if err != nil { return nil, fmt.E...
[ "func", "(", "p", "*", "PUPolicyPublic", ")", "ToPrivatePolicy", "(", "convert", "bool", ")", "(", "*", "PUPolicy", ",", "error", ")", "{", "var", "err", "error", "\n\n", "exposedServices", ":=", "ApplicationServicesList", "{", "}", "\n", "for", "_", ",", ...
// ToPrivatePolicy converts the object to a private object.
[ "ToPrivatePolicy", "converts", "the", "object", "to", "a", "private", "object", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/policy/policy.go#L398-L431
7,510
aporeto-inc/trireme-lib
controller/internal/enforcer/secretsproxy/transformer.go
NewGenericSecretsDriver
func NewGenericSecretsDriver(ca []byte, token string, network *common.Service) (SecretsDriver, error) { caPool := x509.NewCertPool() if !caPool.AppendCertsFromPEM(ca) { return nil, fmt.Errorf("No valid CA provided") } targetAddress := "" if len(network.FQDNs) > 0 { targetAddress = network.FQDNs[0] } else if...
go
func NewGenericSecretsDriver(ca []byte, token string, network *common.Service) (SecretsDriver, error) { caPool := x509.NewCertPool() if !caPool.AppendCertsFromPEM(ca) { return nil, fmt.Errorf("No valid CA provided") } targetAddress := "" if len(network.FQDNs) > 0 { targetAddress = network.FQDNs[0] } else if...
[ "func", "NewGenericSecretsDriver", "(", "ca", "[", "]", "byte", ",", "token", "string", ",", "network", "*", "common", ".", "Service", ")", "(", "SecretsDriver", ",", "error", ")", "{", "caPool", ":=", "x509", ".", "NewCertPool", "(", ")", "\n", "if", ...
// NewGenericSecretsDriver creates a new Kubernetes Secrets Driver. It // always uses the incluster config to automatically derive all the // necessary values.
[ "NewGenericSecretsDriver", "creates", "a", "new", "Kubernetes", "Secrets", "Driver", ".", "It", "always", "uses", "the", "incluster", "config", "to", "automatically", "derive", "all", "the", "necessary", "values", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/secretsproxy/transformer.go#L31-L65
7,511
aporeto-inc/trireme-lib
controller/internal/enforcer/secretsproxy/transformer.go
Transform
func (k *GenericSecretsDriver) Transform(r *http.Request) error { r.Host = k.targetURL.Host r.URL = k.targetURL r.Header.Add("Authorization", "Bearer "+k.token) return nil }
go
func (k *GenericSecretsDriver) Transform(r *http.Request) error { r.Host = k.targetURL.Host r.URL = k.targetURL r.Header.Add("Authorization", "Bearer "+k.token) return nil }
[ "func", "(", "k", "*", "GenericSecretsDriver", ")", "Transform", "(", "r", "*", "http", ".", "Request", ")", "error", "{", "r", ".", "Host", "=", "k", ".", "targetURL", ".", "Host", "\n", "r", ".", "URL", "=", "k", ".", "targetURL", "\n", "r", "....
// Transform transforms the request of the SecretsDriver
[ "Transform", "transforms", "the", "request", "of", "the", "SecretsDriver" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/secretsproxy/transformer.go#L73-L80
7,512
mattn/anko
internal/corelib/corelib.go
ValueEqual
func ValueEqual(v1 interface{}, v2 interface{}) bool { v1RV := reflect.ValueOf(v1) switch v1RV.Kind() { case reflect.Func: // This is best effort to check if functions match, but it could be wrong v2RV := reflect.ValueOf(v2) if !v1RV.IsValid() || !v2RV.IsValid() { if v1RV.IsValid() != !v2RV.IsValid() { ...
go
func ValueEqual(v1 interface{}, v2 interface{}) bool { v1RV := reflect.ValueOf(v1) switch v1RV.Kind() { case reflect.Func: // This is best effort to check if functions match, but it could be wrong v2RV := reflect.ValueOf(v2) if !v1RV.IsValid() || !v2RV.IsValid() { if v1RV.IsValid() != !v2RV.IsValid() { ...
[ "func", "ValueEqual", "(", "v1", "interface", "{", "}", ",", "v2", "interface", "{", "}", ")", "bool", "{", "v1RV", ":=", "reflect", ".", "ValueOf", "(", "v1", ")", "\n", "switch", "v1RV", ".", "Kind", "(", ")", "{", "case", "reflect", ".", "Func",...
// ValueEqual return true if v1 and v2 is same value. If passed function, does // extra checks otherwise just doing reflect.DeepEqual
[ "ValueEqual", "return", "true", "if", "v1", "and", "v2", "is", "same", "value", ".", "If", "passed", "function", "does", "extra", "checks", "otherwise", "just", "doing", "reflect", ".", "DeepEqual" ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/internal/corelib/corelib.go#L22-L52
7,513
mattn/anko
vm/vmStmt.go
Run
func Run(stmt ast.Stmt, env *Env) (interface{}, error) { return RunContext(context.Background(), stmt, env) }
go
func Run(stmt ast.Stmt, env *Env) (interface{}, error) { return RunContext(context.Background(), stmt, env) }
[ "func", "Run", "(", "stmt", "ast", ".", "Stmt", ",", "env", "*", "Env", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "return", "RunContext", "(", "context", ".", "Background", "(", ")", ",", "stmt", ",", "env", ")", "\n", "}" ]
// Run executes statement in the specified environment.
[ "Run", "executes", "statement", "in", "the", "specified", "environment", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/vmStmt.go#L12-L14
7,514
mattn/anko
vm/vmStmt.go
RunContext
func RunContext(ctx context.Context, stmt ast.Stmt, env *Env) (interface{}, error) { runInfo := runInfoStruct{ctx: ctx, env: env, stmt: stmt, rv: nilValue} runInfo.runSingleStmt() if runInfo.err == ErrReturn { runInfo.err = nil } return runInfo.rv.Interface(), runInfo.err }
go
func RunContext(ctx context.Context, stmt ast.Stmt, env *Env) (interface{}, error) { runInfo := runInfoStruct{ctx: ctx, env: env, stmt: stmt, rv: nilValue} runInfo.runSingleStmt() if runInfo.err == ErrReturn { runInfo.err = nil } return runInfo.rv.Interface(), runInfo.err }
[ "func", "RunContext", "(", "ctx", "context", ".", "Context", ",", "stmt", "ast", ".", "Stmt", ",", "env", "*", "Env", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "runInfo", ":=", "runInfoStruct", "{", "ctx", ":", "ctx", ",", "env", ":"...
// RunContext executes statement in the specified environment with context.
[ "RunContext", "executes", "statement", "in", "the", "specified", "environment", "with", "context", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/vmStmt.go#L17-L24
7,515
mattn/anko
vm/vm.go
newError
func newError(pos ast.Pos, err error) error { if err == nil { return nil } if pos == nil { return &Error{Message: err.Error(), Pos: ast.Position{Line: 1, Column: 1}} } return &Error{Message: err.Error(), Pos: pos.Position()} }
go
func newError(pos ast.Pos, err error) error { if err == nil { return nil } if pos == nil { return &Error{Message: err.Error(), Pos: ast.Position{Line: 1, Column: 1}} } return &Error{Message: err.Error(), Pos: pos.Position()} }
[ "func", "newError", "(", "pos", "ast", ".", "Pos", ",", "err", "error", ")", "error", "{", "if", "err", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "if", "pos", "==", "nil", "{", "return", "&", "Error", "{", "Message", ":", "err", ".", ...
// newError makes VM error from error
[ "newError", "makes", "VM", "error", "from", "error" ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/vm.go#L69-L77
7,516
mattn/anko
vm/vm.go
newStringError
func newStringError(pos ast.Pos, err string) error { if err == "" { return nil } if pos == nil { return &Error{Message: err, Pos: ast.Position{Line: 1, Column: 1}} } return &Error{Message: err, Pos: pos.Position()} }
go
func newStringError(pos ast.Pos, err string) error { if err == "" { return nil } if pos == nil { return &Error{Message: err, Pos: ast.Position{Line: 1, Column: 1}} } return &Error{Message: err, Pos: pos.Position()} }
[ "func", "newStringError", "(", "pos", "ast", ".", "Pos", ",", "err", "string", ")", "error", "{", "if", "err", "==", "\"", "\"", "{", "return", "nil", "\n", "}", "\n", "if", "pos", "==", "nil", "{", "return", "&", "Error", "{", "Message", ":", "e...
// newStringError makes VM error from string
[ "newStringError", "makes", "VM", "error", "from", "string" ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/vm.go#L80-L88
7,517
mattn/anko
vm/vm.go
equal
func equal(lhsV, rhsV reflect.Value) bool { lhsIsNil, rhsIsNil := isNil(lhsV), isNil(rhsV) if lhsIsNil && rhsIsNil { return true } if (!lhsIsNil && rhsIsNil) || (lhsIsNil && !rhsIsNil) { return false } if lhsV.Kind() == reflect.Interface || lhsV.Kind() == reflect.Ptr { lhsV = lhsV.Elem() } if rhsV.Kind() ...
go
func equal(lhsV, rhsV reflect.Value) bool { lhsIsNil, rhsIsNil := isNil(lhsV), isNil(rhsV) if lhsIsNil && rhsIsNil { return true } if (!lhsIsNil && rhsIsNil) || (lhsIsNil && !rhsIsNil) { return false } if lhsV.Kind() == reflect.Interface || lhsV.Kind() == reflect.Ptr { lhsV = lhsV.Elem() } if rhsV.Kind() ...
[ "func", "equal", "(", "lhsV", ",", "rhsV", "reflect", ".", "Value", ")", "bool", "{", "lhsIsNil", ",", "rhsIsNil", ":=", "isNil", "(", "lhsV", ")", ",", "isNil", "(", "rhsV", ")", "\n", "if", "lhsIsNil", "&&", "rhsIsNil", "{", "return", "true", "\n",...
// equal returns true when lhsV and rhsV is same value.
[ "equal", "returns", "true", "when", "lhsV", "and", "rhsV", "is", "same", "value", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/vm.go#L114-L173
7,518
mattn/anko
vm/vm.go
appendSlice
func appendSlice(expr ast.Expr, lhsV reflect.Value, rhsV reflect.Value) (reflect.Value, error) { lhsT := lhsV.Type().Elem() rhsT := rhsV.Type().Elem() if lhsT == rhsT { return reflect.AppendSlice(lhsV, rhsV), nil } if rhsT.ConvertibleTo(lhsT) { for i := 0; i < rhsV.Len(); i++ { lhsV = reflect.Append(lhsV,...
go
func appendSlice(expr ast.Expr, lhsV reflect.Value, rhsV reflect.Value) (reflect.Value, error) { lhsT := lhsV.Type().Elem() rhsT := rhsV.Type().Elem() if lhsT == rhsT { return reflect.AppendSlice(lhsV, rhsV), nil } if rhsT.ConvertibleTo(lhsT) { for i := 0; i < rhsV.Len(); i++ { lhsV = reflect.Append(lhsV,...
[ "func", "appendSlice", "(", "expr", "ast", ".", "Expr", ",", "lhsV", "reflect", ".", "Value", ",", "rhsV", "reflect", ".", "Value", ")", "(", "reflect", ".", "Value", ",", "error", ")", "{", "lhsT", ":=", "lhsV", ".", "Type", "(", ")", ".", "Elem",...
// appendSlice appends rhs to lhs // function assumes lhsV and rhsV are slice or array
[ "appendSlice", "appends", "rhs", "to", "lhs", "function", "assumes", "lhsV", "and", "rhsV", "are", "slice", "or", "array" ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/vm.go#L202-L260
7,519
mattn/anko
vm/vm.go
precedenceOfKinds
func precedenceOfKinds(kind1 reflect.Kind, kind2 reflect.Kind) reflect.Kind { if kind1 == kind2 { return kind1 } switch kind1 { case reflect.String: return kind1 case reflect.Float64, reflect.Float32: switch kind2 { case reflect.String: return kind2 } return kind1 case reflect.Int, reflect.Int8, re...
go
func precedenceOfKinds(kind1 reflect.Kind, kind2 reflect.Kind) reflect.Kind { if kind1 == kind2 { return kind1 } switch kind1 { case reflect.String: return kind1 case reflect.Float64, reflect.Float32: switch kind2 { case reflect.String: return kind2 } return kind1 case reflect.Int, reflect.Int8, re...
[ "func", "precedenceOfKinds", "(", "kind1", "reflect", ".", "Kind", ",", "kind2", "reflect", ".", "Kind", ")", "reflect", ".", "Kind", "{", "if", "kind1", "==", "kind2", "{", "return", "kind1", "\n", "}", "\n", "switch", "kind1", "{", "case", "reflect", ...
// precedenceOfKinds returns the greater of two kinds // string > float > int
[ "precedenceOfKinds", "returns", "the", "greater", "of", "two", "kinds", "string", ">", "float", ">", "int" ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/vm.go#L426-L446
7,520
mattn/anko
vm/vmToX.go
toString
func toString(v reflect.Value) string { if v.Kind() == reflect.Interface && !v.IsNil() { v = v.Elem() } if v.Kind() == reflect.Ptr { v = v.Elem() } if v.Kind() == reflect.String { return v.String() } return fmt.Sprint(v.Interface()) }
go
func toString(v reflect.Value) string { if v.Kind() == reflect.Interface && !v.IsNil() { v = v.Elem() } if v.Kind() == reflect.Ptr { v = v.Elem() } if v.Kind() == reflect.String { return v.String() } return fmt.Sprint(v.Interface()) }
[ "func", "toString", "(", "v", "reflect", ".", "Value", ")", "string", "{", "if", "v", ".", "Kind", "(", ")", "==", "reflect", ".", "Interface", "&&", "!", "v", ".", "IsNil", "(", ")", "{", "v", "=", "v", ".", "Elem", "(", ")", "\n", "}", "\n"...
// toString converts all reflect.Value-s into string.
[ "toString", "converts", "all", "reflect", ".", "Value", "-", "s", "into", "string", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/vmToX.go#L12-L23
7,521
mattn/anko
vm/vmToX.go
toBool
func toBool(v reflect.Value) bool { b, _ := tryToBool(v) return b }
go
func toBool(v reflect.Value) bool { b, _ := tryToBool(v) return b }
[ "func", "toBool", "(", "v", "reflect", ".", "Value", ")", "bool", "{", "b", ",", "_", ":=", "tryToBool", "(", "v", ")", "\n", "return", "b", "\n", "}" ]
// toBool converts all reflect.Value-s into bool.
[ "toBool", "converts", "all", "reflect", ".", "Value", "-", "s", "into", "bool", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/vmToX.go#L26-L29
7,522
mattn/anko
vm/vmToX.go
toFloat64
func toFloat64(v reflect.Value) float64 { f, _ := tryToFloat64(v) return f }
go
func toFloat64(v reflect.Value) float64 { f, _ := tryToFloat64(v) return f }
[ "func", "toFloat64", "(", "v", "reflect", ".", "Value", ")", "float64", "{", "f", ",", "_", ":=", "tryToFloat64", "(", "v", ")", "\n", "return", "f", "\n", "}" ]
// toFloat64 converts all reflect.Value-s into float64.
[ "toFloat64", "converts", "all", "reflect", ".", "Value", "-", "s", "into", "float64", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/vmToX.go#L71-L74
7,523
mattn/anko
vm/vmToX.go
toInt64
func toInt64(v reflect.Value) int64 { i, _ := tryToInt64(v) return i }
go
func toInt64(v reflect.Value) int64 { i, _ := tryToInt64(v) return i }
[ "func", "toInt64", "(", "v", "reflect", ".", "Value", ")", "int64", "{", "i", ",", "_", ":=", "tryToInt64", "(", "v", ")", "\n", "return", "i", "\n", "}" ]
// toInt64 converts all reflect.Value-s into int64.
[ "toInt64", "converts", "all", "reflect", ".", "Value", "-", "s", "into", "int64", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/vmToX.go#L103-L106
7,524
mattn/anko
vm/vmToX.go
toInt
func toInt(v reflect.Value) int { i, _ := tryToInt(v) return i }
go
func toInt(v reflect.Value) int { i, _ := tryToInt(v) return i }
[ "func", "toInt", "(", "v", "reflect", ".", "Value", ")", "int", "{", "i", ",", "_", ":=", "tryToInt", "(", "v", ")", "\n", "return", "i", "\n", "}" ]
// toInt converts all reflect.Value-s into int.
[ "toInt", "converts", "all", "reflect", ".", "Value", "-", "s", "into", "int", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/vmToX.go#L142-L145
7,525
mattn/anko
parser/lexer.go
isHex
func isHex(ch rune) bool { return ('0' <= ch && ch <= '9') || ('a' <= ch && ch <= 'f') || ('A' <= ch && ch <= 'F') }
go
func isHex(ch rune) bool { return ('0' <= ch && ch <= '9') || ('a' <= ch && ch <= 'f') || ('A' <= ch && ch <= 'F') }
[ "func", "isHex", "(", "ch", "rune", ")", "bool", "{", "return", "(", "'0'", "<=", "ch", "&&", "ch", "<=", "'9'", ")", "||", "(", "'a'", "<=", "ch", "&&", "ch", "<=", "'f'", ")", "||", "(", "'A'", "<=", "ch", "&&", "ch", "<=", "'F'", ")", "\...
// isHex returns true if the rune is a hex digits.
[ "isHex", "returns", "true", "if", "the", "rune", "is", "a", "hex", "digits", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/parser/lexer.go#L338-L340
7,526
mattn/anko
parser/lexer.go
peek
func (s *Scanner) peek() rune { if s.reachEOF() { return EOF } return s.src[s.offset] }
go
func (s *Scanner) peek() rune { if s.reachEOF() { return EOF } return s.src[s.offset] }
[ "func", "(", "s", "*", "Scanner", ")", "peek", "(", ")", "rune", "{", "if", "s", ".", "reachEOF", "(", ")", "{", "return", "EOF", "\n", "}", "\n", "return", "s", ".", "src", "[", "s", ".", "offset", "]", "\n", "}" ]
// peek returns current rune in the code.
[ "peek", "returns", "current", "rune", "in", "the", "code", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/parser/lexer.go#L353-L358
7,527
mattn/anko
parser/lexer.go
next
func (s *Scanner) next() { if !s.reachEOF() { if s.peek() == '\n' { s.lineHead = s.offset + 1 s.line++ } s.offset++ } }
go
func (s *Scanner) next() { if !s.reachEOF() { if s.peek() == '\n' { s.lineHead = s.offset + 1 s.line++ } s.offset++ } }
[ "func", "(", "s", "*", "Scanner", ")", "next", "(", ")", "{", "if", "!", "s", ".", "reachEOF", "(", ")", "{", "if", "s", ".", "peek", "(", ")", "==", "'\\n'", "{", "s", ".", "lineHead", "=", "s", ".", "offset", "+", "1", "\n", "s", ".", "...
// next moves offset to next.
[ "next", "moves", "offset", "to", "next", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/parser/lexer.go#L361-L369
7,528
mattn/anko
parser/lexer.go
pos
func (s *Scanner) pos() ast.Position { return ast.Position{Line: s.line + 1, Column: s.offset - s.lineHead + 1} }
go
func (s *Scanner) pos() ast.Position { return ast.Position{Line: s.line + 1, Column: s.offset - s.lineHead + 1} }
[ "func", "(", "s", "*", "Scanner", ")", "pos", "(", ")", "ast", ".", "Position", "{", "return", "ast", ".", "Position", "{", "Line", ":", "s", ".", "line", "+", "1", ",", "Column", ":", "s", ".", "offset", "-", "s", ".", "lineHead", "+", "1", ...
// pos returns the position of current.
[ "pos", "returns", "the", "position", "of", "current", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/parser/lexer.go#L392-L394
7,529
mattn/anko
parser/lexer.go
scanIdentifier
func (s *Scanner) scanIdentifier() (string, error) { var ret []rune for { if !isLetter(s.peek()) && !isDigit(s.peek()) { break } ret = append(ret, s.peek()) s.next() } return string(ret), nil }
go
func (s *Scanner) scanIdentifier() (string, error) { var ret []rune for { if !isLetter(s.peek()) && !isDigit(s.peek()) { break } ret = append(ret, s.peek()) s.next() } return string(ret), nil }
[ "func", "(", "s", "*", "Scanner", ")", "scanIdentifier", "(", ")", "(", "string", ",", "error", ")", "{", "var", "ret", "[", "]", "rune", "\n", "for", "{", "if", "!", "isLetter", "(", "s", ".", "peek", "(", ")", ")", "&&", "!", "isDigit", "(", ...
// scanIdentifier returns identifier beginning at current position.
[ "scanIdentifier", "returns", "identifier", "beginning", "at", "current", "position", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/parser/lexer.go#L404-L414
7,530
mattn/anko
parser/lexer.go
scanNumber
func (s *Scanner) scanNumber() (string, error) { result := []rune{s.peek()} s.next() if result[0] == '0' && (s.peek() == 'x' || s.peek() == 'X') { // hex result = append(result, 'x') s.next() for isHex(s.peek()) { result = append(result, s.peek()) s.next() } } else { // non-hex found := false ...
go
func (s *Scanner) scanNumber() (string, error) { result := []rune{s.peek()} s.next() if result[0] == '0' && (s.peek() == 'x' || s.peek() == 'X') { // hex result = append(result, 'x') s.next() for isHex(s.peek()) { result = append(result, s.peek()) s.next() } } else { // non-hex found := false ...
[ "func", "(", "s", "*", "Scanner", ")", "scanNumber", "(", ")", "(", "string", ",", "error", ")", "{", "result", ":=", "[", "]", "rune", "{", "s", ".", "peek", "(", ")", "}", "\n", "s", ".", "next", "(", ")", "\n\n", "if", "result", "[", "0", ...
// scanNumber returns number beginning at current position.
[ "scanNumber", "returns", "number", "beginning", "at", "current", "position", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/parser/lexer.go#L417-L478
7,531
mattn/anko
parser/lexer.go
scanRawString
func (s *Scanner) scanRawString(l rune) (string, error) { var ret []rune for { s.next() if s.peek() == EOF { return "", errors.New("unexpected EOF") } if s.peek() == l { s.next() break } ret = append(ret, s.peek()) } return string(ret), nil }
go
func (s *Scanner) scanRawString(l rune) (string, error) { var ret []rune for { s.next() if s.peek() == EOF { return "", errors.New("unexpected EOF") } if s.peek() == l { s.next() break } ret = append(ret, s.peek()) } return string(ret), nil }
[ "func", "(", "s", "*", "Scanner", ")", "scanRawString", "(", "l", "rune", ")", "(", "string", ",", "error", ")", "{", "var", "ret", "[", "]", "rune", "\n", "for", "{", "s", ".", "next", "(", ")", "\n", "if", "s", ".", "peek", "(", ")", "==", ...
// scanRawString returns raw-string starting at current position.
[ "scanRawString", "returns", "raw", "-", "string", "starting", "at", "current", "position", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/parser/lexer.go#L481-L495
7,532
mattn/anko
parser/lexer.go
scanString
func (s *Scanner) scanString(l rune) (string, error) { var ret []rune eos: for { s.next() switch s.peek() { case EOL: return "", errors.New("unexpected EOL") case EOF: return "", errors.New("unexpected EOF") case l: s.next() break eos case '\\': s.next() switch s.peek() { case 'b': ...
go
func (s *Scanner) scanString(l rune) (string, error) { var ret []rune eos: for { s.next() switch s.peek() { case EOL: return "", errors.New("unexpected EOL") case EOF: return "", errors.New("unexpected EOF") case l: s.next() break eos case '\\': s.next() switch s.peek() { case 'b': ...
[ "func", "(", "s", "*", "Scanner", ")", "scanString", "(", "l", "rune", ")", "(", "string", ",", "error", ")", "{", "var", "ret", "[", "]", "rune", "\n", "eos", ":", "for", "{", "s", ".", "next", "(", ")", "\n", "switch", "s", ".", "peek", "("...
// scanString returns string starting at current position. // This handles backslash escaping.
[ "scanString", "returns", "string", "starting", "at", "current", "position", ".", "This", "handles", "backslash", "escaping", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/parser/lexer.go#L499-L538
7,533
mattn/anko
parser/lexer.go
Lex
func (l *Lexer) Lex(lval *yySymType) int { tok, lit, pos, err := l.s.Scan() if err != nil { l.e = &Error{Message: err.Error(), Pos: pos, Fatal: true} } lval.tok = ast.Token{Tok: tok, Lit: lit} lval.tok.SetPosition(pos) l.lit = lit l.pos = pos return tok }
go
func (l *Lexer) Lex(lval *yySymType) int { tok, lit, pos, err := l.s.Scan() if err != nil { l.e = &Error{Message: err.Error(), Pos: pos, Fatal: true} } lval.tok = ast.Token{Tok: tok, Lit: lit} lval.tok.SetPosition(pos) l.lit = lit l.pos = pos return tok }
[ "func", "(", "l", "*", "Lexer", ")", "Lex", "(", "lval", "*", "yySymType", ")", "int", "{", "tok", ",", "lit", ",", "pos", ",", "err", ":=", "l", ".", "s", ".", "Scan", "(", ")", "\n", "if", "err", "!=", "nil", "{", "l", ".", "e", "=", "&...
// Lex scans the token and literals.
[ "Lex", "scans", "the", "token", "and", "literals", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/parser/lexer.go#L550-L560
7,534
mattn/anko
parser/lexer.go
Error
func (l *Lexer) Error(msg string) { l.e = &Error{Message: msg, Pos: l.pos, Fatal: false} }
go
func (l *Lexer) Error(msg string) { l.e = &Error{Message: msg, Pos: l.pos, Fatal: false} }
[ "func", "(", "l", "*", "Lexer", ")", "Error", "(", "msg", "string", ")", "{", "l", ".", "e", "=", "&", "Error", "{", "Message", ":", "msg", ",", "Pos", ":", "l", ".", "pos", ",", "Fatal", ":", "false", "}", "\n", "}" ]
// Error sets parse error.
[ "Error", "sets", "parse", "error", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/parser/lexer.go#L563-L565
7,535
mattn/anko
parser/lexer.go
Parse
func Parse(s *Scanner) (ast.Stmt, error) { l := Lexer{s: s} if yyParse(&l) != 0 { return nil, l.e } return l.stmt, l.e }
go
func Parse(s *Scanner) (ast.Stmt, error) { l := Lexer{s: s} if yyParse(&l) != 0 { return nil, l.e } return l.stmt, l.e }
[ "func", "Parse", "(", "s", "*", "Scanner", ")", "(", "ast", ".", "Stmt", ",", "error", ")", "{", "l", ":=", "Lexer", "{", "s", ":", "s", "}", "\n", "if", "yyParse", "(", "&", "l", ")", "!=", "0", "{", "return", "nil", ",", "l", ".", "e", ...
// Parse provides way to parse the code using Scanner.
[ "Parse", "provides", "way", "to", "parse", "the", "code", "using", "Scanner", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/parser/lexer.go#L568-L574
7,536
mattn/anko
parser/lexer.go
ParseSrc
func ParseSrc(src string) (ast.Stmt, error) { scanner := &Scanner{ src: []rune(src), } return Parse(scanner) }
go
func ParseSrc(src string) (ast.Stmt, error) { scanner := &Scanner{ src: []rune(src), } return Parse(scanner) }
[ "func", "ParseSrc", "(", "src", "string", ")", "(", "ast", ".", "Stmt", ",", "error", ")", "{", "scanner", ":=", "&", "Scanner", "{", "src", ":", "[", "]", "rune", "(", "src", ")", ",", "}", "\n", "return", "Parse", "(", "scanner", ")", "\n", "...
// ParseSrc provides way to parse the code from source.
[ "ParseSrc", "provides", "way", "to", "parse", "the", "code", "from", "source", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/parser/lexer.go#L582-L587
7,537
mattn/anko
packages/packages.go
DefineImport
func DefineImport(e *vm.Env) { e.Define("import", func(source string) *vm.Env { methods, ok := Packages[source] if !ok { panic(fmt.Sprintf("package '%s' not found", source)) } var err error pack := e.NewPackage(source) for methodName, methodValue := range methods { err = pack.Define(methodName, metho...
go
func DefineImport(e *vm.Env) { e.Define("import", func(source string) *vm.Env { methods, ok := Packages[source] if !ok { panic(fmt.Sprintf("package '%s' not found", source)) } var err error pack := e.NewPackage(source) for methodName, methodValue := range methods { err = pack.Define(methodName, metho...
[ "func", "DefineImport", "(", "e", "*", "vm", ".", "Env", ")", "{", "e", ".", "Define", "(", "\"", "\"", ",", "func", "(", "source", "string", ")", "*", "vm", ".", "Env", "{", "methods", ",", "ok", ":=", "Packages", "[", "source", "]", "\n", "if...
// DefineImport defines the vm import command that will import packages and package types when wanted
[ "DefineImport", "defines", "the", "vm", "import", "command", "that", "will", "import", "packages", "and", "package", "types", "when", "wanted" ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/packages/packages.go#L17-L42
7,538
mattn/anko
vm/vmConvertToX.go
reflectValueSlicetoInterfaceSlice
func reflectValueSlicetoInterfaceSlice(valueSlice []reflect.Value) reflect.Value { interfaceSlice := make([]interface{}, 0, len(valueSlice)) for _, value := range valueSlice { if value.Kind() == reflect.Interface && !value.IsNil() { value = value.Elem() } if value.CanInterface() { interfaceSlice = append(...
go
func reflectValueSlicetoInterfaceSlice(valueSlice []reflect.Value) reflect.Value { interfaceSlice := make([]interface{}, 0, len(valueSlice)) for _, value := range valueSlice { if value.Kind() == reflect.Interface && !value.IsNil() { value = value.Elem() } if value.CanInterface() { interfaceSlice = append(...
[ "func", "reflectValueSlicetoInterfaceSlice", "(", "valueSlice", "[", "]", "reflect", ".", "Value", ")", "reflect", ".", "Value", "{", "interfaceSlice", ":=", "make", "(", "[", "]", "interface", "{", "}", ",", "0", ",", "len", "(", "valueSlice", ")", ")", ...
// reflectValueSlicetoInterfaceSlice convert from a slice of reflect.Value to a interface slice // returned in normal reflect.Value form
[ "reflectValueSlicetoInterfaceSlice", "convert", "from", "a", "slice", "of", "reflect", ".", "Value", "to", "a", "interface", "slice", "returned", "in", "normal", "reflect", ".", "Value", "form" ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/vmConvertToX.go#L11-L24
7,539
mattn/anko
vm/vmConvertToX.go
convertReflectValueToType
func convertReflectValueToType(rv reflect.Value, rt reflect.Type) (reflect.Value, error) { if rt == interfaceType || rv.Type() == rt { // if reflect.Type is interface or the types match, return the provided reflect.Value return rv, nil } if rv.Type().ConvertibleTo(rt) { // if reflect can covert, do that conver...
go
func convertReflectValueToType(rv reflect.Value, rt reflect.Type) (reflect.Value, error) { if rt == interfaceType || rv.Type() == rt { // if reflect.Type is interface or the types match, return the provided reflect.Value return rv, nil } if rv.Type().ConvertibleTo(rt) { // if reflect can covert, do that conver...
[ "func", "convertReflectValueToType", "(", "rv", "reflect", ".", "Value", ",", "rt", "reflect", ".", "Type", ")", "(", "reflect", ".", "Value", ",", "error", ")", "{", "if", "rt", "==", "interfaceType", "||", "rv", ".", "Type", "(", ")", "==", "rt", "...
// convertReflectValueToType trys to covert the reflect.Value to the reflect.Type // if it can not, it returns the original rv and an error
[ "convertReflectValueToType", "trys", "to", "covert", "the", "reflect", ".", "Value", "to", "the", "reflect", ".", "Type", "if", "it", "can", "not", "it", "returns", "the", "original", "rv", "and", "an", "error" ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/vmConvertToX.go#L28-L79
7,540
mattn/anko
vm/vmConvertToX.go
convertSliceOrArray
func convertSliceOrArray(rv reflect.Value, rt reflect.Type) (reflect.Value, error) { rtElemType := rt.Elem() // try to covert elements to new slice/array var value reflect.Value if rt.Kind() == reflect.Slice { // make slice value = reflect.MakeSlice(rt, rv.Len(), rv.Len()) } else { // make array value = r...
go
func convertSliceOrArray(rv reflect.Value, rt reflect.Type) (reflect.Value, error) { rtElemType := rt.Elem() // try to covert elements to new slice/array var value reflect.Value if rt.Kind() == reflect.Slice { // make slice value = reflect.MakeSlice(rt, rv.Len(), rv.Len()) } else { // make array value = r...
[ "func", "convertSliceOrArray", "(", "rv", "reflect", ".", "Value", ",", "rt", "reflect", ".", "Type", ")", "(", "reflect", ".", "Value", ",", "error", ")", "{", "rtElemType", ":=", "rt", ".", "Elem", "(", ")", "\n\n", "// try to covert elements to new slice/...
// convertSliceOrArray trys to covert the reflect.Value slice or array to the slice or array reflect.Type
[ "convertSliceOrArray", "trys", "to", "covert", "the", "reflect", ".", "Value", "slice", "or", "array", "to", "the", "slice", "or", "array", "reflect", ".", "Type" ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/vmConvertToX.go#L82-L107
7,541
mattn/anko
vm/vmConvertToX.go
convertMap
func convertMap(rv reflect.Value, rt reflect.Type) (reflect.Value, error) { rtKey := rt.Key() rtElem := rt.Elem() // create new map // note creating slice as work around to create map // just doing MakeMap can give incorrect type for defined types newMap := reflect.MakeSlice(reflect.SliceOf(rt), 0, 1) newMap = ...
go
func convertMap(rv reflect.Value, rt reflect.Type) (reflect.Value, error) { rtKey := rt.Key() rtElem := rt.Elem() // create new map // note creating slice as work around to create map // just doing MakeMap can give incorrect type for defined types newMap := reflect.MakeSlice(reflect.SliceOf(rt), 0, 1) newMap = ...
[ "func", "convertMap", "(", "rv", "reflect", ".", "Value", ",", "rt", "reflect", ".", "Type", ")", "(", "reflect", ".", "Value", ",", "error", ")", "{", "rtKey", ":=", "rt", ".", "Key", "(", ")", "\n", "rtElem", ":=", "rt", ".", "Elem", "(", ")", ...
// convertMap trys to covert the reflect.Value map to the map reflect.Type
[ "convertMap", "trys", "to", "covert", "the", "reflect", ".", "Value", "map", "to", "the", "map", "reflect", ".", "Type" ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/vmConvertToX.go#L110-L140
7,542
mattn/anko
vm/vmConvertToX.go
convertVMFunctionToType
func convertVMFunctionToType(rv reflect.Value, rt reflect.Type) (reflect.Value, error) { // only translates runVMFunction type if !checkIfRunVMFunction(rv.Type()) { return rv, fmt.Errorf("invalid type conversion") } // create runVMConvertFunction to match reflect.Type // this function is being called by the Go ...
go
func convertVMFunctionToType(rv reflect.Value, rt reflect.Type) (reflect.Value, error) { // only translates runVMFunction type if !checkIfRunVMFunction(rv.Type()) { return rv, fmt.Errorf("invalid type conversion") } // create runVMConvertFunction to match reflect.Type // this function is being called by the Go ...
[ "func", "convertVMFunctionToType", "(", "rv", "reflect", ".", "Value", ",", "rt", "reflect", ".", "Type", ")", "(", "reflect", ".", "Value", ",", "error", ")", "{", "// only translates runVMFunction type", "if", "!", "checkIfRunVMFunction", "(", "rv", ".", "Ty...
// convertVMFunctionToType is for translating a runVMFunction into the correct type // so it can be passed to a Go function argument with the correct static types // it creates a translate function runVMConvertFunction
[ "convertVMFunctionToType", "is", "for", "translating", "a", "runVMFunction", "into", "the", "correct", "type", "so", "it", "can", "be", "passed", "to", "a", "Go", "function", "argument", "with", "the", "correct", "static", "types", "it", "creates", "a", "trans...
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/vmConvertToX.go#L145-L216
7,543
mattn/anko
core/toX.go
toSlice
func toSlice(from []interface{}, ptr interface{}) { // Value of the pointer to the target obj := reflect.Indirect(reflect.ValueOf(ptr)) // We can't just convert from interface{} to whatever the target is (diff memory layout), // so we need to create a New slice of the proper type and copy the values individually t...
go
func toSlice(from []interface{}, ptr interface{}) { // Value of the pointer to the target obj := reflect.Indirect(reflect.ValueOf(ptr)) // We can't just convert from interface{} to whatever the target is (diff memory layout), // so we need to create a New slice of the proper type and copy the values individually t...
[ "func", "toSlice", "(", "from", "[", "]", "interface", "{", "}", ",", "ptr", "interface", "{", "}", ")", "{", "// Value of the pointer to the target", "obj", ":=", "reflect", ".", "Indirect", "(", "reflect", ".", "ValueOf", "(", "ptr", ")", ")", "\n", "/...
// toSlice takes in a "generic" slice and converts and copies // it's elements into the typed slice pointed at by ptr. // Note that this is a costly operation.
[ "toSlice", "takes", "in", "a", "generic", "slice", "and", "converts", "and", "copies", "it", "s", "elements", "into", "the", "typed", "slice", "pointed", "at", "by", "ptr", ".", "Note", "that", "this", "is", "a", "costly", "operation", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/core/toX.go#L150-L171
7,544
mattn/anko
vm/vmExprFunction.go
funcExpr
func (runInfo *runInfoStruct) funcExpr() { funcExpr := runInfo.expr.(*ast.FuncExpr) // create the inTypes needed by reflect.FuncOf inTypes := make([]reflect.Type, len(funcExpr.Params)+1) // for runVMFunction first arg is always context inTypes[0] = contextType for i := 1; i < len(inTypes); i++ { inTypes[i] = r...
go
func (runInfo *runInfoStruct) funcExpr() { funcExpr := runInfo.expr.(*ast.FuncExpr) // create the inTypes needed by reflect.FuncOf inTypes := make([]reflect.Type, len(funcExpr.Params)+1) // for runVMFunction first arg is always context inTypes[0] = contextType for i := 1; i < len(inTypes); i++ { inTypes[i] = r...
[ "func", "(", "runInfo", "*", "runInfoStruct", ")", "funcExpr", "(", ")", "{", "funcExpr", ":=", "runInfo", ".", "expr", ".", "(", "*", "ast", ".", "FuncExpr", ")", "\n\n", "// create the inTypes needed by reflect.FuncOf", "inTypes", ":=", "make", "(", "[", "...
// funcExpr creates a function that reflect Call can use. // When called, it will run runVMFunction, to run the function statements
[ "funcExpr", "creates", "a", "function", "that", "reflect", "Call", "can", "use", ".", "When", "called", "it", "will", "run", "runVMFunction", "to", "run", "the", "function", "statements" ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/vmExprFunction.go#L14-L80
7,545
mattn/anko
vm/vmExprFunction.go
anonCallExpr
func (runInfo *runInfoStruct) anonCallExpr() { anonCallExpr := runInfo.expr.(*ast.AnonCallExpr) runInfo.expr = anonCallExpr.Expr runInfo.invokeExpr() if runInfo.err != nil { return } if runInfo.rv.Kind() == reflect.Interface && !runInfo.rv.IsNil() { runInfo.rv = runInfo.rv.Elem() } if runInfo.rv.Kind() !=...
go
func (runInfo *runInfoStruct) anonCallExpr() { anonCallExpr := runInfo.expr.(*ast.AnonCallExpr) runInfo.expr = anonCallExpr.Expr runInfo.invokeExpr() if runInfo.err != nil { return } if runInfo.rv.Kind() == reflect.Interface && !runInfo.rv.IsNil() { runInfo.rv = runInfo.rv.Elem() } if runInfo.rv.Kind() !=...
[ "func", "(", "runInfo", "*", "runInfoStruct", ")", "anonCallExpr", "(", ")", "{", "anonCallExpr", ":=", "runInfo", ".", "expr", ".", "(", "*", "ast", ".", "AnonCallExpr", ")", "\n\n", "runInfo", ".", "expr", "=", "anonCallExpr", ".", "Expr", "\n", "runIn...
// anonCallExpr handles ast.AnonCallExpr which calls a function anonymously
[ "anonCallExpr", "handles", "ast", ".", "AnonCallExpr", "which", "calls", "a", "function", "anonymously" ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/vmExprFunction.go#L83-L103
7,546
mattn/anko
vm/vmExprFunction.go
checkIfRunVMFunction
func checkIfRunVMFunction(rt reflect.Type) bool { if rt.NumIn() < 1 || rt.NumOut() != 2 || rt.In(0) != contextType || rt.Out(0) != reflectValueType || rt.Out(1) != reflectValueType { return false } if rt.NumIn() > 1 { if rt.IsVariadic() { if rt.In(rt.NumIn()-1) != interfaceSliceType { return false } ...
go
func checkIfRunVMFunction(rt reflect.Type) bool { if rt.NumIn() < 1 || rt.NumOut() != 2 || rt.In(0) != contextType || rt.Out(0) != reflectValueType || rt.Out(1) != reflectValueType { return false } if rt.NumIn() > 1 { if rt.IsVariadic() { if rt.In(rt.NumIn()-1) != interfaceSliceType { return false } ...
[ "func", "checkIfRunVMFunction", "(", "rt", "reflect", ".", "Type", ")", "bool", "{", "if", "rt", ".", "NumIn", "(", ")", "<", "1", "||", "rt", ".", "NumOut", "(", ")", "!=", "2", "||", "rt", ".", "In", "(", "0", ")", "!=", "contextType", "||", ...
// checkIfRunVMFunction checking the number and types of the reflect.Type. // If it matches the types for a runVMFunction this will return true, otherwise false
[ "checkIfRunVMFunction", "checking", "the", "number", "and", "types", "of", "the", "reflect", ".", "Type", ".", "If", "it", "matches", "the", "types", "for", "a", "runVMFunction", "this", "will", "return", "true", "otherwise", "false" ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/vmExprFunction.go#L189-L210
7,547
mattn/anko
vm/env.go
NewEnv
func NewEnv() *Env { return &Env{ env: make(map[string]reflect.Value), typ: make(map[string]reflect.Type), parent: nil, } }
go
func NewEnv() *Env { return &Env{ env: make(map[string]reflect.Value), typ: make(map[string]reflect.Type), parent: nil, } }
[ "func", "NewEnv", "(", ")", "*", "Env", "{", "return", "&", "Env", "{", "env", ":", "make", "(", "map", "[", "string", "]", "reflect", ".", "Value", ")", ",", "typ", ":", "make", "(", "map", "[", "string", "]", "reflect", ".", "Type", ")", ",",...
// NewEnv creates new global scope.
[ "NewEnv", "creates", "new", "global", "scope", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L48-L54
7,548
mattn/anko
vm/env.go
NewEnv
func (e *Env) NewEnv() *Env { return &Env{ env: make(map[string]reflect.Value), typ: make(map[string]reflect.Type), parent: e, name: e.name, } }
go
func (e *Env) NewEnv() *Env { return &Env{ env: make(map[string]reflect.Value), typ: make(map[string]reflect.Type), parent: e, name: e.name, } }
[ "func", "(", "e", "*", "Env", ")", "NewEnv", "(", ")", "*", "Env", "{", "return", "&", "Env", "{", "env", ":", "make", "(", "map", "[", "string", "]", "reflect", ".", "Value", ")", ",", "typ", ":", "make", "(", "map", "[", "string", "]", "ref...
// NewEnv creates new child scope.
[ "NewEnv", "creates", "new", "child", "scope", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L57-L64
7,549
mattn/anko
vm/env.go
NewPackage
func NewPackage(n string) *Env { return &Env{ env: make(map[string]reflect.Value), typ: make(map[string]reflect.Type), parent: nil, name: n, } }
go
func NewPackage(n string) *Env { return &Env{ env: make(map[string]reflect.Value), typ: make(map[string]reflect.Type), parent: nil, name: n, } }
[ "func", "NewPackage", "(", "n", "string", ")", "*", "Env", "{", "return", "&", "Env", "{", "env", ":", "make", "(", "map", "[", "string", "]", "reflect", ".", "Value", ")", ",", "typ", ":", "make", "(", "map", "[", "string", "]", "reflect", ".", ...
// NewPackage creates a new env with a name
[ "NewPackage", "creates", "a", "new", "env", "with", "a", "name" ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L67-L74
7,550
mattn/anko
vm/env.go
AddPackage
func (e *Env) AddPackage(name string, methods map[string]interface{}, types map[string]interface{}) (*Env, error) { if strings.Contains(name, ".") { return nil, fmt.Errorf("unknown symbol '%s'", name) } var err error pack := e.NewPackage(name) for methodName, methodValue := range methods { err = pack.Define(m...
go
func (e *Env) AddPackage(name string, methods map[string]interface{}, types map[string]interface{}) (*Env, error) { if strings.Contains(name, ".") { return nil, fmt.Errorf("unknown symbol '%s'", name) } var err error pack := e.NewPackage(name) for methodName, methodValue := range methods { err = pack.Define(m...
[ "func", "(", "e", "*", "Env", ")", "AddPackage", "(", "name", "string", ",", "methods", "map", "[", "string", "]", "interface", "{", "}", ",", "types", "map", "[", "string", "]", "interface", "{", "}", ")", "(", "*", "Env", ",", "error", ")", "{"...
// AddPackage creates a new env with a name that has methods and types in it. Created under the parent env
[ "AddPackage", "creates", "a", "new", "env", "with", "a", "name", "that", "has", "methods", "and", "types", "in", "it", ".", "Created", "under", "the", "parent", "env" ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L87-L110
7,551
mattn/anko
vm/env.go
NewModule
func (e *Env) NewModule(n string) *Env { m := &Env{ env: make(map[string]reflect.Value), typ: make(map[string]reflect.Type), parent: e, name: n, } e.Define(n, m) return m }
go
func (e *Env) NewModule(n string) *Env { m := &Env{ env: make(map[string]reflect.Value), typ: make(map[string]reflect.Type), parent: e, name: n, } e.Define(n, m) return m }
[ "func", "(", "e", "*", "Env", ")", "NewModule", "(", "n", "string", ")", "*", "Env", "{", "m", ":=", "&", "Env", "{", "env", ":", "make", "(", "map", "[", "string", "]", "reflect", ".", "Value", ")", ",", "typ", ":", "make", "(", "map", "[", ...
// NewModule creates new module.
[ "NewModule", "creates", "new", "module", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L118-L127
7,552
mattn/anko
vm/env.go
SetName
func (e *Env) SetName(n string) { e.Lock() e.name = n e.Unlock() }
go
func (e *Env) SetName(n string) { e.Lock() e.name = n e.Unlock() }
[ "func", "(", "e", "*", "Env", ")", "SetName", "(", "n", "string", ")", "{", "e", ".", "Lock", "(", ")", "\n", "e", ".", "name", "=", "n", "\n", "e", ".", "Unlock", "(", ")", "\n", "}" ]
// SetName sets a name of the scope. This means that the scope is module.
[ "SetName", "sets", "a", "name", "of", "the", "scope", ".", "This", "means", "that", "the", "scope", "is", "module", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L130-L134
7,553
mattn/anko
vm/env.go
GetName
func (e *Env) GetName() string { e.RLock() defer e.RUnlock() return e.name }
go
func (e *Env) GetName() string { e.RLock() defer e.RUnlock() return e.name }
[ "func", "(", "e", "*", "Env", ")", "GetName", "(", ")", "string", "{", "e", ".", "RLock", "(", ")", "\n", "defer", "e", ".", "RUnlock", "(", ")", "\n\n", "return", "e", ".", "name", "\n", "}" ]
// GetName returns module name.
[ "GetName", "returns", "module", "name", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L137-L142
7,554
mattn/anko
vm/env.go
Addr
func (e *Env) Addr(k string) (reflect.Value, error) { e.RLock() defer e.RUnlock() if v, ok := e.env[k]; ok { if v.CanAddr() { return v.Addr(), nil } return nilValue, fmt.Errorf("unaddressable") } if e.external != nil { v, err := e.external.Get(k) if err == nil { if v.CanAddr() { return v.Addr(...
go
func (e *Env) Addr(k string) (reflect.Value, error) { e.RLock() defer e.RUnlock() if v, ok := e.env[k]; ok { if v.CanAddr() { return v.Addr(), nil } return nilValue, fmt.Errorf("unaddressable") } if e.external != nil { v, err := e.external.Get(k) if err == nil { if v.CanAddr() { return v.Addr(...
[ "func", "(", "e", "*", "Env", ")", "Addr", "(", "k", "string", ")", "(", "reflect", ".", "Value", ",", "error", ")", "{", "e", ".", "RLock", "(", ")", "\n", "defer", "e", ".", "RUnlock", "(", ")", "\n\n", "if", "v", ",", "ok", ":=", "e", "....
// Addr returns pointer value which specified symbol. It goes to upper scope until // found or returns error.
[ "Addr", "returns", "pointer", "value", "which", "specified", "symbol", ".", "It", "goes", "to", "upper", "scope", "until", "found", "or", "returns", "error", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L146-L169
7,555
mattn/anko
vm/env.go
Type
func (e *Env) Type(k string) (reflect.Type, error) { e.RLock() defer e.RUnlock() if v, ok := e.typ[k]; ok { return v, nil } if e.external != nil { v, err := e.external.Type(k) if err == nil { return v, nil } } if e.parent == nil { if v, ok := basicTypes[k]; ok { return v, nil } return nilTyp...
go
func (e *Env) Type(k string) (reflect.Type, error) { e.RLock() defer e.RUnlock() if v, ok := e.typ[k]; ok { return v, nil } if e.external != nil { v, err := e.external.Type(k) if err == nil { return v, nil } } if e.parent == nil { if v, ok := basicTypes[k]; ok { return v, nil } return nilTyp...
[ "func", "(", "e", "*", "Env", ")", "Type", "(", "k", "string", ")", "(", "reflect", ".", "Type", ",", "error", ")", "{", "e", ".", "RLock", "(", ")", "\n", "defer", "e", ".", "RUnlock", "(", ")", "\n\n", "if", "v", ",", "ok", ":=", "e", "."...
// Type returns type which specified symbol. It goes to upper scope until // found or returns error.
[ "Type", "returns", "type", "which", "specified", "symbol", ".", "It", "goes", "to", "upper", "scope", "until", "found", "or", "returns", "error", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L173-L193
7,556
mattn/anko
vm/env.go
Get
func (e *Env) Get(k string) (interface{}, error) { rv, err := e.get(k) return rv.Interface(), err }
go
func (e *Env) Get(k string) (interface{}, error) { rv, err := e.get(k) return rv.Interface(), err }
[ "func", "(", "e", "*", "Env", ")", "Get", "(", "k", "string", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "rv", ",", "err", ":=", "e", ".", "get", "(", "k", ")", "\n", "return", "rv", ".", "Interface", "(", ")", ",", "err", "\n...
// Get returns value which specified symbol. It goes to upper scope until // found or returns error.
[ "Get", "returns", "value", "which", "specified", "symbol", ".", "It", "goes", "to", "upper", "scope", "until", "found", "or", "returns", "error", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L197-L200
7,557
mattn/anko
vm/env.go
Set
func (e *Env) Set(k string, v interface{}) error { if v == nil { return e.setValue(k, nilValue) } return e.setValue(k, reflect.ValueOf(v)) }
go
func (e *Env) Set(k string, v interface{}) error { if v == nil { return e.setValue(k, nilValue) } return e.setValue(k, reflect.ValueOf(v)) }
[ "func", "(", "e", "*", "Env", ")", "Set", "(", "k", "string", ",", "v", "interface", "{", "}", ")", "error", "{", "if", "v", "==", "nil", "{", "return", "e", ".", "setValue", "(", "k", ",", "nilValue", ")", "\n", "}", "\n", "return", "e", "."...
// Set modifies value which specified as symbol. It goes to upper scope until // found or returns error.
[ "Set", "modifies", "value", "which", "specified", "as", "symbol", ".", "It", "goes", "to", "upper", "scope", "until", "found", "or", "returns", "error", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L223-L228
7,558
mattn/anko
vm/env.go
DefineGlobal
func (e *Env) DefineGlobal(k string, v interface{}) error { for e.parent != nil { e = e.parent } return e.Define(k, v) }
go
func (e *Env) DefineGlobal(k string, v interface{}) error { for e.parent != nil { e = e.parent } return e.Define(k, v) }
[ "func", "(", "e", "*", "Env", ")", "DefineGlobal", "(", "k", "string", ",", "v", "interface", "{", "}", ")", "error", "{", "for", "e", ".", "parent", "!=", "nil", "{", "e", "=", "e", ".", "parent", "\n", "}", "\n", "return", "e", ".", "Define",...
// DefineGlobal defines symbol in global scope.
[ "DefineGlobal", "defines", "symbol", "in", "global", "scope", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L247-L252
7,559
mattn/anko
vm/env.go
defineGlobalValue
func (e *Env) defineGlobalValue(k string, v reflect.Value) error { for e.parent != nil { e = e.parent } return e.defineValue(k, v) }
go
func (e *Env) defineGlobalValue(k string, v reflect.Value) error { for e.parent != nil { e = e.parent } return e.defineValue(k, v) }
[ "func", "(", "e", "*", "Env", ")", "defineGlobalValue", "(", "k", "string", ",", "v", "reflect", ".", "Value", ")", "error", "{", "for", "e", ".", "parent", "!=", "nil", "{", "e", "=", "e", ".", "parent", "\n", "}", "\n", "return", "e", ".", "d...
// defineGlobalValue defines symbol in global scope.
[ "defineGlobalValue", "defines", "symbol", "in", "global", "scope", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L255-L260
7,560
mattn/anko
vm/env.go
Define
func (e *Env) Define(k string, v interface{}) error { if v == nil { return e.defineValue(k, nilValue) } return e.defineValue(k, reflect.ValueOf(v)) }
go
func (e *Env) Define(k string, v interface{}) error { if v == nil { return e.defineValue(k, nilValue) } return e.defineValue(k, reflect.ValueOf(v)) }
[ "func", "(", "e", "*", "Env", ")", "Define", "(", "k", "string", ",", "v", "interface", "{", "}", ")", "error", "{", "if", "v", "==", "nil", "{", "return", "e", ".", "defineValue", "(", "k", ",", "nilValue", ")", "\n", "}", "\n", "return", "e",...
// Define defines symbol in current scope.
[ "Define", "defines", "symbol", "in", "current", "scope", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L263-L268
7,561
mattn/anko
vm/env.go
defineValue
func (e *Env) defineValue(k string, v reflect.Value) error { if strings.Contains(k, ".") { return fmt.Errorf("unknown symbol '%s'", k) } e.Lock() e.env[k] = v e.Unlock() return nil }
go
func (e *Env) defineValue(k string, v reflect.Value) error { if strings.Contains(k, ".") { return fmt.Errorf("unknown symbol '%s'", k) } e.Lock() e.env[k] = v e.Unlock() return nil }
[ "func", "(", "e", "*", "Env", ")", "defineValue", "(", "k", "string", ",", "v", "reflect", ".", "Value", ")", "error", "{", "if", "strings", ".", "Contains", "(", "k", ",", "\"", "\"", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ...
// defineValue defines symbol in current scope.
[ "defineValue", "defines", "symbol", "in", "current", "scope", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L271-L281
7,562
mattn/anko
vm/env.go
Delete
func (e *Env) Delete(k string) error { if strings.Contains(k, ".") { return fmt.Errorf("Unknown symbol '%s'", k) } e.Lock() delete(e.env, k) e.Unlock() return nil }
go
func (e *Env) Delete(k string) error { if strings.Contains(k, ".") { return fmt.Errorf("Unknown symbol '%s'", k) } e.Lock() delete(e.env, k) e.Unlock() return nil }
[ "func", "(", "e", "*", "Env", ")", "Delete", "(", "k", "string", ")", "error", "{", "if", "strings", ".", "Contains", "(", "k", ",", "\"", "\"", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "k", ")", "\n", "}", "\n\n", "e",...
// Delete deletes symbol in current scope.
[ "Delete", "deletes", "symbol", "in", "current", "scope", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L284-L294
7,563
mattn/anko
vm/env.go
DeleteGlobal
func (e *Env) DeleteGlobal(k string) error { if e.parent == nil { return e.Delete(k) } e.RLock() _, ok := e.env[k] e.RUnlock() if ok { return e.Delete(k) } return e.parent.DeleteGlobal(k) }
go
func (e *Env) DeleteGlobal(k string) error { if e.parent == nil { return e.Delete(k) } e.RLock() _, ok := e.env[k] e.RUnlock() if ok { return e.Delete(k) } return e.parent.DeleteGlobal(k) }
[ "func", "(", "e", "*", "Env", ")", "DeleteGlobal", "(", "k", "string", ")", "error", "{", "if", "e", ".", "parent", "==", "nil", "{", "return", "e", ".", "Delete", "(", "k", ")", "\n", "}", "\n\n", "e", ".", "RLock", "(", ")", "\n", "_", ",",...
// DeleteGlobal deletes the first matching symbol found in current or parent scope.
[ "DeleteGlobal", "deletes", "the", "first", "matching", "symbol", "found", "in", "current", "or", "parent", "scope", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L297-L311
7,564
mattn/anko
vm/env.go
DefineGlobalType
func (e *Env) DefineGlobalType(k string, t interface{}) error { for e.parent != nil { e = e.parent } return e.DefineType(k, t) }
go
func (e *Env) DefineGlobalType(k string, t interface{}) error { for e.parent != nil { e = e.parent } return e.DefineType(k, t) }
[ "func", "(", "e", "*", "Env", ")", "DefineGlobalType", "(", "k", "string", ",", "t", "interface", "{", "}", ")", "error", "{", "for", "e", ".", "parent", "!=", "nil", "{", "e", "=", "e", ".", "parent", "\n", "}", "\n", "return", "e", ".", "Defi...
// DefineGlobalType defines type in global scope.
[ "DefineGlobalType", "defines", "type", "in", "global", "scope", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L314-L319
7,565
mattn/anko
vm/env.go
DefineGlobalReflectType
func (e *Env) DefineGlobalReflectType(k string, t reflect.Type) error { for e.parent != nil { e = e.parent } return e.DefineReflectType(k, t) }
go
func (e *Env) DefineGlobalReflectType(k string, t reflect.Type) error { for e.parent != nil { e = e.parent } return e.DefineReflectType(k, t) }
[ "func", "(", "e", "*", "Env", ")", "DefineGlobalReflectType", "(", "k", "string", ",", "t", "reflect", ".", "Type", ")", "error", "{", "for", "e", ".", "parent", "!=", "nil", "{", "e", "=", "e", ".", "parent", "\n", "}", "\n", "return", "e", ".",...
// DefineGlobalReflectType defines type in global scope.
[ "DefineGlobalReflectType", "defines", "type", "in", "global", "scope", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L322-L327
7,566
mattn/anko
vm/env.go
DefineType
func (e *Env) DefineType(k string, t interface{}) error { var typ reflect.Type if t == nil { typ = nilType } else { var ok bool typ, ok = t.(reflect.Type) if !ok { typ = reflect.TypeOf(t) } } return e.DefineReflectType(k, typ) }
go
func (e *Env) DefineType(k string, t interface{}) error { var typ reflect.Type if t == nil { typ = nilType } else { var ok bool typ, ok = t.(reflect.Type) if !ok { typ = reflect.TypeOf(t) } } return e.DefineReflectType(k, typ) }
[ "func", "(", "e", "*", "Env", ")", "DefineType", "(", "k", "string", ",", "t", "interface", "{", "}", ")", "error", "{", "var", "typ", "reflect", ".", "Type", "\n", "if", "t", "==", "nil", "{", "typ", "=", "nilType", "\n", "}", "else", "{", "va...
// DefineType defines type in current scope.
[ "DefineType", "defines", "type", "in", "current", "scope", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L330-L343
7,567
mattn/anko
vm/env.go
DefineReflectType
func (e *Env) DefineReflectType(k string, t reflect.Type) error { if strings.Contains(k, ".") { return fmt.Errorf("unknown symbol '%s'", k) } e.Lock() e.typ[k] = t e.Unlock() return nil }
go
func (e *Env) DefineReflectType(k string, t reflect.Type) error { if strings.Contains(k, ".") { return fmt.Errorf("unknown symbol '%s'", k) } e.Lock() e.typ[k] = t e.Unlock() return nil }
[ "func", "(", "e", "*", "Env", ")", "DefineReflectType", "(", "k", "string", ",", "t", "reflect", ".", "Type", ")", "error", "{", "if", "strings", ".", "Contains", "(", "k", ",", "\"", "\"", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"...
// DefineReflectType defines type in current scope.
[ "DefineReflectType", "defines", "type", "in", "current", "scope", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L346-L356
7,568
mattn/anko
vm/env.go
String
func (e *Env) String() string { e.RLock() defer e.RUnlock() return e.name }
go
func (e *Env) String() string { e.RLock() defer e.RUnlock() return e.name }
[ "func", "(", "e", "*", "Env", ")", "String", "(", ")", "string", "{", "e", ".", "RLock", "(", ")", "\n", "defer", "e", ".", "RUnlock", "(", ")", "\n\n", "return", "e", ".", "name", "\n", "}" ]
// String return the name of current scope.
[ "String", "return", "the", "name", "of", "current", "scope", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L359-L364
7,569
mattn/anko
vm/env.go
Dump
func (e *Env) Dump() { e.RLock() fmt.Printf("Name: %v\n", e.name) fmt.Printf("Has parent: %v\n", e.parent != nil) for k, v := range e.env { fmt.Printf("%v = %#v\n", k, v) } e.RUnlock() }
go
func (e *Env) Dump() { e.RLock() fmt.Printf("Name: %v\n", e.name) fmt.Printf("Has parent: %v\n", e.parent != nil) for k, v := range e.env { fmt.Printf("%v = %#v\n", k, v) } e.RUnlock() }
[ "func", "(", "e", "*", "Env", ")", "Dump", "(", ")", "{", "e", ".", "RLock", "(", ")", "\n", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "e", ".", "name", ")", "\n", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "e", ".", "par...
// Dump show symbol values in the scope.
[ "Dump", "show", "symbol", "values", "in", "the", "scope", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L367-L375
7,570
mattn/anko
vm/env.go
Execute
func (e *Env) Execute(src string) (interface{}, error) { return e.ExecuteContext(context.Background(), src) }
go
func (e *Env) Execute(src string) (interface{}, error) { return e.ExecuteContext(context.Background(), src) }
[ "func", "(", "e", "*", "Env", ")", "Execute", "(", "src", "string", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "return", "e", ".", "ExecuteContext", "(", "context", ".", "Background", "(", ")", ",", "src", ")", "\n", "}" ]
// Execute parses and runs source in current scope.
[ "Execute", "parses", "and", "runs", "source", "in", "current", "scope", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L378-L380
7,571
mattn/anko
vm/env.go
ExecuteContext
func (e *Env) ExecuteContext(ctx context.Context, src string) (interface{}, error) { stmt, err := parser.ParseSrc(src) if err != nil { return nilValue, err } return RunContext(ctx, stmt, e) }
go
func (e *Env) ExecuteContext(ctx context.Context, src string) (interface{}, error) { stmt, err := parser.ParseSrc(src) if err != nil { return nilValue, err } return RunContext(ctx, stmt, e) }
[ "func", "(", "e", "*", "Env", ")", "ExecuteContext", "(", "ctx", "context", ".", "Context", ",", "src", "string", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "stmt", ",", "err", ":=", "parser", ".", "ParseSrc", "(", "src", ")", "\n", ...
// ExecuteContext parses and runs source in current scope.
[ "ExecuteContext", "parses", "and", "runs", "source", "in", "current", "scope", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L383-L389
7,572
mattn/anko
vm/env.go
RunContext
func (e *Env) RunContext(ctx context.Context, stmt ast.Stmt) (interface{}, error) { return RunContext(ctx, stmt, e) }
go
func (e *Env) RunContext(ctx context.Context, stmt ast.Stmt) (interface{}, error) { return RunContext(ctx, stmt, e) }
[ "func", "(", "e", "*", "Env", ")", "RunContext", "(", "ctx", "context", ".", "Context", ",", "stmt", "ast", ".", "Stmt", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "return", "RunContext", "(", "ctx", ",", "stmt", ",", "e", ")", "\n"...
// RunContext runs statement in current scope.
[ "RunContext", "runs", "statement", "in", "current", "scope", "." ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L397-L399
7,573
mattn/anko
vm/env.go
Copy
func (e *Env) Copy() *Env { e.Lock() defer e.Unlock() copy := Env{ name: e.name, env: make(map[string]reflect.Value), typ: make(map[string]reflect.Type), parent: e.parent, external: e.external, } for name, value := range e.env { copy.env[name] = value } for name, typ := range e.typ { ...
go
func (e *Env) Copy() *Env { e.Lock() defer e.Unlock() copy := Env{ name: e.name, env: make(map[string]reflect.Value), typ: make(map[string]reflect.Type), parent: e.parent, external: e.external, } for name, value := range e.env { copy.env[name] = value } for name, typ := range e.typ { ...
[ "func", "(", "e", "*", "Env", ")", "Copy", "(", ")", "*", "Env", "{", "e", ".", "Lock", "(", ")", "\n", "defer", "e", ".", "Unlock", "(", ")", "\n", "copy", ":=", "Env", "{", "name", ":", "e", ".", "name", ",", "env", ":", "make", "(", "m...
// Copy the state of the virtual machine environment
[ "Copy", "the", "state", "of", "the", "virtual", "machine", "environment" ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L402-L419
7,574
mattn/anko
vm/env.go
DeepCopy
func (e *Env) DeepCopy() *Env { copy := e.Copy() if copy.parent != nil { copy.parent = copy.parent.DeepCopy() } return copy }
go
func (e *Env) DeepCopy() *Env { copy := e.Copy() if copy.parent != nil { copy.parent = copy.parent.DeepCopy() } return copy }
[ "func", "(", "e", "*", "Env", ")", "DeepCopy", "(", ")", "*", "Env", "{", "copy", ":=", "e", ".", "Copy", "(", ")", "\n", "if", "copy", ".", "parent", "!=", "nil", "{", "copy", ".", "parent", "=", "copy", ".", "parent", ".", "DeepCopy", "(", ...
// DeepCopy copy recursively the state of the virtual machine environment
[ "DeepCopy", "copy", "recursively", "the", "state", "of", "the", "virtual", "machine", "environment" ]
98bb0482ab4cd4fe854a932bbb0d818acc0e3338
https://github.com/mattn/anko/blob/98bb0482ab4cd4fe854a932bbb0d818acc0e3338/vm/env.go#L422-L428
7,575
gin-contrib/cors
cors.go
AddAllowMethods
func (c *Config) AddAllowMethods(methods ...string) { c.AllowMethods = append(c.AllowMethods, methods...) }
go
func (c *Config) AddAllowMethods(methods ...string) { c.AllowMethods = append(c.AllowMethods, methods...) }
[ "func", "(", "c", "*", "Config", ")", "AddAllowMethods", "(", "methods", "...", "string", ")", "{", "c", ".", "AllowMethods", "=", "append", "(", "c", ".", "AllowMethods", ",", "methods", "...", ")", "\n", "}" ]
// AddAllowMethods is allowed to add custom methods
[ "AddAllowMethods", "is", "allowed", "to", "add", "custom", "methods" ]
bd1331c62cae84c40036ce4e7d95b15d62157d4e
https://github.com/gin-contrib/cors/blob/bd1331c62cae84c40036ce4e7d95b15d62157d4e/cors.go#L59-L61
7,576
gin-contrib/cors
cors.go
AddAllowHeaders
func (c *Config) AddAllowHeaders(headers ...string) { c.AllowHeaders = append(c.AllowHeaders, headers...) }
go
func (c *Config) AddAllowHeaders(headers ...string) { c.AllowHeaders = append(c.AllowHeaders, headers...) }
[ "func", "(", "c", "*", "Config", ")", "AddAllowHeaders", "(", "headers", "...", "string", ")", "{", "c", ".", "AllowHeaders", "=", "append", "(", "c", ".", "AllowHeaders", ",", "headers", "...", ")", "\n", "}" ]
// AddAllowHeaders is allowed to add custom headers
[ "AddAllowHeaders", "is", "allowed", "to", "add", "custom", "headers" ]
bd1331c62cae84c40036ce4e7d95b15d62157d4e
https://github.com/gin-contrib/cors/blob/bd1331c62cae84c40036ce4e7d95b15d62157d4e/cors.go#L64-L66
7,577
gin-contrib/cors
cors.go
AddExposeHeaders
func (c *Config) AddExposeHeaders(headers ...string) { c.ExposeHeaders = append(c.ExposeHeaders, headers...) }
go
func (c *Config) AddExposeHeaders(headers ...string) { c.ExposeHeaders = append(c.ExposeHeaders, headers...) }
[ "func", "(", "c", "*", "Config", ")", "AddExposeHeaders", "(", "headers", "...", "string", ")", "{", "c", ".", "ExposeHeaders", "=", "append", "(", "c", ".", "ExposeHeaders", ",", "headers", "...", ")", "\n", "}" ]
// AddExposeHeaders is allowed to add custom expose headers
[ "AddExposeHeaders", "is", "allowed", "to", "add", "custom", "expose", "headers" ]
bd1331c62cae84c40036ce4e7d95b15d62157d4e
https://github.com/gin-contrib/cors/blob/bd1331c62cae84c40036ce4e7d95b15d62157d4e/cors.go#L69-L71
7,578
gin-contrib/cors
cors.go
Validate
func (c *Config) Validate() error { if c.AllowAllOrigins && (c.AllowOriginFunc != nil || len(c.AllowOrigins) > 0) { return errors.New("conflict settings: all origins are allowed. AllowOriginFunc or AllowOrigins is not needed") } if !c.AllowAllOrigins && c.AllowOriginFunc == nil && len(c.AllowOrigins) == 0 { retu...
go
func (c *Config) Validate() error { if c.AllowAllOrigins && (c.AllowOriginFunc != nil || len(c.AllowOrigins) > 0) { return errors.New("conflict settings: all origins are allowed. AllowOriginFunc or AllowOrigins is not needed") } if !c.AllowAllOrigins && c.AllowOriginFunc == nil && len(c.AllowOrigins) == 0 { retu...
[ "func", "(", "c", "*", "Config", ")", "Validate", "(", ")", "error", "{", "if", "c", ".", "AllowAllOrigins", "&&", "(", "c", ".", "AllowOriginFunc", "!=", "nil", "||", "len", "(", "c", ".", "AllowOrigins", ")", ">", "0", ")", "{", "return", "errors...
// Validate is check configuration of user defined.
[ "Validate", "is", "check", "configuration", "of", "user", "defined", "." ]
bd1331c62cae84c40036ce4e7d95b15d62157d4e
https://github.com/gin-contrib/cors/blob/bd1331c62cae84c40036ce4e7d95b15d62157d4e/cors.go#L98-L114
7,579
gin-contrib/cors
cors.go
DefaultConfig
func DefaultConfig() Config { return Config{ AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"}, AllowHeaders: []string{"Origin", "Content-Length", "Content-Type"}, AllowCredentials: false, MaxAge: 12 * time.Hour, } }
go
func DefaultConfig() Config { return Config{ AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"}, AllowHeaders: []string{"Origin", "Content-Length", "Content-Type"}, AllowCredentials: false, MaxAge: 12 * time.Hour, } }
[ "func", "DefaultConfig", "(", ")", "Config", "{", "return", "Config", "{", "AllowMethods", ":", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", "}", ",", "AllowHeaders", ":...
// DefaultConfig returns a generic default configuration mapped to localhost.
[ "DefaultConfig", "returns", "a", "generic", "default", "configuration", "mapped", "to", "localhost", "." ]
bd1331c62cae84c40036ce4e7d95b15d62157d4e
https://github.com/gin-contrib/cors/blob/bd1331c62cae84c40036ce4e7d95b15d62157d4e/cors.go#L149-L156
7,580
gin-contrib/cors
cors.go
Default
func Default() gin.HandlerFunc { config := DefaultConfig() config.AllowAllOrigins = true return New(config) }
go
func Default() gin.HandlerFunc { config := DefaultConfig() config.AllowAllOrigins = true return New(config) }
[ "func", "Default", "(", ")", "gin", ".", "HandlerFunc", "{", "config", ":=", "DefaultConfig", "(", ")", "\n", "config", ".", "AllowAllOrigins", "=", "true", "\n", "return", "New", "(", "config", ")", "\n", "}" ]
// Default returns the location middleware with default configuration.
[ "Default", "returns", "the", "location", "middleware", "with", "default", "configuration", "." ]
bd1331c62cae84c40036ce4e7d95b15d62157d4e
https://github.com/gin-contrib/cors/blob/bd1331c62cae84c40036ce4e7d95b15d62157d4e/cors.go#L159-L163
7,581
gin-contrib/cors
cors.go
New
func New(config Config) gin.HandlerFunc { cors := newCors(config) return func(c *gin.Context) { cors.applyCors(c) } }
go
func New(config Config) gin.HandlerFunc { cors := newCors(config) return func(c *gin.Context) { cors.applyCors(c) } }
[ "func", "New", "(", "config", "Config", ")", "gin", ".", "HandlerFunc", "{", "cors", ":=", "newCors", "(", "config", ")", "\n", "return", "func", "(", "c", "*", "gin", ".", "Context", ")", "{", "cors", ".", "applyCors", "(", "c", ")", "\n", "}", ...
// New returns the location middleware with user-defined custom configuration.
[ "New", "returns", "the", "location", "middleware", "with", "user", "-", "defined", "custom", "configuration", "." ]
bd1331c62cae84c40036ce4e7d95b15d62157d4e
https://github.com/gin-contrib/cors/blob/bd1331c62cae84c40036ce4e7d95b15d62157d4e/cors.go#L166-L171
7,582
pkg/profile
profile.go
MemProfileRate
func MemProfileRate(rate int) func(*Profile) { return func(p *Profile) { p.memProfileRate = rate p.mode = memMode } }
go
func MemProfileRate(rate int) func(*Profile) { return func(p *Profile) { p.memProfileRate = rate p.mode = memMode } }
[ "func", "MemProfileRate", "(", "rate", "int", ")", "func", "(", "*", "Profile", ")", "{", "return", "func", "(", "p", "*", "Profile", ")", "{", "p", ".", "memProfileRate", "=", "rate", "\n", "p", ".", "mode", "=", "memMode", "\n", "}", "\n", "}" ]
// MemProfileRate enables memory profiling at the preferred rate. // It disables any previous profiling settings.
[ "MemProfileRate", "enables", "memory", "profiling", "at", "the", "preferred", "rate", ".", "It", "disables", "any", "previous", "profiling", "settings", "." ]
f6fe06335df110bcf1ed6d4e852b760bfc15beee
https://github.com/pkg/profile/blob/f6fe06335df110bcf1ed6d4e852b760bfc15beee/profile.go#L78-L83
7,583
pkg/profile
profile.go
Stop
func (p *Profile) Stop() { if !atomic.CompareAndSwapUint32(&p.stopped, 0, 1) { // someone has already called close return } p.closer() atomic.StoreUint32(&started, 0) }
go
func (p *Profile) Stop() { if !atomic.CompareAndSwapUint32(&p.stopped, 0, 1) { // someone has already called close return } p.closer() atomic.StoreUint32(&started, 0) }
[ "func", "(", "p", "*", "Profile", ")", "Stop", "(", ")", "{", "if", "!", "atomic", ".", "CompareAndSwapUint32", "(", "&", "p", ".", "stopped", ",", "0", ",", "1", ")", "{", "// someone has already called close", "return", "\n", "}", "\n", "p", ".", "...
// Stop stops the profile and flushes any unwritten data.
[ "Stop", "stops", "the", "profile", "and", "flushes", "any", "unwritten", "data", "." ]
f6fe06335df110bcf1ed6d4e852b760bfc15beee
https://github.com/pkg/profile/blob/f6fe06335df110bcf1ed6d4e852b760bfc15beee/profile.go#L111-L118
7,584
uber-go/ratelimit
ratelimit.go
New
func New(rate int, opts ...Option) Limiter { l := &limiter{ perRequest: time.Second / time.Duration(rate), maxSlack: -10 * time.Second / time.Duration(rate), } for _, opt := range opts { opt(l) } if l.clock == nil { l.clock = clock.New() } return l }
go
func New(rate int, opts ...Option) Limiter { l := &limiter{ perRequest: time.Second / time.Duration(rate), maxSlack: -10 * time.Second / time.Duration(rate), } for _, opt := range opts { opt(l) } if l.clock == nil { l.clock = clock.New() } return l }
[ "func", "New", "(", "rate", "int", ",", "opts", "...", "Option", ")", "Limiter", "{", "l", ":=", "&", "limiter", "{", "perRequest", ":", "time", ".", "Second", "/", "time", ".", "Duration", "(", "rate", ")", ",", "maxSlack", ":", "-", "10", "*", ...
// New returns a Limiter that will limit to the given RPS.
[ "New", "returns", "a", "Limiter", "that", "will", "limit", "to", "the", "given", "RPS", "." ]
c15da02342779cb6dc027fc95ee2277787698f36
https://github.com/uber-go/ratelimit/blob/c15da02342779cb6dc027fc95ee2277787698f36/ratelimit.go#L62-L74
7,585
gorilla/schema
cache.go
newCache
func newCache() *cache { c := cache{ m: make(map[reflect.Type]*structInfo), regconv: make(map[reflect.Type]Converter), tag: "schema", } return &c }
go
func newCache() *cache { c := cache{ m: make(map[reflect.Type]*structInfo), regconv: make(map[reflect.Type]Converter), tag: "schema", } return &c }
[ "func", "newCache", "(", ")", "*", "cache", "{", "c", ":=", "cache", "{", "m", ":", "make", "(", "map", "[", "reflect", ".", "Type", "]", "*", "structInfo", ")", ",", "regconv", ":", "make", "(", "map", "[", "reflect", ".", "Type", "]", "Converte...
// newCache returns a new cache.
[ "newCache", "returns", "a", "new", "cache", "." ]
d768c7020973d24fadced0db99bfdc261241d85f
https://github.com/gorilla/schema/blob/d768c7020973d24fadced0db99bfdc261241d85f/cache.go#L18-L25
7,586
gorilla/schema
cache.go
registerConverter
func (c *cache) registerConverter(value interface{}, converterFunc Converter) { c.regconv[reflect.TypeOf(value)] = converterFunc }
go
func (c *cache) registerConverter(value interface{}, converterFunc Converter) { c.regconv[reflect.TypeOf(value)] = converterFunc }
[ "func", "(", "c", "*", "cache", ")", "registerConverter", "(", "value", "interface", "{", "}", ",", "converterFunc", "Converter", ")", "{", "c", ".", "regconv", "[", "reflect", ".", "TypeOf", "(", "value", ")", "]", "=", "converterFunc", "\n", "}" ]
// registerConverter registers a converter function for a custom type.
[ "registerConverter", "registers", "a", "converter", "function", "for", "a", "custom", "type", "." ]
d768c7020973d24fadced0db99bfdc261241d85f
https://github.com/gorilla/schema/blob/d768c7020973d24fadced0db99bfdc261241d85f/cache.go#L36-L38
7,587
gorilla/schema
cache.go
get
func (c *cache) get(t reflect.Type) *structInfo { c.l.RLock() info := c.m[t] c.l.RUnlock() if info == nil { info = c.create(t, "") c.l.Lock() c.m[t] = info c.l.Unlock() } return info }
go
func (c *cache) get(t reflect.Type) *structInfo { c.l.RLock() info := c.m[t] c.l.RUnlock() if info == nil { info = c.create(t, "") c.l.Lock() c.m[t] = info c.l.Unlock() } return info }
[ "func", "(", "c", "*", "cache", ")", "get", "(", "t", "reflect", ".", "Type", ")", "*", "structInfo", "{", "c", ".", "l", ".", "RLock", "(", ")", "\n", "info", ":=", "c", ".", "m", "[", "t", "]", "\n", "c", ".", "l", ".", "RUnlock", "(", ...
// get returns a cached structInfo, creating it if necessary.
[ "get", "returns", "a", "cached", "structInfo", "creating", "it", "if", "necessary", "." ]
d768c7020973d24fadced0db99bfdc261241d85f
https://github.com/gorilla/schema/blob/d768c7020973d24fadced0db99bfdc261241d85f/cache.go#L115-L126
7,588
gorilla/schema
cache.go
create
func (c *cache) create(t reflect.Type, parentAlias string) *structInfo { info := &structInfo{} var anonymousInfos []*structInfo for i := 0; i < t.NumField(); i++ { if f := c.createField(t.Field(i), parentAlias); f != nil { info.fields = append(info.fields, f) if ft := indirectType(f.typ); ft.Kind() == reflec...
go
func (c *cache) create(t reflect.Type, parentAlias string) *structInfo { info := &structInfo{} var anonymousInfos []*structInfo for i := 0; i < t.NumField(); i++ { if f := c.createField(t.Field(i), parentAlias); f != nil { info.fields = append(info.fields, f) if ft := indirectType(f.typ); ft.Kind() == reflec...
[ "func", "(", "c", "*", "cache", ")", "create", "(", "t", "reflect", ".", "Type", ",", "parentAlias", "string", ")", "*", "structInfo", "{", "info", ":=", "&", "structInfo", "{", "}", "\n", "var", "anonymousInfos", "[", "]", "*", "structInfo", "\n", "...
// create creates a structInfo with meta-data about a struct.
[ "create", "creates", "a", "structInfo", "with", "meta", "-", "data", "about", "a", "struct", "." ]
d768c7020973d24fadced0db99bfdc261241d85f
https://github.com/gorilla/schema/blob/d768c7020973d24fadced0db99bfdc261241d85f/cache.go#L129-L151
7,589
gorilla/schema
cache.go
createField
func (c *cache) createField(field reflect.StructField, parentAlias string) *fieldInfo { alias, options := fieldAlias(field, c.tag) if alias == "-" { // Ignore this field. return nil } canonicalAlias := alias if parentAlias != "" { canonicalAlias = parentAlias + "." + alias } // Check if the type is support...
go
func (c *cache) createField(field reflect.StructField, parentAlias string) *fieldInfo { alias, options := fieldAlias(field, c.tag) if alias == "-" { // Ignore this field. return nil } canonicalAlias := alias if parentAlias != "" { canonicalAlias = parentAlias + "." + alias } // Check if the type is support...
[ "func", "(", "c", "*", "cache", ")", "createField", "(", "field", "reflect", ".", "StructField", ",", "parentAlias", "string", ")", "*", "fieldInfo", "{", "alias", ",", "options", ":=", "fieldAlias", "(", "field", ",", "c", ".", "tag", ")", "\n", "if",...
// createField creates a fieldInfo for the given field.
[ "createField", "creates", "a", "fieldInfo", "for", "the", "given", "field", "." ]
d768c7020973d24fadced0db99bfdc261241d85f
https://github.com/gorilla/schema/blob/d768c7020973d24fadced0db99bfdc261241d85f/cache.go#L154-L201
7,590
gorilla/schema
cache.go
converter
func (c *cache) converter(t reflect.Type) Converter { return c.regconv[t] }
go
func (c *cache) converter(t reflect.Type) Converter { return c.regconv[t] }
[ "func", "(", "c", "*", "cache", ")", "converter", "(", "t", "reflect", ".", "Type", ")", "Converter", "{", "return", "c", ".", "regconv", "[", "t", "]", "\n", "}" ]
// converter returns the converter for a type.
[ "converter", "returns", "the", "converter", "for", "a", "type", "." ]
d768c7020973d24fadced0db99bfdc261241d85f
https://github.com/gorilla/schema/blob/d768c7020973d24fadced0db99bfdc261241d85f/cache.go#L204-L206
7,591
gorilla/schema
cache.go
fieldAlias
func fieldAlias(field reflect.StructField, tagName string) (alias string, options tagOptions) { if tag := field.Tag.Get(tagName); tag != "" { alias, options = parseTag(tag) } if alias == "" { alias = field.Name } return alias, options }
go
func fieldAlias(field reflect.StructField, tagName string) (alias string, options tagOptions) { if tag := field.Tag.Get(tagName); tag != "" { alias, options = parseTag(tag) } if alias == "" { alias = field.Name } return alias, options }
[ "func", "fieldAlias", "(", "field", "reflect", ".", "StructField", ",", "tagName", "string", ")", "(", "alias", "string", ",", "options", "tagOptions", ")", "{", "if", "tag", ":=", "field", ".", "Tag", ".", "Get", "(", "tagName", ")", ";", "tag", "!=",...
// fieldAlias parses a field tag to get a field alias.
[ "fieldAlias", "parses", "a", "field", "tag", "to", "get", "a", "field", "alias", "." ]
d768c7020973d24fadced0db99bfdc261241d85f
https://github.com/gorilla/schema/blob/d768c7020973d24fadced0db99bfdc261241d85f/cache.go#L276-L284
7,592
gorilla/schema
cache.go
parseTag
func parseTag(tag string) (string, tagOptions) { s := strings.Split(tag, ",") return s[0], s[1:] }
go
func parseTag(tag string) (string, tagOptions) { s := strings.Split(tag, ",") return s[0], s[1:] }
[ "func", "parseTag", "(", "tag", "string", ")", "(", "string", ",", "tagOptions", ")", "{", "s", ":=", "strings", ".", "Split", "(", "tag", ",", "\"", "\"", ")", "\n", "return", "s", "[", "0", "]", ",", "s", "[", "1", ":", "]", "\n", "}" ]
// parseTag splits a struct field's url tag into its name and comma-separated // options.
[ "parseTag", "splits", "a", "struct", "field", "s", "url", "tag", "into", "its", "name", "and", "comma", "-", "separated", "options", "." ]
d768c7020973d24fadced0db99bfdc261241d85f
https://github.com/gorilla/schema/blob/d768c7020973d24fadced0db99bfdc261241d85f/cache.go#L292-L295
7,593
gorilla/schema
cache.go
Contains
func (o tagOptions) Contains(option string) bool { for _, s := range o { if s == option { return true } } return false }
go
func (o tagOptions) Contains(option string) bool { for _, s := range o { if s == option { return true } } return false }
[ "func", "(", "o", "tagOptions", ")", "Contains", "(", "option", "string", ")", "bool", "{", "for", "_", ",", "s", ":=", "range", "o", "{", "if", "s", "==", "option", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ...
// Contains checks whether the tagOptions contains the specified option.
[ "Contains", "checks", "whether", "the", "tagOptions", "contains", "the", "specified", "option", "." ]
d768c7020973d24fadced0db99bfdc261241d85f
https://github.com/gorilla/schema/blob/d768c7020973d24fadced0db99bfdc261241d85f/cache.go#L298-L305
7,594
gorilla/schema
decoder.go
RegisterConverter
func (d *Decoder) RegisterConverter(value interface{}, converterFunc Converter) { d.cache.registerConverter(value, converterFunc) }
go
func (d *Decoder) RegisterConverter(value interface{}, converterFunc Converter) { d.cache.registerConverter(value, converterFunc) }
[ "func", "(", "d", "*", "Decoder", ")", "RegisterConverter", "(", "value", "interface", "{", "}", ",", "converterFunc", "Converter", ")", "{", "d", ".", "cache", ".", "registerConverter", "(", "value", ",", "converterFunc", ")", "\n", "}" ]
// RegisterConverter registers a converter function for a custom type.
[ "RegisterConverter", "registers", "a", "converter", "function", "for", "a", "custom", "type", "." ]
d768c7020973d24fadced0db99bfdc261241d85f
https://github.com/gorilla/schema/blob/d768c7020973d24fadced0db99bfdc261241d85f/decoder.go#L58-L60
7,595
gorilla/schema
decoder.go
checkRequired
func (d *Decoder) checkRequired(t reflect.Type, src map[string][]string) MultiError { m, errs := d.findRequiredFields(t, "", "") for key, fields := range m { if isEmptyFields(fields, src) { errs[key] = EmptyFieldError{Key: key} } } return errs }
go
func (d *Decoder) checkRequired(t reflect.Type, src map[string][]string) MultiError { m, errs := d.findRequiredFields(t, "", "") for key, fields := range m { if isEmptyFields(fields, src) { errs[key] = EmptyFieldError{Key: key} } } return errs }
[ "func", "(", "d", "*", "Decoder", ")", "checkRequired", "(", "t", "reflect", ".", "Type", ",", "src", "map", "[", "string", "]", "[", "]", "string", ")", "MultiError", "{", "m", ",", "errs", ":=", "d", ".", "findRequiredFields", "(", "t", ",", "\""...
// checkRequired checks whether required fields are empty // // check type t recursively if t has struct fields. // // src is the source map for decoding, we use it here to see if those required fields are included in src
[ "checkRequired", "checks", "whether", "required", "fields", "are", "empty", "check", "type", "t", "recursively", "if", "t", "has", "struct", "fields", ".", "src", "is", "the", "source", "map", "for", "decoding", "we", "use", "it", "here", "to", "see", "if"...
d768c7020973d24fadced0db99bfdc261241d85f
https://github.com/gorilla/schema/blob/d768c7020973d24fadced0db99bfdc261241d85f/decoder.go#L99-L107
7,596
gorilla/schema
decoder.go
findRequiredFields
func (d *Decoder) findRequiredFields(t reflect.Type, canonicalPrefix, searchPrefix string) (map[string][]fieldWithPrefix, MultiError) { struc := d.cache.get(t) if struc == nil { // unexpect, cache.get never return nil return nil, MultiError{canonicalPrefix + "*": errors.New("cache fail")} } m := map[string][]f...
go
func (d *Decoder) findRequiredFields(t reflect.Type, canonicalPrefix, searchPrefix string) (map[string][]fieldWithPrefix, MultiError) { struc := d.cache.get(t) if struc == nil { // unexpect, cache.get never return nil return nil, MultiError{canonicalPrefix + "*": errors.New("cache fail")} } m := map[string][]f...
[ "func", "(", "d", "*", "Decoder", ")", "findRequiredFields", "(", "t", "reflect", ".", "Type", ",", "canonicalPrefix", ",", "searchPrefix", "string", ")", "(", "map", "[", "string", "]", "[", "]", "fieldWithPrefix", ",", "MultiError", ")", "{", "struc", ...
// findRequiredFields recursively searches the struct type t for required fields. // // canonicalPrefix and searchPrefix are used to resolve full paths in dotted notation // for nested struct fields. canonicalPrefix is a complete path which never omits // any embedded struct fields. searchPrefix is a user-friendly path...
[ "findRequiredFields", "recursively", "searches", "the", "struct", "type", "t", "for", "required", "fields", ".", "canonicalPrefix", "and", "searchPrefix", "are", "used", "to", "resolve", "full", "paths", "in", "dotted", "notation", "for", "nested", "struct", "fiel...
d768c7020973d24fadced0db99bfdc261241d85f
https://github.com/gorilla/schema/blob/d768c7020973d24fadced0db99bfdc261241d85f/decoder.go#L115-L144
7,597
gorilla/schema
decoder.go
isEmptyFields
func isEmptyFields(fields []fieldWithPrefix, src map[string][]string) bool { for _, f := range fields { for _, path := range f.paths(f.prefix) { if !isEmpty(f.typ, src[path]) { return false } } } return true }
go
func isEmptyFields(fields []fieldWithPrefix, src map[string][]string) bool { for _, f := range fields { for _, path := range f.paths(f.prefix) { if !isEmpty(f.typ, src[path]) { return false } } } return true }
[ "func", "isEmptyFields", "(", "fields", "[", "]", "fieldWithPrefix", ",", "src", "map", "[", "string", "]", "[", "]", "string", ")", "bool", "{", "for", "_", ",", "f", ":=", "range", "fields", "{", "for", "_", ",", "path", ":=", "range", "f", ".", ...
// isEmptyFields returns true if all of specified fields are empty.
[ "isEmptyFields", "returns", "true", "if", "all", "of", "specified", "fields", "are", "empty", "." ]
d768c7020973d24fadced0db99bfdc261241d85f
https://github.com/gorilla/schema/blob/d768c7020973d24fadced0db99bfdc261241d85f/decoder.go#L152-L161
7,598
gorilla/schema
decoder.go
isEmpty
func isEmpty(t reflect.Type, value []string) bool { if len(value) == 0 { return true } switch t.Kind() { case boolType, float32Type, float64Type, intType, int8Type, int32Type, int64Type, stringType, uint8Type, uint16Type, uint32Type, uint64Type: return len(value[0]) == 0 } return false }
go
func isEmpty(t reflect.Type, value []string) bool { if len(value) == 0 { return true } switch t.Kind() { case boolType, float32Type, float64Type, intType, int8Type, int32Type, int64Type, stringType, uint8Type, uint16Type, uint32Type, uint64Type: return len(value[0]) == 0 } return false }
[ "func", "isEmpty", "(", "t", "reflect", ".", "Type", ",", "value", "[", "]", "string", ")", "bool", "{", "if", "len", "(", "value", ")", "==", "0", "{", "return", "true", "\n", "}", "\n", "switch", "t", ".", "Kind", "(", ")", "{", "case", "bool...
// isEmpty returns true if value is empty for specific type
[ "isEmpty", "returns", "true", "if", "value", "is", "empty", "for", "specific", "type" ]
d768c7020973d24fadced0db99bfdc261241d85f
https://github.com/gorilla/schema/blob/d768c7020973d24fadced0db99bfdc261241d85f/decoder.go#L164-L173
7,599
gorilla/schema
encoder.go
NewEncoder
func NewEncoder() *Encoder { return &Encoder{cache: newCache(), regenc: make(map[reflect.Type]encoderFunc)} }
go
func NewEncoder() *Encoder { return &Encoder{cache: newCache(), regenc: make(map[reflect.Type]encoderFunc)} }
[ "func", "NewEncoder", "(", ")", "*", "Encoder", "{", "return", "&", "Encoder", "{", "cache", ":", "newCache", "(", ")", ",", "regenc", ":", "make", "(", "map", "[", "reflect", ".", "Type", "]", "encoderFunc", ")", "}", "\n", "}" ]
// NewEncoder returns a new Encoder with defaults.
[ "NewEncoder", "returns", "a", "new", "Encoder", "with", "defaults", "." ]
d768c7020973d24fadced0db99bfdc261241d85f
https://github.com/gorilla/schema/blob/d768c7020973d24fadced0db99bfdc261241d85f/encoder.go#L19-L21