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
10,300
go-openapi/runtime
client/runtime.go
TLSTransport
func TLSTransport(opts TLSClientOptions) (http.RoundTripper, error) { cfg, err := TLSClientAuth(opts) if err != nil { return nil, err } return &http.Transport{TLSClientConfig: cfg}, nil }
go
func TLSTransport(opts TLSClientOptions) (http.RoundTripper, error) { cfg, err := TLSClientAuth(opts) if err != nil { return nil, err } return &http.Transport{TLSClientConfig: cfg}, nil }
[ "func", "TLSTransport", "(", "opts", "TLSClientOptions", ")", "(", "http", ".", "RoundTripper", ",", "error", ")", "{", "cfg", ",", "err", ":=", "TLSClientAuth", "(", "opts", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "http", ".", "Transport", "{", "TLSClientConfig", ":", "cfg", "}", ",", "nil", "\n", "}" ]
// TLSTransport creates a http client transport suitable for mutual tls auth
[ "TLSTransport", "creates", "a", "http", "client", "transport", "suitable", "for", "mutual", "tls", "auth" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/client/runtime.go#L154-L161
10,301
go-openapi/runtime
client/runtime.go
TLSClient
func TLSClient(opts TLSClientOptions) (*http.Client, error) { transport, err := TLSTransport(opts) if err != nil { return nil, err } return &http.Client{Transport: transport}, nil }
go
func TLSClient(opts TLSClientOptions) (*http.Client, error) { transport, err := TLSTransport(opts) if err != nil { return nil, err } return &http.Client{Transport: transport}, nil }
[ "func", "TLSClient", "(", "opts", "TLSClientOptions", ")", "(", "*", "http", ".", "Client", ",", "error", ")", "{", "transport", ",", "err", ":=", "TLSTransport", "(", "opts", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "http", ".", "Client", "{", "Transport", ":", "transport", "}", ",", "nil", "\n", "}" ]
// TLSClient creates a http.Client for mutual auth
[ "TLSClient", "creates", "a", "http", ".", "Client", "for", "mutual", "auth" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/client/runtime.go#L164-L170
10,302
go-openapi/runtime
client/runtime.go
New
func New(host, basePath string, schemes []string) *Runtime { var rt Runtime rt.DefaultMediaType = runtime.JSONMime // TODO: actually infer this stuff from the spec rt.Consumers = map[string]runtime.Consumer{ runtime.JSONMime: runtime.JSONConsumer(), runtime.XMLMime: runtime.XMLConsumer(), runtime.TextMime: runtime.TextConsumer(), runtime.HTMLMime: runtime.TextConsumer(), runtime.CSVMime: runtime.CSVConsumer(), runtime.DefaultMime: runtime.ByteStreamConsumer(), } rt.Producers = map[string]runtime.Producer{ runtime.JSONMime: runtime.JSONProducer(), runtime.XMLMime: runtime.XMLProducer(), runtime.TextMime: runtime.TextProducer(), runtime.HTMLMime: runtime.TextProducer(), runtime.CSVMime: runtime.CSVProducer(), runtime.DefaultMime: runtime.ByteStreamProducer(), } rt.Transport = http.DefaultTransport rt.Jar = nil rt.Host = host rt.BasePath = basePath rt.Context = context.Background() rt.clientOnce = new(sync.Once) if !strings.HasPrefix(rt.BasePath, "/") { rt.BasePath = "/" + rt.BasePath } rt.Debug = logger.DebugEnabled() rt.logger = logger.StandardLogger{} if len(schemes) > 0 { rt.schemes = schemes } return &rt }
go
func New(host, basePath string, schemes []string) *Runtime { var rt Runtime rt.DefaultMediaType = runtime.JSONMime // TODO: actually infer this stuff from the spec rt.Consumers = map[string]runtime.Consumer{ runtime.JSONMime: runtime.JSONConsumer(), runtime.XMLMime: runtime.XMLConsumer(), runtime.TextMime: runtime.TextConsumer(), runtime.HTMLMime: runtime.TextConsumer(), runtime.CSVMime: runtime.CSVConsumer(), runtime.DefaultMime: runtime.ByteStreamConsumer(), } rt.Producers = map[string]runtime.Producer{ runtime.JSONMime: runtime.JSONProducer(), runtime.XMLMime: runtime.XMLProducer(), runtime.TextMime: runtime.TextProducer(), runtime.HTMLMime: runtime.TextProducer(), runtime.CSVMime: runtime.CSVProducer(), runtime.DefaultMime: runtime.ByteStreamProducer(), } rt.Transport = http.DefaultTransport rt.Jar = nil rt.Host = host rt.BasePath = basePath rt.Context = context.Background() rt.clientOnce = new(sync.Once) if !strings.HasPrefix(rt.BasePath, "/") { rt.BasePath = "/" + rt.BasePath } rt.Debug = logger.DebugEnabled() rt.logger = logger.StandardLogger{} if len(schemes) > 0 { rt.schemes = schemes } return &rt }
[ "func", "New", "(", "host", ",", "basePath", "string", ",", "schemes", "[", "]", "string", ")", "*", "Runtime", "{", "var", "rt", "Runtime", "\n", "rt", ".", "DefaultMediaType", "=", "runtime", ".", "JSONMime", "\n\n", "// TODO: actually infer this stuff from the spec", "rt", ".", "Consumers", "=", "map", "[", "string", "]", "runtime", ".", "Consumer", "{", "runtime", ".", "JSONMime", ":", "runtime", ".", "JSONConsumer", "(", ")", ",", "runtime", ".", "XMLMime", ":", "runtime", ".", "XMLConsumer", "(", ")", ",", "runtime", ".", "TextMime", ":", "runtime", ".", "TextConsumer", "(", ")", ",", "runtime", ".", "HTMLMime", ":", "runtime", ".", "TextConsumer", "(", ")", ",", "runtime", ".", "CSVMime", ":", "runtime", ".", "CSVConsumer", "(", ")", ",", "runtime", ".", "DefaultMime", ":", "runtime", ".", "ByteStreamConsumer", "(", ")", ",", "}", "\n", "rt", ".", "Producers", "=", "map", "[", "string", "]", "runtime", ".", "Producer", "{", "runtime", ".", "JSONMime", ":", "runtime", ".", "JSONProducer", "(", ")", ",", "runtime", ".", "XMLMime", ":", "runtime", ".", "XMLProducer", "(", ")", ",", "runtime", ".", "TextMime", ":", "runtime", ".", "TextProducer", "(", ")", ",", "runtime", ".", "HTMLMime", ":", "runtime", ".", "TextProducer", "(", ")", ",", "runtime", ".", "CSVMime", ":", "runtime", ".", "CSVProducer", "(", ")", ",", "runtime", ".", "DefaultMime", ":", "runtime", ".", "ByteStreamProducer", "(", ")", ",", "}", "\n", "rt", ".", "Transport", "=", "http", ".", "DefaultTransport", "\n", "rt", ".", "Jar", "=", "nil", "\n", "rt", ".", "Host", "=", "host", "\n", "rt", ".", "BasePath", "=", "basePath", "\n", "rt", ".", "Context", "=", "context", ".", "Background", "(", ")", "\n", "rt", ".", "clientOnce", "=", "new", "(", "sync", ".", "Once", ")", "\n", "if", "!", "strings", ".", "HasPrefix", "(", "rt", ".", "BasePath", ",", "\"", "\"", ")", "{", "rt", ".", "BasePath", "=", "\"", "\"", "+", "rt", ".", "BasePath", "\n", "}", "\n\n", "rt", ".", "Debug", "=", "logger", ".", "DebugEnabled", "(", ")", "\n", "rt", ".", "logger", "=", "logger", ".", "StandardLogger", "{", "}", "\n\n", "if", "len", "(", "schemes", ")", ">", "0", "{", "rt", ".", "schemes", "=", "schemes", "\n", "}", "\n", "return", "&", "rt", "\n", "}" ]
// New creates a new default runtime for a swagger api runtime.Client
[ "New", "creates", "a", "new", "default", "runtime", "for", "a", "swagger", "api", "runtime", ".", "Client" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/client/runtime.go#L200-L238
10,303
go-openapi/runtime
client/runtime.go
NewWithClient
func NewWithClient(host, basePath string, schemes []string, client *http.Client) *Runtime { rt := New(host, basePath, schemes) if client != nil { rt.clientOnce.Do(func() { rt.client = client }) } return rt }
go
func NewWithClient(host, basePath string, schemes []string, client *http.Client) *Runtime { rt := New(host, basePath, schemes) if client != nil { rt.clientOnce.Do(func() { rt.client = client }) } return rt }
[ "func", "NewWithClient", "(", "host", ",", "basePath", "string", ",", "schemes", "[", "]", "string", ",", "client", "*", "http", ".", "Client", ")", "*", "Runtime", "{", "rt", ":=", "New", "(", "host", ",", "basePath", ",", "schemes", ")", "\n", "if", "client", "!=", "nil", "{", "rt", ".", "clientOnce", ".", "Do", "(", "func", "(", ")", "{", "rt", ".", "client", "=", "client", "\n", "}", ")", "\n", "}", "\n", "return", "rt", "\n", "}" ]
// NewWithClient allows you to create a new transport with a configured http.Client
[ "NewWithClient", "allows", "you", "to", "create", "a", "new", "transport", "with", "a", "configured", "http", ".", "Client" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/client/runtime.go#L241-L249
10,304
go-openapi/runtime
client/runtime.go
EnableConnectionReuse
func (r *Runtime) EnableConnectionReuse() { if r.client == nil { r.Transport = KeepAliveTransport( transportOrDefault(r.Transport, http.DefaultTransport), ) return } r.client.Transport = KeepAliveTransport( transportOrDefault(r.client.Transport, transportOrDefault(r.Transport, http.DefaultTransport), ), ) }
go
func (r *Runtime) EnableConnectionReuse() { if r.client == nil { r.Transport = KeepAliveTransport( transportOrDefault(r.Transport, http.DefaultTransport), ) return } r.client.Transport = KeepAliveTransport( transportOrDefault(r.client.Transport, transportOrDefault(r.Transport, http.DefaultTransport), ), ) }
[ "func", "(", "r", "*", "Runtime", ")", "EnableConnectionReuse", "(", ")", "{", "if", "r", ".", "client", "==", "nil", "{", "r", ".", "Transport", "=", "KeepAliveTransport", "(", "transportOrDefault", "(", "r", ".", "Transport", ",", "http", ".", "DefaultTransport", ")", ",", ")", "\n", "return", "\n", "}", "\n\n", "r", ".", "client", ".", "Transport", "=", "KeepAliveTransport", "(", "transportOrDefault", "(", "r", ".", "client", ".", "Transport", ",", "transportOrDefault", "(", "r", ".", "Transport", ",", "http", ".", "DefaultTransport", ")", ",", ")", ",", ")", "\n", "}" ]
// EnableConnectionReuse drains the remaining body from a response // so that go will reuse the TCP connections. // // This is not enabled by default because there are servers where // the response never gets closed and that would make the code hang forever. // So instead it's provided as a http client middleware that can be used to override // any request.
[ "EnableConnectionReuse", "drains", "the", "remaining", "body", "from", "a", "response", "so", "that", "go", "will", "reuse", "the", "TCP", "connections", ".", "This", "is", "not", "enabled", "by", "default", "because", "there", "are", "servers", "where", "the", "response", "never", "gets", "closed", "and", "that", "would", "make", "the", "code", "hang", "forever", ".", "So", "instead", "it", "s", "provided", "as", "a", "http", "client", "middleware", "that", "can", "be", "used", "to", "override", "any", "request", "." ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/client/runtime.go#L293-L306
10,305
go-openapi/runtime
client/runtime.go
SetDebug
func (r *Runtime) SetDebug(debug bool) { r.Debug = debug middleware.Debug = debug }
go
func (r *Runtime) SetDebug(debug bool) { r.Debug = debug middleware.Debug = debug }
[ "func", "(", "r", "*", "Runtime", ")", "SetDebug", "(", "debug", "bool", ")", "{", "r", ".", "Debug", "=", "debug", "\n", "middleware", ".", "Debug", "=", "debug", "\n", "}" ]
// SetDebug changes the debug flag. // It ensures that client and middlewares have the set debug level.
[ "SetDebug", "changes", "the", "debug", "flag", ".", "It", "ensures", "that", "client", "and", "middlewares", "have", "the", "set", "debug", "level", "." ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/client/runtime.go#L429-L432
10,306
go-openapi/runtime
client/runtime.go
SetLogger
func (r *Runtime) SetLogger(logger logger.Logger) { r.logger = logger middleware.Logger = logger }
go
func (r *Runtime) SetLogger(logger logger.Logger) { r.logger = logger middleware.Logger = logger }
[ "func", "(", "r", "*", "Runtime", ")", "SetLogger", "(", "logger", "logger", ".", "Logger", ")", "{", "r", ".", "logger", "=", "logger", "\n", "middleware", ".", "Logger", "=", "logger", "\n", "}" ]
// SetLogger changes the logger stream. // It ensures that client and middlewares use the same logger.
[ "SetLogger", "changes", "the", "logger", "stream", ".", "It", "ensures", "that", "client", "and", "middlewares", "use", "the", "same", "logger", "." ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/client/runtime.go#L436-L439
10,307
go-openapi/runtime
xml.go
XMLConsumer
func XMLConsumer() Consumer { return ConsumerFunc(func(reader io.Reader, data interface{}) error { dec := xml.NewDecoder(reader) return dec.Decode(data) }) }
go
func XMLConsumer() Consumer { return ConsumerFunc(func(reader io.Reader, data interface{}) error { dec := xml.NewDecoder(reader) return dec.Decode(data) }) }
[ "func", "XMLConsumer", "(", ")", "Consumer", "{", "return", "ConsumerFunc", "(", "func", "(", "reader", "io", ".", "Reader", ",", "data", "interface", "{", "}", ")", "error", "{", "dec", ":=", "xml", ".", "NewDecoder", "(", "reader", ")", "\n", "return", "dec", ".", "Decode", "(", "data", ")", "\n", "}", ")", "\n", "}" ]
// XMLConsumer creates a new XML consumer
[ "XMLConsumer", "creates", "a", "new", "XML", "consumer" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/xml.go#L23-L28
10,308
go-openapi/runtime
xml.go
XMLProducer
func XMLProducer() Producer { return ProducerFunc(func(writer io.Writer, data interface{}) error { enc := xml.NewEncoder(writer) return enc.Encode(data) }) }
go
func XMLProducer() Producer { return ProducerFunc(func(writer io.Writer, data interface{}) error { enc := xml.NewEncoder(writer) return enc.Encode(data) }) }
[ "func", "XMLProducer", "(", ")", "Producer", "{", "return", "ProducerFunc", "(", "func", "(", "writer", "io", ".", "Writer", ",", "data", "interface", "{", "}", ")", "error", "{", "enc", ":=", "xml", ".", "NewEncoder", "(", "writer", ")", "\n", "return", "enc", ".", "Encode", "(", "data", ")", "\n", "}", ")", "\n", "}" ]
// XMLProducer creates a new XML producer
[ "XMLProducer", "creates", "a", "new", "XML", "producer" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/xml.go#L31-L36
10,309
go-openapi/runtime
middleware/denco/server.go
Handler
func (m *Mux) Handler(method, path string, handler HandlerFunc) Handler { return Handler{ Method: method, Path: path, Func: handler, } }
go
func (m *Mux) Handler(method, path string, handler HandlerFunc) Handler { return Handler{ Method: method, Path: path, Func: handler, } }
[ "func", "(", "m", "*", "Mux", ")", "Handler", "(", "method", ",", "path", "string", ",", "handler", "HandlerFunc", ")", "Handler", "{", "return", "Handler", "{", "Method", ":", "method", ",", "Path", ":", "path", ",", "Func", ":", "handler", ",", "}", "\n", "}" ]
// Handler returns a handler for HTTP method.
[ "Handler", "returns", "a", "handler", "for", "HTTP", "method", "." ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/middleware/denco/server.go#L36-L42
10,310
go-openapi/runtime
middleware/denco/server.go
Build
func (m *Mux) Build(handlers []Handler) (http.Handler, error) { recordMap := make(map[string][]Record) for _, h := range handlers { recordMap[h.Method] = append(recordMap[h.Method], NewRecord(h.Path, h.Func)) } mux := newServeMux() for m, records := range recordMap { router := New() if err := router.Build(records); err != nil { return nil, err } mux.routers[m] = router } return mux, nil }
go
func (m *Mux) Build(handlers []Handler) (http.Handler, error) { recordMap := make(map[string][]Record) for _, h := range handlers { recordMap[h.Method] = append(recordMap[h.Method], NewRecord(h.Path, h.Func)) } mux := newServeMux() for m, records := range recordMap { router := New() if err := router.Build(records); err != nil { return nil, err } mux.routers[m] = router } return mux, nil }
[ "func", "(", "m", "*", "Mux", ")", "Build", "(", "handlers", "[", "]", "Handler", ")", "(", "http", ".", "Handler", ",", "error", ")", "{", "recordMap", ":=", "make", "(", "map", "[", "string", "]", "[", "]", "Record", ")", "\n", "for", "_", ",", "h", ":=", "range", "handlers", "{", "recordMap", "[", "h", ".", "Method", "]", "=", "append", "(", "recordMap", "[", "h", ".", "Method", "]", ",", "NewRecord", "(", "h", ".", "Path", ",", "h", ".", "Func", ")", ")", "\n", "}", "\n", "mux", ":=", "newServeMux", "(", ")", "\n", "for", "m", ",", "records", ":=", "range", "recordMap", "{", "router", ":=", "New", "(", ")", "\n", "if", "err", ":=", "router", ".", "Build", "(", "records", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "mux", ".", "routers", "[", "m", "]", "=", "router", "\n", "}", "\n", "return", "mux", ",", "nil", "\n", "}" ]
// Build builds a http.Handler.
[ "Build", "builds", "a", "http", ".", "Handler", "." ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/middleware/denco/server.go#L45-L59
10,311
go-openapi/runtime
middleware/denco/util.go
NextSeparator
func NextSeparator(path string, start int) int { for start < len(path) { if c := path[start]; c == '/' || c == TerminationCharacter { break } start++ } return start }
go
func NextSeparator(path string, start int) int { for start < len(path) { if c := path[start]; c == '/' || c == TerminationCharacter { break } start++ } return start }
[ "func", "NextSeparator", "(", "path", "string", ",", "start", "int", ")", "int", "{", "for", "start", "<", "len", "(", "path", ")", "{", "if", "c", ":=", "path", "[", "start", "]", ";", "c", "==", "'/'", "||", "c", "==", "TerminationCharacter", "{", "break", "\n", "}", "\n", "start", "++", "\n", "}", "\n", "return", "start", "\n", "}" ]
// NextSeparator returns an index of next separator in path.
[ "NextSeparator", "returns", "an", "index", "of", "next", "separator", "in", "path", "." ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/middleware/denco/util.go#L4-L12
10,312
go-openapi/runtime
middleware/request.go
newUntypedRequestBinder
func newUntypedRequestBinder(parameters map[string]spec.Parameter, spec *spec.Swagger, formats strfmt.Registry) *untypedRequestBinder { binders := make(map[string]*untypedParamBinder) for fieldName, param := range parameters { binders[fieldName] = newUntypedParamBinder(param, spec, formats) } return &untypedRequestBinder{ Parameters: parameters, paramBinders: binders, Spec: spec, Formats: formats, } }
go
func newUntypedRequestBinder(parameters map[string]spec.Parameter, spec *spec.Swagger, formats strfmt.Registry) *untypedRequestBinder { binders := make(map[string]*untypedParamBinder) for fieldName, param := range parameters { binders[fieldName] = newUntypedParamBinder(param, spec, formats) } return &untypedRequestBinder{ Parameters: parameters, paramBinders: binders, Spec: spec, Formats: formats, } }
[ "func", "newUntypedRequestBinder", "(", "parameters", "map", "[", "string", "]", "spec", ".", "Parameter", ",", "spec", "*", "spec", ".", "Swagger", ",", "formats", "strfmt", ".", "Registry", ")", "*", "untypedRequestBinder", "{", "binders", ":=", "make", "(", "map", "[", "string", "]", "*", "untypedParamBinder", ")", "\n", "for", "fieldName", ",", "param", ":=", "range", "parameters", "{", "binders", "[", "fieldName", "]", "=", "newUntypedParamBinder", "(", "param", ",", "spec", ",", "formats", ")", "\n", "}", "\n", "return", "&", "untypedRequestBinder", "{", "Parameters", ":", "parameters", ",", "paramBinders", ":", "binders", ",", "Spec", ":", "spec", ",", "Formats", ":", "formats", ",", "}", "\n", "}" ]
// NewRequestBinder creates a new binder for reading a request.
[ "NewRequestBinder", "creates", "a", "new", "binder", "for", "reading", "a", "request", "." ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/middleware/request.go#L36-L47
10,313
go-openapi/runtime
middleware/request.go
Bind
func (o *untypedRequestBinder) Bind(request *http.Request, routeParams RouteParams, consumer runtime.Consumer, data interface{}) error { val := reflect.Indirect(reflect.ValueOf(data)) isMap := val.Kind() == reflect.Map var result []error debugLog("binding %d parameters for %s %s", len(o.Parameters), request.Method, request.URL.EscapedPath()) for fieldName, param := range o.Parameters { binder := o.paramBinders[fieldName] debugLog("binding parameter %s for %s %s", fieldName, request.Method, request.URL.EscapedPath()) var target reflect.Value if !isMap { binder.Name = fieldName target = val.FieldByName(fieldName) } if isMap { tpe := binder.Type() if tpe == nil { if param.Schema.Type.Contains("array") { tpe = reflect.TypeOf([]interface{}{}) } else { tpe = reflect.TypeOf(map[string]interface{}{}) } } target = reflect.Indirect(reflect.New(tpe)) } if !target.IsValid() { result = append(result, errors.New(500, "parameter name %q is an unknown field", binder.Name)) continue } if err := binder.Bind(request, routeParams, consumer, target); err != nil { result = append(result, err) continue } if binder.validator != nil { rr := binder.validator.Validate(target.Interface()) if rr != nil && rr.HasErrors() { result = append(result, rr.AsError()) } } if isMap { val.SetMapIndex(reflect.ValueOf(param.Name), target) } } if len(result) > 0 { return errors.CompositeValidationError(result...) } return nil }
go
func (o *untypedRequestBinder) Bind(request *http.Request, routeParams RouteParams, consumer runtime.Consumer, data interface{}) error { val := reflect.Indirect(reflect.ValueOf(data)) isMap := val.Kind() == reflect.Map var result []error debugLog("binding %d parameters for %s %s", len(o.Parameters), request.Method, request.URL.EscapedPath()) for fieldName, param := range o.Parameters { binder := o.paramBinders[fieldName] debugLog("binding parameter %s for %s %s", fieldName, request.Method, request.URL.EscapedPath()) var target reflect.Value if !isMap { binder.Name = fieldName target = val.FieldByName(fieldName) } if isMap { tpe := binder.Type() if tpe == nil { if param.Schema.Type.Contains("array") { tpe = reflect.TypeOf([]interface{}{}) } else { tpe = reflect.TypeOf(map[string]interface{}{}) } } target = reflect.Indirect(reflect.New(tpe)) } if !target.IsValid() { result = append(result, errors.New(500, "parameter name %q is an unknown field", binder.Name)) continue } if err := binder.Bind(request, routeParams, consumer, target); err != nil { result = append(result, err) continue } if binder.validator != nil { rr := binder.validator.Validate(target.Interface()) if rr != nil && rr.HasErrors() { result = append(result, rr.AsError()) } } if isMap { val.SetMapIndex(reflect.ValueOf(param.Name), target) } } if len(result) > 0 { return errors.CompositeValidationError(result...) } return nil }
[ "func", "(", "o", "*", "untypedRequestBinder", ")", "Bind", "(", "request", "*", "http", ".", "Request", ",", "routeParams", "RouteParams", ",", "consumer", "runtime", ".", "Consumer", ",", "data", "interface", "{", "}", ")", "error", "{", "val", ":=", "reflect", ".", "Indirect", "(", "reflect", ".", "ValueOf", "(", "data", ")", ")", "\n", "isMap", ":=", "val", ".", "Kind", "(", ")", "==", "reflect", ".", "Map", "\n", "var", "result", "[", "]", "error", "\n", "debugLog", "(", "\"", "\"", ",", "len", "(", "o", ".", "Parameters", ")", ",", "request", ".", "Method", ",", "request", ".", "URL", ".", "EscapedPath", "(", ")", ")", "\n", "for", "fieldName", ",", "param", ":=", "range", "o", ".", "Parameters", "{", "binder", ":=", "o", ".", "paramBinders", "[", "fieldName", "]", "\n", "debugLog", "(", "\"", "\"", ",", "fieldName", ",", "request", ".", "Method", ",", "request", ".", "URL", ".", "EscapedPath", "(", ")", ")", "\n", "var", "target", "reflect", ".", "Value", "\n", "if", "!", "isMap", "{", "binder", ".", "Name", "=", "fieldName", "\n", "target", "=", "val", ".", "FieldByName", "(", "fieldName", ")", "\n", "}", "\n\n", "if", "isMap", "{", "tpe", ":=", "binder", ".", "Type", "(", ")", "\n", "if", "tpe", "==", "nil", "{", "if", "param", ".", "Schema", ".", "Type", ".", "Contains", "(", "\"", "\"", ")", "{", "tpe", "=", "reflect", ".", "TypeOf", "(", "[", "]", "interface", "{", "}", "{", "}", ")", "\n", "}", "else", "{", "tpe", "=", "reflect", ".", "TypeOf", "(", "map", "[", "string", "]", "interface", "{", "}", "{", "}", ")", "\n", "}", "\n", "}", "\n", "target", "=", "reflect", ".", "Indirect", "(", "reflect", ".", "New", "(", "tpe", ")", ")", "\n\n", "}", "\n\n", "if", "!", "target", ".", "IsValid", "(", ")", "{", "result", "=", "append", "(", "result", ",", "errors", ".", "New", "(", "500", ",", "\"", "\"", ",", "binder", ".", "Name", ")", ")", "\n", "continue", "\n", "}", "\n\n", "if", "err", ":=", "binder", ".", "Bind", "(", "request", ",", "routeParams", ",", "consumer", ",", "target", ")", ";", "err", "!=", "nil", "{", "result", "=", "append", "(", "result", ",", "err", ")", "\n", "continue", "\n", "}", "\n\n", "if", "binder", ".", "validator", "!=", "nil", "{", "rr", ":=", "binder", ".", "validator", ".", "Validate", "(", "target", ".", "Interface", "(", ")", ")", "\n", "if", "rr", "!=", "nil", "&&", "rr", ".", "HasErrors", "(", ")", "{", "result", "=", "append", "(", "result", ",", "rr", ".", "AsError", "(", ")", ")", "\n", "}", "\n", "}", "\n\n", "if", "isMap", "{", "val", ".", "SetMapIndex", "(", "reflect", ".", "ValueOf", "(", "param", ".", "Name", ")", ",", "target", ")", "\n", "}", "\n", "}", "\n\n", "if", "len", "(", "result", ")", ">", "0", "{", "return", "errors", ".", "CompositeValidationError", "(", "result", "...", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Bind perform the databinding and validation
[ "Bind", "perform", "the", "databinding", "and", "validation" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/middleware/request.go#L50-L104
10,314
go-openapi/runtime
middleware/not_implemented.go
NotImplemented
func NotImplemented(message string) Responder { return &errorResp{http.StatusNotImplemented, message, make(http.Header)} }
go
func NotImplemented(message string) Responder { return &errorResp{http.StatusNotImplemented, message, make(http.Header)} }
[ "func", "NotImplemented", "(", "message", "string", ")", "Responder", "{", "return", "&", "errorResp", "{", "http", ".", "StatusNotImplemented", ",", "message", ",", "make", "(", "http", ".", "Header", ")", "}", "\n", "}" ]
// NotImplemented the error response when the response is not implemented
[ "NotImplemented", "the", "error", "response", "when", "the", "response", "is", "not", "implemented" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/middleware/not_implemented.go#L46-L48
10,315
go-openapi/runtime
client_request.go
WriteToRequest
func (fn ClientRequestWriterFunc) WriteToRequest(req ClientRequest, reg strfmt.Registry) error { return fn(req, reg) }
go
func (fn ClientRequestWriterFunc) WriteToRequest(req ClientRequest, reg strfmt.Registry) error { return fn(req, reg) }
[ "func", "(", "fn", "ClientRequestWriterFunc", ")", "WriteToRequest", "(", "req", "ClientRequest", ",", "reg", "strfmt", ".", "Registry", ")", "error", "{", "return", "fn", "(", "req", ",", "reg", ")", "\n", "}" ]
// WriteToRequest adds data to the request
[ "WriteToRequest", "adds", "data", "to", "the", "request" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/client_request.go#L31-L33
10,316
go-openapi/runtime
client_request.go
NamedReader
func NamedReader(name string, rdr io.Reader) NamedReadCloser { rc, ok := rdr.(io.ReadCloser) if !ok { rc = ioutil.NopCloser(rdr) } return &namedReadCloser{ name: name, cr: rc, } }
go
func NamedReader(name string, rdr io.Reader) NamedReadCloser { rc, ok := rdr.(io.ReadCloser) if !ok { rc = ioutil.NopCloser(rdr) } return &namedReadCloser{ name: name, cr: rc, } }
[ "func", "NamedReader", "(", "name", "string", ",", "rdr", "io", ".", "Reader", ")", "NamedReadCloser", "{", "rc", ",", "ok", ":=", "rdr", ".", "(", "io", ".", "ReadCloser", ")", "\n", "if", "!", "ok", "{", "rc", "=", "ioutil", ".", "NopCloser", "(", "rdr", ")", "\n", "}", "\n", "return", "&", "namedReadCloser", "{", "name", ":", "name", ",", "cr", ":", "rc", ",", "}", "\n", "}" ]
// NamedReader creates a NamedReadCloser for use as file upload
[ "NamedReader", "creates", "a", "NamedReadCloser", "for", "use", "as", "file", "upload" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/client_request.go#L79-L88
10,317
go-openapi/runtime
middleware/context.go
WriteResponse
func (fn ResponderFunc) WriteResponse(rw http.ResponseWriter, pr runtime.Producer) { fn(rw, pr) }
go
func (fn ResponderFunc) WriteResponse(rw http.ResponseWriter, pr runtime.Producer) { fn(rw, pr) }
[ "func", "(", "fn", "ResponderFunc", ")", "WriteResponse", "(", "rw", "http", ".", "ResponseWriter", ",", "pr", "runtime", ".", "Producer", ")", "{", "fn", "(", "rw", ",", "pr", ")", "\n", "}" ]
// WriteResponse writes to the response
[ "WriteResponse", "writes", "to", "the", "response" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/middleware/context.go#L68-L70
10,318
go-openapi/runtime
middleware/context.go
NewRoutableContext
func NewRoutableContext(spec *loads.Document, routableAPI RoutableAPI, routes Router) *Context { var an *analysis.Spec if spec != nil { an = analysis.New(spec.Spec()) } ctx := &Context{spec: spec, api: routableAPI, analyzer: an, router: routes} return ctx }
go
func NewRoutableContext(spec *loads.Document, routableAPI RoutableAPI, routes Router) *Context { var an *analysis.Spec if spec != nil { an = analysis.New(spec.Spec()) } ctx := &Context{spec: spec, api: routableAPI, analyzer: an, router: routes} return ctx }
[ "func", "NewRoutableContext", "(", "spec", "*", "loads", ".", "Document", ",", "routableAPI", "RoutableAPI", ",", "routes", "Router", ")", "*", "Context", "{", "var", "an", "*", "analysis", ".", "Spec", "\n", "if", "spec", "!=", "nil", "{", "an", "=", "analysis", ".", "New", "(", "spec", ".", "Spec", "(", ")", ")", "\n", "}", "\n", "ctx", ":=", "&", "Context", "{", "spec", ":", "spec", ",", "api", ":", "routableAPI", ",", "analyzer", ":", "an", ",", "router", ":", "routes", "}", "\n", "return", "ctx", "\n", "}" ]
// NewRoutableContext creates a new context for a routable API
[ "NewRoutableContext", "creates", "a", "new", "context", "for", "a", "routable", "API" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/middleware/context.go#L193-L200
10,319
go-openapi/runtime
middleware/context.go
NewContext
func NewContext(spec *loads.Document, api *untyped.API, routes Router) *Context { var an *analysis.Spec if spec != nil { an = analysis.New(spec.Spec()) } ctx := &Context{spec: spec, analyzer: an} ctx.api = newRoutableUntypedAPI(spec, api, ctx) ctx.router = routes return ctx }
go
func NewContext(spec *loads.Document, api *untyped.API, routes Router) *Context { var an *analysis.Spec if spec != nil { an = analysis.New(spec.Spec()) } ctx := &Context{spec: spec, analyzer: an} ctx.api = newRoutableUntypedAPI(spec, api, ctx) ctx.router = routes return ctx }
[ "func", "NewContext", "(", "spec", "*", "loads", ".", "Document", ",", "api", "*", "untyped", ".", "API", ",", "routes", "Router", ")", "*", "Context", "{", "var", "an", "*", "analysis", ".", "Spec", "\n", "if", "spec", "!=", "nil", "{", "an", "=", "analysis", ".", "New", "(", "spec", ".", "Spec", "(", ")", ")", "\n", "}", "\n", "ctx", ":=", "&", "Context", "{", "spec", ":", "spec", ",", "analyzer", ":", "an", "}", "\n", "ctx", ".", "api", "=", "newRoutableUntypedAPI", "(", "spec", ",", "api", ",", "ctx", ")", "\n", "ctx", ".", "router", "=", "routes", "\n", "return", "ctx", "\n", "}" ]
// NewContext creates a new context wrapper
[ "NewContext", "creates", "a", "new", "context", "wrapper" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/middleware/context.go#L203-L212
10,320
go-openapi/runtime
middleware/context.go
Serve
func Serve(spec *loads.Document, api *untyped.API) http.Handler { return ServeWithBuilder(spec, api, PassthroughBuilder) }
go
func Serve(spec *loads.Document, api *untyped.API) http.Handler { return ServeWithBuilder(spec, api, PassthroughBuilder) }
[ "func", "Serve", "(", "spec", "*", "loads", ".", "Document", ",", "api", "*", "untyped", ".", "API", ")", "http", ".", "Handler", "{", "return", "ServeWithBuilder", "(", "spec", ",", "api", ",", "PassthroughBuilder", ")", "\n", "}" ]
// Serve serves the specified spec with the specified api registrations as a http.Handler
[ "Serve", "serves", "the", "specified", "spec", "with", "the", "specified", "api", "registrations", "as", "a", "http", ".", "Handler" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/middleware/context.go#L215-L217
10,321
go-openapi/runtime
middleware/context.go
ServeWithBuilder
func ServeWithBuilder(spec *loads.Document, api *untyped.API, builder Builder) http.Handler { context := NewContext(spec, api, nil) return context.APIHandler(builder) }
go
func ServeWithBuilder(spec *loads.Document, api *untyped.API, builder Builder) http.Handler { context := NewContext(spec, api, nil) return context.APIHandler(builder) }
[ "func", "ServeWithBuilder", "(", "spec", "*", "loads", ".", "Document", ",", "api", "*", "untyped", ".", "API", ",", "builder", "Builder", ")", "http", ".", "Handler", "{", "context", ":=", "NewContext", "(", "spec", ",", "api", ",", "nil", ")", "\n", "return", "context", ".", "APIHandler", "(", "builder", ")", "\n", "}" ]
// ServeWithBuilder serves the specified spec with the specified api registrations as a http.Handler that is decorated // by the Builder
[ "ServeWithBuilder", "serves", "the", "specified", "spec", "with", "the", "specified", "api", "registrations", "as", "a", "http", ".", "Handler", "that", "is", "decorated", "by", "the", "Builder" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/middleware/context.go#L221-L224
10,322
go-openapi/runtime
middleware/context.go
MatchedRouteFrom
func MatchedRouteFrom(req *http.Request) *MatchedRoute { mr := req.Context().Value(ctxMatchedRoute) if mr == nil { return nil } if res, ok := mr.(*MatchedRoute); ok { return res } return nil }
go
func MatchedRouteFrom(req *http.Request) *MatchedRoute { mr := req.Context().Value(ctxMatchedRoute) if mr == nil { return nil } if res, ok := mr.(*MatchedRoute); ok { return res } return nil }
[ "func", "MatchedRouteFrom", "(", "req", "*", "http", ".", "Request", ")", "*", "MatchedRoute", "{", "mr", ":=", "req", ".", "Context", "(", ")", ".", "Value", "(", "ctxMatchedRoute", ")", "\n", "if", "mr", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "if", "res", ",", "ok", ":=", "mr", ".", "(", "*", "MatchedRoute", ")", ";", "ok", "{", "return", "res", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// MatchedRouteFrom request context value.
[ "MatchedRouteFrom", "request", "context", "value", "." ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/middleware/context.go#L239-L248
10,323
go-openapi/runtime
middleware/context.go
SecurityScopesFrom
func SecurityScopesFrom(req *http.Request) []string { rs := req.Context().Value(ctxSecurityScopes) if res, ok := rs.([]string); ok { return res } return nil }
go
func SecurityScopesFrom(req *http.Request) []string { rs := req.Context().Value(ctxSecurityScopes) if res, ok := rs.([]string); ok { return res } return nil }
[ "func", "SecurityScopesFrom", "(", "req", "*", "http", ".", "Request", ")", "[", "]", "string", "{", "rs", ":=", "req", ".", "Context", "(", ")", ".", "Value", "(", "ctxSecurityScopes", ")", "\n", "if", "res", ",", "ok", ":=", "rs", ".", "(", "[", "]", "string", ")", ";", "ok", "{", "return", "res", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// SecurityScopesFrom request context value.
[ "SecurityScopesFrom", "request", "context", "value", "." ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/middleware/context.go#L256-L262
10,324
go-openapi/runtime
middleware/context.go
BindValidRequest
func (c *Context) BindValidRequest(request *http.Request, route *MatchedRoute, binder RequestBinder) error { var res []error requestContentType := "*/*" // check and validate content type, select consumer if runtime.HasBody(request) { ct, _, err := runtime.ContentType(request.Header) if err != nil { res = append(res, err) } else { if err := validateContentType(route.Consumes, ct); err != nil { res = append(res, err) } if len(res) == 0 { cons, ok := route.Consumers[ct] if !ok { res = append(res, errors.New(500, "no consumer registered for %s", ct)) } else { route.Consumer = cons requestContentType = ct } } } } // check and validate the response format if len(res) == 0 && runtime.HasBody(request) { if str := NegotiateContentType(request, route.Produces, requestContentType); str == "" { res = append(res, errors.InvalidResponseFormat(request.Header.Get(runtime.HeaderAccept), route.Produces)) } } // now bind the request with the provided binder // it's assumed the binder will also validate the request and return an error if the // request is invalid if binder != nil && len(res) == 0 { if err := binder.BindRequest(request, route); err != nil { return err } } if len(res) > 0 { return errors.CompositeValidationError(res...) } return nil }
go
func (c *Context) BindValidRequest(request *http.Request, route *MatchedRoute, binder RequestBinder) error { var res []error requestContentType := "*/*" // check and validate content type, select consumer if runtime.HasBody(request) { ct, _, err := runtime.ContentType(request.Header) if err != nil { res = append(res, err) } else { if err := validateContentType(route.Consumes, ct); err != nil { res = append(res, err) } if len(res) == 0 { cons, ok := route.Consumers[ct] if !ok { res = append(res, errors.New(500, "no consumer registered for %s", ct)) } else { route.Consumer = cons requestContentType = ct } } } } // check and validate the response format if len(res) == 0 && runtime.HasBody(request) { if str := NegotiateContentType(request, route.Produces, requestContentType); str == "" { res = append(res, errors.InvalidResponseFormat(request.Header.Get(runtime.HeaderAccept), route.Produces)) } } // now bind the request with the provided binder // it's assumed the binder will also validate the request and return an error if the // request is invalid if binder != nil && len(res) == 0 { if err := binder.BindRequest(request, route); err != nil { return err } } if len(res) > 0 { return errors.CompositeValidationError(res...) } return nil }
[ "func", "(", "c", "*", "Context", ")", "BindValidRequest", "(", "request", "*", "http", ".", "Request", ",", "route", "*", "MatchedRoute", ",", "binder", "RequestBinder", ")", "error", "{", "var", "res", "[", "]", "error", "\n\n", "requestContentType", ":=", "\"", "\"", "\n", "// check and validate content type, select consumer", "if", "runtime", ".", "HasBody", "(", "request", ")", "{", "ct", ",", "_", ",", "err", ":=", "runtime", ".", "ContentType", "(", "request", ".", "Header", ")", "\n", "if", "err", "!=", "nil", "{", "res", "=", "append", "(", "res", ",", "err", ")", "\n", "}", "else", "{", "if", "err", ":=", "validateContentType", "(", "route", ".", "Consumes", ",", "ct", ")", ";", "err", "!=", "nil", "{", "res", "=", "append", "(", "res", ",", "err", ")", "\n", "}", "\n", "if", "len", "(", "res", ")", "==", "0", "{", "cons", ",", "ok", ":=", "route", ".", "Consumers", "[", "ct", "]", "\n", "if", "!", "ok", "{", "res", "=", "append", "(", "res", ",", "errors", ".", "New", "(", "500", ",", "\"", "\"", ",", "ct", ")", ")", "\n", "}", "else", "{", "route", ".", "Consumer", "=", "cons", "\n", "requestContentType", "=", "ct", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n\n", "// check and validate the response format", "if", "len", "(", "res", ")", "==", "0", "&&", "runtime", ".", "HasBody", "(", "request", ")", "{", "if", "str", ":=", "NegotiateContentType", "(", "request", ",", "route", ".", "Produces", ",", "requestContentType", ")", ";", "str", "==", "\"", "\"", "{", "res", "=", "append", "(", "res", ",", "errors", ".", "InvalidResponseFormat", "(", "request", ".", "Header", ".", "Get", "(", "runtime", ".", "HeaderAccept", ")", ",", "route", ".", "Produces", ")", ")", "\n", "}", "\n", "}", "\n\n", "// now bind the request with the provided binder", "// it's assumed the binder will also validate the request and return an error if the", "// request is invalid", "if", "binder", "!=", "nil", "&&", "len", "(", "res", ")", "==", "0", "{", "if", "err", ":=", "binder", ".", "BindRequest", "(", "request", ",", "route", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "if", "len", "(", "res", ")", ">", "0", "{", "return", "errors", ".", "CompositeValidationError", "(", "res", "...", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// BindValidRequest binds a params object to a request but only when the request is valid // if the request is not valid an error will be returned
[ "BindValidRequest", "binds", "a", "params", "object", "to", "a", "request", "but", "only", "when", "the", "request", "is", "valid", "if", "the", "request", "is", "not", "valid", "an", "error", "will", "be", "returned" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/middleware/context.go#L281-L326
10,325
go-openapi/runtime
middleware/context.go
ContentType
func (c *Context) ContentType(request *http.Request) (string, string, *http.Request, error) { var rCtx = request.Context() if v, ok := rCtx.Value(ctxContentType).(*contentTypeValue); ok { return v.MediaType, v.Charset, request, nil } mt, cs, err := runtime.ContentType(request.Header) if err != nil { return "", "", nil, err } rCtx = stdContext.WithValue(rCtx, ctxContentType, &contentTypeValue{mt, cs}) return mt, cs, request.WithContext(rCtx), nil }
go
func (c *Context) ContentType(request *http.Request) (string, string, *http.Request, error) { var rCtx = request.Context() if v, ok := rCtx.Value(ctxContentType).(*contentTypeValue); ok { return v.MediaType, v.Charset, request, nil } mt, cs, err := runtime.ContentType(request.Header) if err != nil { return "", "", nil, err } rCtx = stdContext.WithValue(rCtx, ctxContentType, &contentTypeValue{mt, cs}) return mt, cs, request.WithContext(rCtx), nil }
[ "func", "(", "c", "*", "Context", ")", "ContentType", "(", "request", "*", "http", ".", "Request", ")", "(", "string", ",", "string", ",", "*", "http", ".", "Request", ",", "error", ")", "{", "var", "rCtx", "=", "request", ".", "Context", "(", ")", "\n\n", "if", "v", ",", "ok", ":=", "rCtx", ".", "Value", "(", "ctxContentType", ")", ".", "(", "*", "contentTypeValue", ")", ";", "ok", "{", "return", "v", ".", "MediaType", ",", "v", ".", "Charset", ",", "request", ",", "nil", "\n", "}", "\n\n", "mt", ",", "cs", ",", "err", ":=", "runtime", ".", "ContentType", "(", "request", ".", "Header", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "\"", "\"", ",", "nil", ",", "err", "\n", "}", "\n", "rCtx", "=", "stdContext", ".", "WithValue", "(", "rCtx", ",", "ctxContentType", ",", "&", "contentTypeValue", "{", "mt", ",", "cs", "}", ")", "\n", "return", "mt", ",", "cs", ",", "request", ".", "WithContext", "(", "rCtx", ")", ",", "nil", "\n", "}" ]
// ContentType gets the parsed value of a content type // Returns the media type, its charset and a shallow copy of the request // when its context doesn't contain the content type value, otherwise it returns // the same request // Returns the error that runtime.ContentType may retunrs.
[ "ContentType", "gets", "the", "parsed", "value", "of", "a", "content", "type", "Returns", "the", "media", "type", "its", "charset", "and", "a", "shallow", "copy", "of", "the", "request", "when", "its", "context", "doesn", "t", "contain", "the", "content", "type", "value", "otherwise", "it", "returns", "the", "same", "request", "Returns", "the", "error", "that", "runtime", ".", "ContentType", "may", "retunrs", "." ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/middleware/context.go#L333-L346
10,326
go-openapi/runtime
middleware/context.go
LookupRoute
func (c *Context) LookupRoute(request *http.Request) (*MatchedRoute, bool) { if route, ok := c.router.Lookup(request.Method, request.URL.EscapedPath()); ok { return route, ok } return nil, false }
go
func (c *Context) LookupRoute(request *http.Request) (*MatchedRoute, bool) { if route, ok := c.router.Lookup(request.Method, request.URL.EscapedPath()); ok { return route, ok } return nil, false }
[ "func", "(", "c", "*", "Context", ")", "LookupRoute", "(", "request", "*", "http", ".", "Request", ")", "(", "*", "MatchedRoute", ",", "bool", ")", "{", "if", "route", ",", "ok", ":=", "c", ".", "router", ".", "Lookup", "(", "request", ".", "Method", ",", "request", ".", "URL", ".", "EscapedPath", "(", ")", ")", ";", "ok", "{", "return", "route", ",", "ok", "\n", "}", "\n", "return", "nil", ",", "false", "\n", "}" ]
// LookupRoute looks a route up and returns true when it is found
[ "LookupRoute", "looks", "a", "route", "up", "and", "returns", "true", "when", "it", "is", "found" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/middleware/context.go#L349-L354
10,327
go-openapi/runtime
middleware/context.go
RouteInfo
func (c *Context) RouteInfo(request *http.Request) (*MatchedRoute, *http.Request, bool) { var rCtx = request.Context() if v, ok := rCtx.Value(ctxMatchedRoute).(*MatchedRoute); ok { return v, request, ok } if route, ok := c.LookupRoute(request); ok { rCtx = stdContext.WithValue(rCtx, ctxMatchedRoute, route) return route, request.WithContext(rCtx), ok } return nil, nil, false }
go
func (c *Context) RouteInfo(request *http.Request) (*MatchedRoute, *http.Request, bool) { var rCtx = request.Context() if v, ok := rCtx.Value(ctxMatchedRoute).(*MatchedRoute); ok { return v, request, ok } if route, ok := c.LookupRoute(request); ok { rCtx = stdContext.WithValue(rCtx, ctxMatchedRoute, route) return route, request.WithContext(rCtx), ok } return nil, nil, false }
[ "func", "(", "c", "*", "Context", ")", "RouteInfo", "(", "request", "*", "http", ".", "Request", ")", "(", "*", "MatchedRoute", ",", "*", "http", ".", "Request", ",", "bool", ")", "{", "var", "rCtx", "=", "request", ".", "Context", "(", ")", "\n\n", "if", "v", ",", "ok", ":=", "rCtx", ".", "Value", "(", "ctxMatchedRoute", ")", ".", "(", "*", "MatchedRoute", ")", ";", "ok", "{", "return", "v", ",", "request", ",", "ok", "\n", "}", "\n\n", "if", "route", ",", "ok", ":=", "c", ".", "LookupRoute", "(", "request", ")", ";", "ok", "{", "rCtx", "=", "stdContext", ".", "WithValue", "(", "rCtx", ",", "ctxMatchedRoute", ",", "route", ")", "\n", "return", "route", ",", "request", ".", "WithContext", "(", "rCtx", ")", ",", "ok", "\n", "}", "\n\n", "return", "nil", ",", "nil", ",", "false", "\n", "}" ]
// RouteInfo tries to match a route for this request // Returns the matched route, a shallow copy of the request if its context // contains the matched router, otherwise the same request, and a bool to // indicate if it the request matches one of the routes, if it doesn't // then it returns false and nil for the other two return values
[ "RouteInfo", "tries", "to", "match", "a", "route", "for", "this", "request", "Returns", "the", "matched", "route", "a", "shallow", "copy", "of", "the", "request", "if", "its", "context", "contains", "the", "matched", "router", "otherwise", "the", "same", "request", "and", "a", "bool", "to", "indicate", "if", "it", "the", "request", "matches", "one", "of", "the", "routes", "if", "it", "doesn", "t", "then", "it", "returns", "false", "and", "nil", "for", "the", "other", "two", "return", "values" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/middleware/context.go#L361-L374
10,328
go-openapi/runtime
middleware/context.go
ResponseFormat
func (c *Context) ResponseFormat(r *http.Request, offers []string) (string, *http.Request) { var rCtx = r.Context() if v, ok := rCtx.Value(ctxResponseFormat).(string); ok { debugLog("[%s %s] found response format %q in context", r.Method, r.URL.Path, v) return v, r } format := NegotiateContentType(r, offers, "") if format != "" { debugLog("[%s %s] set response format %q in context", r.Method, r.URL.Path, format) r = r.WithContext(stdContext.WithValue(rCtx, ctxResponseFormat, format)) } debugLog("[%s %s] negotiated response format %q", r.Method, r.URL.Path, format) return format, r }
go
func (c *Context) ResponseFormat(r *http.Request, offers []string) (string, *http.Request) { var rCtx = r.Context() if v, ok := rCtx.Value(ctxResponseFormat).(string); ok { debugLog("[%s %s] found response format %q in context", r.Method, r.URL.Path, v) return v, r } format := NegotiateContentType(r, offers, "") if format != "" { debugLog("[%s %s] set response format %q in context", r.Method, r.URL.Path, format) r = r.WithContext(stdContext.WithValue(rCtx, ctxResponseFormat, format)) } debugLog("[%s %s] negotiated response format %q", r.Method, r.URL.Path, format) return format, r }
[ "func", "(", "c", "*", "Context", ")", "ResponseFormat", "(", "r", "*", "http", ".", "Request", ",", "offers", "[", "]", "string", ")", "(", "string", ",", "*", "http", ".", "Request", ")", "{", "var", "rCtx", "=", "r", ".", "Context", "(", ")", "\n\n", "if", "v", ",", "ok", ":=", "rCtx", ".", "Value", "(", "ctxResponseFormat", ")", ".", "(", "string", ")", ";", "ok", "{", "debugLog", "(", "\"", "\"", ",", "r", ".", "Method", ",", "r", ".", "URL", ".", "Path", ",", "v", ")", "\n", "return", "v", ",", "r", "\n", "}", "\n\n", "format", ":=", "NegotiateContentType", "(", "r", ",", "offers", ",", "\"", "\"", ")", "\n", "if", "format", "!=", "\"", "\"", "{", "debugLog", "(", "\"", "\"", ",", "r", ".", "Method", ",", "r", ".", "URL", ".", "Path", ",", "format", ")", "\n", "r", "=", "r", ".", "WithContext", "(", "stdContext", ".", "WithValue", "(", "rCtx", ",", "ctxResponseFormat", ",", "format", ")", ")", "\n", "}", "\n", "debugLog", "(", "\"", "\"", ",", "r", ".", "Method", ",", "r", ".", "URL", ".", "Path", ",", "format", ")", "\n", "return", "format", ",", "r", "\n", "}" ]
// ResponseFormat negotiates the response content type // Returns the response format and a shallow copy of the request if its context // doesn't contain the response format, otherwise the same request
[ "ResponseFormat", "negotiates", "the", "response", "content", "type", "Returns", "the", "response", "format", "and", "a", "shallow", "copy", "of", "the", "request", "if", "its", "context", "doesn", "t", "contain", "the", "response", "format", "otherwise", "the", "same", "request" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/middleware/context.go#L379-L394
10,329
go-openapi/runtime
middleware/context.go
AllowedMethods
func (c *Context) AllowedMethods(request *http.Request) []string { return c.router.OtherMethods(request.Method, request.URL.EscapedPath()) }
go
func (c *Context) AllowedMethods(request *http.Request) []string { return c.router.OtherMethods(request.Method, request.URL.EscapedPath()) }
[ "func", "(", "c", "*", "Context", ")", "AllowedMethods", "(", "request", "*", "http", ".", "Request", ")", "[", "]", "string", "{", "return", "c", ".", "router", ".", "OtherMethods", "(", "request", ".", "Method", ",", "request", ".", "URL", ".", "EscapedPath", "(", ")", ")", "\n", "}" ]
// AllowedMethods gets the allowed methods for the path of this request
[ "AllowedMethods", "gets", "the", "allowed", "methods", "for", "the", "path", "of", "this", "request" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/middleware/context.go#L397-L399
10,330
go-openapi/runtime
middleware/context.go
ResetAuth
func (c *Context) ResetAuth(request *http.Request) *http.Request { rctx := request.Context() rctx = stdContext.WithValue(rctx, ctxSecurityPrincipal, nil) rctx = stdContext.WithValue(rctx, ctxSecurityScopes, nil) return request.WithContext(rctx) }
go
func (c *Context) ResetAuth(request *http.Request) *http.Request { rctx := request.Context() rctx = stdContext.WithValue(rctx, ctxSecurityPrincipal, nil) rctx = stdContext.WithValue(rctx, ctxSecurityScopes, nil) return request.WithContext(rctx) }
[ "func", "(", "c", "*", "Context", ")", "ResetAuth", "(", "request", "*", "http", ".", "Request", ")", "*", "http", ".", "Request", "{", "rctx", ":=", "request", ".", "Context", "(", ")", "\n", "rctx", "=", "stdContext", ".", "WithValue", "(", "rctx", ",", "ctxSecurityPrincipal", ",", "nil", ")", "\n", "rctx", "=", "stdContext", ".", "WithValue", "(", "rctx", ",", "ctxSecurityScopes", ",", "nil", ")", "\n", "return", "request", ".", "WithContext", "(", "rctx", ")", "\n", "}" ]
// ResetAuth removes the current principal from the request context
[ "ResetAuth", "removes", "the", "current", "principal", "from", "the", "request", "context" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/middleware/context.go#L402-L407
10,331
go-openapi/runtime
middleware/context.go
BindAndValidate
func (c *Context) BindAndValidate(request *http.Request, matched *MatchedRoute) (interface{}, *http.Request, error) { var rCtx = request.Context() if v, ok := rCtx.Value(ctxBoundParams).(*validation); ok { debugLog("got cached validation (valid: %t)", len(v.result) == 0) if len(v.result) > 0 { return v.bound, request, errors.CompositeValidationError(v.result...) } return v.bound, request, nil } result := validateRequest(c, request, matched) rCtx = stdContext.WithValue(rCtx, ctxBoundParams, result) request = request.WithContext(rCtx) if len(result.result) > 0 { return result.bound, request, errors.CompositeValidationError(result.result...) } debugLog("no validation errors found") return result.bound, request, nil }
go
func (c *Context) BindAndValidate(request *http.Request, matched *MatchedRoute) (interface{}, *http.Request, error) { var rCtx = request.Context() if v, ok := rCtx.Value(ctxBoundParams).(*validation); ok { debugLog("got cached validation (valid: %t)", len(v.result) == 0) if len(v.result) > 0 { return v.bound, request, errors.CompositeValidationError(v.result...) } return v.bound, request, nil } result := validateRequest(c, request, matched) rCtx = stdContext.WithValue(rCtx, ctxBoundParams, result) request = request.WithContext(rCtx) if len(result.result) > 0 { return result.bound, request, errors.CompositeValidationError(result.result...) } debugLog("no validation errors found") return result.bound, request, nil }
[ "func", "(", "c", "*", "Context", ")", "BindAndValidate", "(", "request", "*", "http", ".", "Request", ",", "matched", "*", "MatchedRoute", ")", "(", "interface", "{", "}", ",", "*", "http", ".", "Request", ",", "error", ")", "{", "var", "rCtx", "=", "request", ".", "Context", "(", ")", "\n\n", "if", "v", ",", "ok", ":=", "rCtx", ".", "Value", "(", "ctxBoundParams", ")", ".", "(", "*", "validation", ")", ";", "ok", "{", "debugLog", "(", "\"", "\"", ",", "len", "(", "v", ".", "result", ")", "==", "0", ")", "\n", "if", "len", "(", "v", ".", "result", ")", ">", "0", "{", "return", "v", ".", "bound", ",", "request", ",", "errors", ".", "CompositeValidationError", "(", "v", ".", "result", "...", ")", "\n", "}", "\n", "return", "v", ".", "bound", ",", "request", ",", "nil", "\n", "}", "\n", "result", ":=", "validateRequest", "(", "c", ",", "request", ",", "matched", ")", "\n", "rCtx", "=", "stdContext", ".", "WithValue", "(", "rCtx", ",", "ctxBoundParams", ",", "result", ")", "\n", "request", "=", "request", ".", "WithContext", "(", "rCtx", ")", "\n", "if", "len", "(", "result", ".", "result", ")", ">", "0", "{", "return", "result", ".", "bound", ",", "request", ",", "errors", ".", "CompositeValidationError", "(", "result", ".", "result", "...", ")", "\n", "}", "\n", "debugLog", "(", "\"", "\"", ")", "\n", "return", "result", ".", "bound", ",", "request", ",", "nil", "\n", "}" ]
// BindAndValidate binds and validates the request // Returns the validation map and a shallow copy of the request when its context // doesn't contain the validation, otherwise it returns the same request or an // CompositeValidationError error
[ "BindAndValidate", "binds", "and", "validates", "the", "request", "Returns", "the", "validation", "map", "and", "a", "shallow", "copy", "of", "the", "request", "when", "its", "context", "doesn", "t", "contain", "the", "validation", "otherwise", "it", "returns", "the", "same", "request", "or", "an", "CompositeValidationError", "error" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/middleware/context.go#L445-L463
10,332
go-openapi/runtime
middleware/context.go
NotFound
func (c *Context) NotFound(rw http.ResponseWriter, r *http.Request) { c.Respond(rw, r, []string{c.api.DefaultProduces()}, nil, errors.NotFound("not found")) }
go
func (c *Context) NotFound(rw http.ResponseWriter, r *http.Request) { c.Respond(rw, r, []string{c.api.DefaultProduces()}, nil, errors.NotFound("not found")) }
[ "func", "(", "c", "*", "Context", ")", "NotFound", "(", "rw", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "c", ".", "Respond", "(", "rw", ",", "r", ",", "[", "]", "string", "{", "c", ".", "api", ".", "DefaultProduces", "(", ")", "}", ",", "nil", ",", "errors", ".", "NotFound", "(", "\"", "\"", ")", ")", "\n", "}" ]
// NotFound the default not found responder for when no route has been matched yet
[ "NotFound", "the", "default", "not", "found", "responder", "for", "when", "no", "route", "has", "been", "matched", "yet" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/middleware/context.go#L466-L468
10,333
go-openapi/runtime
middleware/context.go
APIHandler
func (c *Context) APIHandler(builder Builder) http.Handler { b := builder if b == nil { b = PassthroughBuilder } var title string sp := c.spec.Spec() if sp != nil && sp.Info != nil && sp.Info.Title != "" { title = sp.Info.Title } redocOpts := RedocOpts{ BasePath: c.BasePath(), Title: title, } return Spec("", c.spec.Raw(), Redoc(redocOpts, c.RoutesHandler(b))) }
go
func (c *Context) APIHandler(builder Builder) http.Handler { b := builder if b == nil { b = PassthroughBuilder } var title string sp := c.spec.Spec() if sp != nil && sp.Info != nil && sp.Info.Title != "" { title = sp.Info.Title } redocOpts := RedocOpts{ BasePath: c.BasePath(), Title: title, } return Spec("", c.spec.Raw(), Redoc(redocOpts, c.RoutesHandler(b))) }
[ "func", "(", "c", "*", "Context", ")", "APIHandler", "(", "builder", "Builder", ")", "http", ".", "Handler", "{", "b", ":=", "builder", "\n", "if", "b", "==", "nil", "{", "b", "=", "PassthroughBuilder", "\n", "}", "\n\n", "var", "title", "string", "\n", "sp", ":=", "c", ".", "spec", ".", "Spec", "(", ")", "\n", "if", "sp", "!=", "nil", "&&", "sp", ".", "Info", "!=", "nil", "&&", "sp", ".", "Info", ".", "Title", "!=", "\"", "\"", "{", "title", "=", "sp", ".", "Info", ".", "Title", "\n", "}", "\n\n", "redocOpts", ":=", "RedocOpts", "{", "BasePath", ":", "c", ".", "BasePath", "(", ")", ",", "Title", ":", "title", ",", "}", "\n\n", "return", "Spec", "(", "\"", "\"", ",", "c", ".", "spec", ".", "Raw", "(", ")", ",", "Redoc", "(", "redocOpts", ",", "c", ".", "RoutesHandler", "(", "b", ")", ")", ")", "\n", "}" ]
// APIHandler returns a handler to serve the API, this includes a swagger spec, router and the contract defined in the swagger spec
[ "APIHandler", "returns", "a", "handler", "to", "serve", "the", "API", "this", "includes", "a", "swagger", "spec", "router", "and", "the", "contract", "defined", "in", "the", "swagger", "spec" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/middleware/context.go#L563-L581
10,334
go-openapi/runtime
middleware/context.go
RoutesHandler
func (c *Context) RoutesHandler(builder Builder) http.Handler { b := builder if b == nil { b = PassthroughBuilder } return NewRouter(c, b(NewOperationExecutor(c))) }
go
func (c *Context) RoutesHandler(builder Builder) http.Handler { b := builder if b == nil { b = PassthroughBuilder } return NewRouter(c, b(NewOperationExecutor(c))) }
[ "func", "(", "c", "*", "Context", ")", "RoutesHandler", "(", "builder", "Builder", ")", "http", ".", "Handler", "{", "b", ":=", "builder", "\n", "if", "b", "==", "nil", "{", "b", "=", "PassthroughBuilder", "\n", "}", "\n", "return", "NewRouter", "(", "c", ",", "b", "(", "NewOperationExecutor", "(", "c", ")", ")", ")", "\n", "}" ]
// RoutesHandler returns a handler to serve the API, just the routes and the contract defined in the swagger spec
[ "RoutesHandler", "returns", "a", "handler", "to", "serve", "the", "API", "just", "the", "routes", "and", "the", "contract", "defined", "in", "the", "swagger", "spec" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/middleware/context.go#L584-L590
10,335
go-openapi/runtime
text.go
TextConsumer
func TextConsumer() Consumer { return ConsumerFunc(func(reader io.Reader, data interface{}) error { if reader == nil { return errors.New("TextConsumer requires a reader") // early exit } buf := new(bytes.Buffer) _, err := buf.ReadFrom(reader) if err != nil { return err } b := buf.Bytes() // If the buffer is empty, no need to unmarshal it, which causes a panic. if len(b) == 0 { data = "" return nil } if tu, ok := data.(encoding.TextUnmarshaler); ok { err := tu.UnmarshalText(b) if err != nil { return fmt.Errorf("text consumer: %v", err) } return nil } t := reflect.TypeOf(data) if data != nil && t.Kind() == reflect.Ptr { v := reflect.Indirect(reflect.ValueOf(data)) if t.Elem().Kind() == reflect.String { v.SetString(string(b)) return nil } } return fmt.Errorf("%v (%T) is not supported by the TextConsumer, %s", data, data, "can be resolved by supporting TextUnmarshaler interface") }) }
go
func TextConsumer() Consumer { return ConsumerFunc(func(reader io.Reader, data interface{}) error { if reader == nil { return errors.New("TextConsumer requires a reader") // early exit } buf := new(bytes.Buffer) _, err := buf.ReadFrom(reader) if err != nil { return err } b := buf.Bytes() // If the buffer is empty, no need to unmarshal it, which causes a panic. if len(b) == 0 { data = "" return nil } if tu, ok := data.(encoding.TextUnmarshaler); ok { err := tu.UnmarshalText(b) if err != nil { return fmt.Errorf("text consumer: %v", err) } return nil } t := reflect.TypeOf(data) if data != nil && t.Kind() == reflect.Ptr { v := reflect.Indirect(reflect.ValueOf(data)) if t.Elem().Kind() == reflect.String { v.SetString(string(b)) return nil } } return fmt.Errorf("%v (%T) is not supported by the TextConsumer, %s", data, data, "can be resolved by supporting TextUnmarshaler interface") }) }
[ "func", "TextConsumer", "(", ")", "Consumer", "{", "return", "ConsumerFunc", "(", "func", "(", "reader", "io", ".", "Reader", ",", "data", "interface", "{", "}", ")", "error", "{", "if", "reader", "==", "nil", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "// early exit", "\n", "}", "\n\n", "buf", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "_", ",", "err", ":=", "buf", ".", "ReadFrom", "(", "reader", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "b", ":=", "buf", ".", "Bytes", "(", ")", "\n\n", "// If the buffer is empty, no need to unmarshal it, which causes a panic.", "if", "len", "(", "b", ")", "==", "0", "{", "data", "=", "\"", "\"", "\n", "return", "nil", "\n", "}", "\n\n", "if", "tu", ",", "ok", ":=", "data", ".", "(", "encoding", ".", "TextUnmarshaler", ")", ";", "ok", "{", "err", ":=", "tu", ".", "UnmarshalText", "(", "b", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}", "\n\n", "t", ":=", "reflect", ".", "TypeOf", "(", "data", ")", "\n", "if", "data", "!=", "nil", "&&", "t", ".", "Kind", "(", ")", "==", "reflect", ".", "Ptr", "{", "v", ":=", "reflect", ".", "Indirect", "(", "reflect", ".", "ValueOf", "(", "data", ")", ")", "\n", "if", "t", ".", "Elem", "(", ")", ".", "Kind", "(", ")", "==", "reflect", ".", "String", "{", "v", ".", "SetString", "(", "string", "(", "b", ")", ")", "\n", "return", "nil", "\n", "}", "\n", "}", "\n\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "data", ",", "data", ",", "\"", "\"", ")", "\n", "}", ")", "\n", "}" ]
// TextConsumer creates a new text consumer
[ "TextConsumer", "creates", "a", "new", "text", "consumer" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/text.go#L29-L69
10,336
go-openapi/runtime
text.go
TextProducer
func TextProducer() Producer { return ProducerFunc(func(writer io.Writer, data interface{}) error { if writer == nil { return errors.New("TextProducer requires a writer") // early exit } if data == nil { return errors.New("no data given to produce text from") } if tm, ok := data.(encoding.TextMarshaler); ok { txt, err := tm.MarshalText() if err != nil { return fmt.Errorf("text producer: %v", err) } _, err = writer.Write(txt) return err } if str, ok := data.(error); ok { _, err := writer.Write([]byte(str.Error())) return err } if str, ok := data.(fmt.Stringer); ok { _, err := writer.Write([]byte(str.String())) return err } v := reflect.Indirect(reflect.ValueOf(data)) if t := v.Type(); t.Kind() == reflect.Struct || t.Kind() == reflect.Slice { b, err := swag.WriteJSON(data) if err != nil { return err } _, err = writer.Write(b) return err } if v.Kind() != reflect.String { return fmt.Errorf("%T is not a supported type by the TextProducer", data) } _, err := writer.Write([]byte(v.String())) return err }) }
go
func TextProducer() Producer { return ProducerFunc(func(writer io.Writer, data interface{}) error { if writer == nil { return errors.New("TextProducer requires a writer") // early exit } if data == nil { return errors.New("no data given to produce text from") } if tm, ok := data.(encoding.TextMarshaler); ok { txt, err := tm.MarshalText() if err != nil { return fmt.Errorf("text producer: %v", err) } _, err = writer.Write(txt) return err } if str, ok := data.(error); ok { _, err := writer.Write([]byte(str.Error())) return err } if str, ok := data.(fmt.Stringer); ok { _, err := writer.Write([]byte(str.String())) return err } v := reflect.Indirect(reflect.ValueOf(data)) if t := v.Type(); t.Kind() == reflect.Struct || t.Kind() == reflect.Slice { b, err := swag.WriteJSON(data) if err != nil { return err } _, err = writer.Write(b) return err } if v.Kind() != reflect.String { return fmt.Errorf("%T is not a supported type by the TextProducer", data) } _, err := writer.Write([]byte(v.String())) return err }) }
[ "func", "TextProducer", "(", ")", "Producer", "{", "return", "ProducerFunc", "(", "func", "(", "writer", "io", ".", "Writer", ",", "data", "interface", "{", "}", ")", "error", "{", "if", "writer", "==", "nil", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "// early exit", "\n", "}", "\n\n", "if", "data", "==", "nil", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "tm", ",", "ok", ":=", "data", ".", "(", "encoding", ".", "TextMarshaler", ")", ";", "ok", "{", "txt", ",", "err", ":=", "tm", ".", "MarshalText", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "_", ",", "err", "=", "writer", ".", "Write", "(", "txt", ")", "\n", "return", "err", "\n", "}", "\n\n", "if", "str", ",", "ok", ":=", "data", ".", "(", "error", ")", ";", "ok", "{", "_", ",", "err", ":=", "writer", ".", "Write", "(", "[", "]", "byte", "(", "str", ".", "Error", "(", ")", ")", ")", "\n", "return", "err", "\n", "}", "\n\n", "if", "str", ",", "ok", ":=", "data", ".", "(", "fmt", ".", "Stringer", ")", ";", "ok", "{", "_", ",", "err", ":=", "writer", ".", "Write", "(", "[", "]", "byte", "(", "str", ".", "String", "(", ")", ")", ")", "\n", "return", "err", "\n", "}", "\n\n", "v", ":=", "reflect", ".", "Indirect", "(", "reflect", ".", "ValueOf", "(", "data", ")", ")", "\n", "if", "t", ":=", "v", ".", "Type", "(", ")", ";", "t", ".", "Kind", "(", ")", "==", "reflect", ".", "Struct", "||", "t", ".", "Kind", "(", ")", "==", "reflect", ".", "Slice", "{", "b", ",", "err", ":=", "swag", ".", "WriteJSON", "(", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "_", ",", "err", "=", "writer", ".", "Write", "(", "b", ")", "\n", "return", "err", "\n", "}", "\n", "if", "v", ".", "Kind", "(", ")", "!=", "reflect", ".", "String", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "data", ")", "\n", "}", "\n\n", "_", ",", "err", ":=", "writer", ".", "Write", "(", "[", "]", "byte", "(", "v", ".", "String", "(", ")", ")", ")", "\n", "return", "err", "\n", "}", ")", "\n", "}" ]
// TextProducer creates a new text producer
[ "TextProducer", "creates", "a", "new", "text", "producer" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/text.go#L72-L117
10,337
go-openapi/runtime
csv.go
CSVConsumer
func CSVConsumer() Consumer { return ConsumerFunc(func(reader io.Reader, data interface{}) error { if reader == nil { return errors.New("CSVConsumer requires a reader") } csvReader := csv.NewReader(reader) writer, ok := data.(io.Writer) if !ok { return errors.New("data type must be io.Writer") } csvWriter := csv.NewWriter(writer) records, err := csvReader.ReadAll() if err != nil { return err } for _, r := range records { if err := csvWriter.Write(r); err != nil { return err } } csvWriter.Flush() return nil }) }
go
func CSVConsumer() Consumer { return ConsumerFunc(func(reader io.Reader, data interface{}) error { if reader == nil { return errors.New("CSVConsumer requires a reader") } csvReader := csv.NewReader(reader) writer, ok := data.(io.Writer) if !ok { return errors.New("data type must be io.Writer") } csvWriter := csv.NewWriter(writer) records, err := csvReader.ReadAll() if err != nil { return err } for _, r := range records { if err := csvWriter.Write(r); err != nil { return err } } csvWriter.Flush() return nil }) }
[ "func", "CSVConsumer", "(", ")", "Consumer", "{", "return", "ConsumerFunc", "(", "func", "(", "reader", "io", ".", "Reader", ",", "data", "interface", "{", "}", ")", "error", "{", "if", "reader", "==", "nil", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "csvReader", ":=", "csv", ".", "NewReader", "(", "reader", ")", "\n", "writer", ",", "ok", ":=", "data", ".", "(", "io", ".", "Writer", ")", "\n", "if", "!", "ok", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "csvWriter", ":=", "csv", ".", "NewWriter", "(", "writer", ")", "\n", "records", ",", "err", ":=", "csvReader", ".", "ReadAll", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "_", ",", "r", ":=", "range", "records", "{", "if", "err", ":=", "csvWriter", ".", "Write", "(", "r", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "csvWriter", ".", "Flush", "(", ")", "\n", "return", "nil", "\n", "}", ")", "\n", "}" ]
// CSVConsumer creates a new CSV consumer
[ "CSVConsumer", "creates", "a", "new", "CSV", "consumer" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/csv.go#L25-L49
10,338
go-openapi/runtime
csv.go
CSVProducer
func CSVProducer() Producer { return ProducerFunc(func(writer io.Writer, data interface{}) error { if writer == nil { return errors.New("CSVProducer requires a writer") } dataBytes, ok := data.([]byte) if !ok { return errors.New("data type must be byte array") } csvReader := csv.NewReader(bytes.NewBuffer(dataBytes)) records, err := csvReader.ReadAll() if err != nil { return err } csvWriter := csv.NewWriter(writer) for _, r := range records { if err := csvWriter.Write(r); err != nil { return err } } csvWriter.Flush() return nil }) }
go
func CSVProducer() Producer { return ProducerFunc(func(writer io.Writer, data interface{}) error { if writer == nil { return errors.New("CSVProducer requires a writer") } dataBytes, ok := data.([]byte) if !ok { return errors.New("data type must be byte array") } csvReader := csv.NewReader(bytes.NewBuffer(dataBytes)) records, err := csvReader.ReadAll() if err != nil { return err } csvWriter := csv.NewWriter(writer) for _, r := range records { if err := csvWriter.Write(r); err != nil { return err } } csvWriter.Flush() return nil }) }
[ "func", "CSVProducer", "(", ")", "Producer", "{", "return", "ProducerFunc", "(", "func", "(", "writer", "io", ".", "Writer", ",", "data", "interface", "{", "}", ")", "error", "{", "if", "writer", "==", "nil", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "dataBytes", ",", "ok", ":=", "data", ".", "(", "[", "]", "byte", ")", "\n", "if", "!", "ok", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "csvReader", ":=", "csv", ".", "NewReader", "(", "bytes", ".", "NewBuffer", "(", "dataBytes", ")", ")", "\n", "records", ",", "err", ":=", "csvReader", ".", "ReadAll", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "csvWriter", ":=", "csv", ".", "NewWriter", "(", "writer", ")", "\n", "for", "_", ",", "r", ":=", "range", "records", "{", "if", "err", ":=", "csvWriter", ".", "Write", "(", "r", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "csvWriter", ".", "Flush", "(", ")", "\n", "return", "nil", "\n", "}", ")", "\n", "}" ]
// CSVProducer creates a new CSV producer
[ "CSVProducer", "creates", "a", "new", "CSV", "producer" ]
a790424692bbda30f61bc3b21754972de1803b91
https://github.com/go-openapi/runtime/blob/a790424692bbda30f61bc3b21754972de1803b91/csv.go#L52-L77
10,339
stretchr/objx
conversions.go
JSON
func (m Map) JSON() (string, error) { for k, v := range m { m[k] = cleanUp(v) } result, err := json.Marshal(m) if err != nil { err = errors.New("objx: JSON encode failed with: " + err.Error()) } return string(result), err }
go
func (m Map) JSON() (string, error) { for k, v := range m { m[k] = cleanUp(v) } result, err := json.Marshal(m) if err != nil { err = errors.New("objx: JSON encode failed with: " + err.Error()) } return string(result), err }
[ "func", "(", "m", "Map", ")", "JSON", "(", ")", "(", "string", ",", "error", ")", "{", "for", "k", ",", "v", ":=", "range", "m", "{", "m", "[", "k", "]", "=", "cleanUp", "(", "v", ")", "\n", "}", "\n\n", "result", ",", "err", ":=", "json", ".", "Marshal", "(", "m", ")", "\n", "if", "err", "!=", "nil", "{", "err", "=", "errors", ".", "New", "(", "\"", "\"", "+", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n", "return", "string", "(", "result", ")", ",", "err", "\n", "}" ]
// JSON converts the contained object to a JSON string // representation
[ "JSON", "converts", "the", "contained", "object", "to", "a", "JSON", "string", "representation" ]
35313a95ee26395aa17d366c71a2ccf788fa69b6
https://github.com/stretchr/objx/blob/35313a95ee26395aa17d366c71a2ccf788fa69b6/conversions.go#L50-L60
10,340
stretchr/objx
conversions.go
MustJSON
func (m Map) MustJSON() string { result, err := m.JSON() if err != nil { panic(err.Error()) } return result }
go
func (m Map) MustJSON() string { result, err := m.JSON() if err != nil { panic(err.Error()) } return result }
[ "func", "(", "m", "Map", ")", "MustJSON", "(", ")", "string", "{", "result", ",", "err", ":=", "m", ".", "JSON", "(", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n", "return", "result", "\n", "}" ]
// MustJSON converts the contained object to a JSON string // representation and panics if there is an error
[ "MustJSON", "converts", "the", "contained", "object", "to", "a", "JSON", "string", "representation", "and", "panics", "if", "there", "is", "an", "error" ]
35313a95ee26395aa17d366c71a2ccf788fa69b6
https://github.com/stretchr/objx/blob/35313a95ee26395aa17d366c71a2ccf788fa69b6/conversions.go#L121-L127
10,341
stretchr/objx
conversions.go
Base64
func (m Map) Base64() (string, error) { var buf bytes.Buffer jsonData, err := m.JSON() if err != nil { return "", err } encoder := base64.NewEncoder(base64.StdEncoding, &buf) _, _ = encoder.Write([]byte(jsonData)) _ = encoder.Close() return buf.String(), nil }
go
func (m Map) Base64() (string, error) { var buf bytes.Buffer jsonData, err := m.JSON() if err != nil { return "", err } encoder := base64.NewEncoder(base64.StdEncoding, &buf) _, _ = encoder.Write([]byte(jsonData)) _ = encoder.Close() return buf.String(), nil }
[ "func", "(", "m", "Map", ")", "Base64", "(", ")", "(", "string", ",", "error", ")", "{", "var", "buf", "bytes", ".", "Buffer", "\n\n", "jsonData", ",", "err", ":=", "m", ".", "JSON", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "encoder", ":=", "base64", ".", "NewEncoder", "(", "base64", ".", "StdEncoding", ",", "&", "buf", ")", "\n", "_", ",", "_", "=", "encoder", ".", "Write", "(", "[", "]", "byte", "(", "jsonData", ")", ")", "\n", "_", "=", "encoder", ".", "Close", "(", ")", "\n\n", "return", "buf", ".", "String", "(", ")", ",", "nil", "\n", "}" ]
// Base64 converts the contained object to a Base64 string // representation of the JSON string representation
[ "Base64", "converts", "the", "contained", "object", "to", "a", "Base64", "string", "representation", "of", "the", "JSON", "string", "representation" ]
35313a95ee26395aa17d366c71a2ccf788fa69b6
https://github.com/stretchr/objx/blob/35313a95ee26395aa17d366c71a2ccf788fa69b6/conversions.go#L131-L144
10,342
stretchr/objx
conversions.go
MustBase64
func (m Map) MustBase64() string { result, err := m.Base64() if err != nil { panic(err.Error()) } return result }
go
func (m Map) MustBase64() string { result, err := m.Base64() if err != nil { panic(err.Error()) } return result }
[ "func", "(", "m", "Map", ")", "MustBase64", "(", ")", "string", "{", "result", ",", "err", ":=", "m", ".", "Base64", "(", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n", "return", "result", "\n", "}" ]
// MustBase64 converts the contained object to a Base64 string // representation of the JSON string representation and panics // if there is an error
[ "MustBase64", "converts", "the", "contained", "object", "to", "a", "Base64", "string", "representation", "of", "the", "JSON", "string", "representation", "and", "panics", "if", "there", "is", "an", "error" ]
35313a95ee26395aa17d366c71a2ccf788fa69b6
https://github.com/stretchr/objx/blob/35313a95ee26395aa17d366c71a2ccf788fa69b6/conversions.go#L149-L155
10,343
stretchr/objx
conversions.go
SignedBase64
func (m Map) SignedBase64(key string) (string, error) { base64, err := m.Base64() if err != nil { return "", err } sig := HashWithKey(base64, key) return base64 + SignatureSeparator + sig, nil }
go
func (m Map) SignedBase64(key string) (string, error) { base64, err := m.Base64() if err != nil { return "", err } sig := HashWithKey(base64, key) return base64 + SignatureSeparator + sig, nil }
[ "func", "(", "m", "Map", ")", "SignedBase64", "(", "key", "string", ")", "(", "string", ",", "error", ")", "{", "base64", ",", "err", ":=", "m", ".", "Base64", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "sig", ":=", "HashWithKey", "(", "base64", ",", "key", ")", "\n", "return", "base64", "+", "SignatureSeparator", "+", "sig", ",", "nil", "\n", "}" ]
// SignedBase64 converts the contained object to a Base64 string // representation of the JSON string representation and signs it // using the provided key.
[ "SignedBase64", "converts", "the", "contained", "object", "to", "a", "Base64", "string", "representation", "of", "the", "JSON", "string", "representation", "and", "signs", "it", "using", "the", "provided", "key", "." ]
35313a95ee26395aa17d366c71a2ccf788fa69b6
https://github.com/stretchr/objx/blob/35313a95ee26395aa17d366c71a2ccf788fa69b6/conversions.go#L160-L168
10,344
stretchr/objx
conversions.go
MustSignedBase64
func (m Map) MustSignedBase64(key string) string { result, err := m.SignedBase64(key) if err != nil { panic(err.Error()) } return result }
go
func (m Map) MustSignedBase64(key string) string { result, err := m.SignedBase64(key) if err != nil { panic(err.Error()) } return result }
[ "func", "(", "m", "Map", ")", "MustSignedBase64", "(", "key", "string", ")", "string", "{", "result", ",", "err", ":=", "m", ".", "SignedBase64", "(", "key", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n", "return", "result", "\n", "}" ]
// MustSignedBase64 converts the contained object to a Base64 string // representation of the JSON string representation and signs it // using the provided key and panics if there is an error
[ "MustSignedBase64", "converts", "the", "contained", "object", "to", "a", "Base64", "string", "representation", "of", "the", "JSON", "string", "representation", "and", "signs", "it", "using", "the", "provided", "key", "and", "panics", "if", "there", "is", "an", "error" ]
35313a95ee26395aa17d366c71a2ccf788fa69b6
https://github.com/stretchr/objx/blob/35313a95ee26395aa17d366c71a2ccf788fa69b6/conversions.go#L173-L179
10,345
stretchr/objx
accessors.go
getKey
func getKey(s string) (string, string) { selSegs := strings.SplitN(s, PathSeparator, 2) thisSel := selSegs[0] nextSel := "" if len(selSegs) > 1 { nextSel = selSegs[1] } mapMatches := mapAccessRegex.FindStringSubmatch(s) if len(mapMatches) > 0 { if _, err := strconv.Atoi(mapMatches[2]); err != nil { thisSel = mapMatches[1] nextSel = "[" + mapMatches[2] + "]" + mapMatches[3] if thisSel == "" { thisSel = mapMatches[2] nextSel = mapMatches[3] } if nextSel == "" { selSegs = []string{"", ""} } else if nextSel[0] == '.' { nextSel = nextSel[1:] } } } return thisSel, nextSel }
go
func getKey(s string) (string, string) { selSegs := strings.SplitN(s, PathSeparator, 2) thisSel := selSegs[0] nextSel := "" if len(selSegs) > 1 { nextSel = selSegs[1] } mapMatches := mapAccessRegex.FindStringSubmatch(s) if len(mapMatches) > 0 { if _, err := strconv.Atoi(mapMatches[2]); err != nil { thisSel = mapMatches[1] nextSel = "[" + mapMatches[2] + "]" + mapMatches[3] if thisSel == "" { thisSel = mapMatches[2] nextSel = mapMatches[3] } if nextSel == "" { selSegs = []string{"", ""} } else if nextSel[0] == '.' { nextSel = nextSel[1:] } } } return thisSel, nextSel }
[ "func", "getKey", "(", "s", "string", ")", "(", "string", ",", "string", ")", "{", "selSegs", ":=", "strings", ".", "SplitN", "(", "s", ",", "PathSeparator", ",", "2", ")", "\n", "thisSel", ":=", "selSegs", "[", "0", "]", "\n", "nextSel", ":=", "\"", "\"", "\n\n", "if", "len", "(", "selSegs", ")", ">", "1", "{", "nextSel", "=", "selSegs", "[", "1", "]", "\n", "}", "\n\n", "mapMatches", ":=", "mapAccessRegex", ".", "FindStringSubmatch", "(", "s", ")", "\n", "if", "len", "(", "mapMatches", ")", ">", "0", "{", "if", "_", ",", "err", ":=", "strconv", ".", "Atoi", "(", "mapMatches", "[", "2", "]", ")", ";", "err", "!=", "nil", "{", "thisSel", "=", "mapMatches", "[", "1", "]", "\n", "nextSel", "=", "\"", "\"", "+", "mapMatches", "[", "2", "]", "+", "\"", "\"", "+", "mapMatches", "[", "3", "]", "\n\n", "if", "thisSel", "==", "\"", "\"", "{", "thisSel", "=", "mapMatches", "[", "2", "]", "\n", "nextSel", "=", "mapMatches", "[", "3", "]", "\n", "}", "\n\n", "if", "nextSel", "==", "\"", "\"", "{", "selSegs", "=", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", "}", "\n", "}", "else", "if", "nextSel", "[", "0", "]", "==", "'.'", "{", "nextSel", "=", "nextSel", "[", "1", ":", "]", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "thisSel", ",", "nextSel", "\n", "}" ]
// getKey returns the key which is held in s by two brackets. // It also returns the next selector.
[ "getKey", "returns", "the", "key", "which", "is", "held", "in", "s", "by", "two", "brackets", ".", "It", "also", "returns", "the", "next", "selector", "." ]
35313a95ee26395aa17d366c71a2ccf788fa69b6
https://github.com/stretchr/objx/blob/35313a95ee26395aa17d366c71a2ccf788fa69b6/accessors.go#L83-L112
10,346
stretchr/objx
accessors.go
access
func access(current interface{}, selector string, value interface{}, isSet bool) interface{} { thisSel, nextSel := getKey(selector) index := -1 if strings.Contains(thisSel, "[") { index, thisSel = getIndex(thisSel) } if curMap, ok := current.(Map); ok { current = map[string]interface{}(curMap) } // get the object in question switch current.(type) { case map[string]interface{}: curMSI := current.(map[string]interface{}) if nextSel == "" && isSet { curMSI[thisSel] = value return nil } _, ok := curMSI[thisSel].(map[string]interface{}) if (curMSI[thisSel] == nil || !ok) && index == -1 && isSet { curMSI[thisSel] = map[string]interface{}{} } current = curMSI[thisSel] default: current = nil } // do we need to access the item of an array? if index > -1 { if array, ok := interSlice(current); ok { if index < len(array) { current = array[index] } else { current = nil } } } if nextSel != "" { current = access(current, nextSel, value, isSet) } return current }
go
func access(current interface{}, selector string, value interface{}, isSet bool) interface{} { thisSel, nextSel := getKey(selector) index := -1 if strings.Contains(thisSel, "[") { index, thisSel = getIndex(thisSel) } if curMap, ok := current.(Map); ok { current = map[string]interface{}(curMap) } // get the object in question switch current.(type) { case map[string]interface{}: curMSI := current.(map[string]interface{}) if nextSel == "" && isSet { curMSI[thisSel] = value return nil } _, ok := curMSI[thisSel].(map[string]interface{}) if (curMSI[thisSel] == nil || !ok) && index == -1 && isSet { curMSI[thisSel] = map[string]interface{}{} } current = curMSI[thisSel] default: current = nil } // do we need to access the item of an array? if index > -1 { if array, ok := interSlice(current); ok { if index < len(array) { current = array[index] } else { current = nil } } } if nextSel != "" { current = access(current, nextSel, value, isSet) } return current }
[ "func", "access", "(", "current", "interface", "{", "}", ",", "selector", "string", ",", "value", "interface", "{", "}", ",", "isSet", "bool", ")", "interface", "{", "}", "{", "thisSel", ",", "nextSel", ":=", "getKey", "(", "selector", ")", "\n\n", "index", ":=", "-", "1", "\n", "if", "strings", ".", "Contains", "(", "thisSel", ",", "\"", "\"", ")", "{", "index", ",", "thisSel", "=", "getIndex", "(", "thisSel", ")", "\n", "}", "\n\n", "if", "curMap", ",", "ok", ":=", "current", ".", "(", "Map", ")", ";", "ok", "{", "current", "=", "map", "[", "string", "]", "interface", "{", "}", "(", "curMap", ")", "\n", "}", "\n", "// get the object in question", "switch", "current", ".", "(", "type", ")", "{", "case", "map", "[", "string", "]", "interface", "{", "}", ":", "curMSI", ":=", "current", ".", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "if", "nextSel", "==", "\"", "\"", "&&", "isSet", "{", "curMSI", "[", "thisSel", "]", "=", "value", "\n", "return", "nil", "\n", "}", "\n\n", "_", ",", "ok", ":=", "curMSI", "[", "thisSel", "]", ".", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "if", "(", "curMSI", "[", "thisSel", "]", "==", "nil", "||", "!", "ok", ")", "&&", "index", "==", "-", "1", "&&", "isSet", "{", "curMSI", "[", "thisSel", "]", "=", "map", "[", "string", "]", "interface", "{", "}", "{", "}", "\n", "}", "\n\n", "current", "=", "curMSI", "[", "thisSel", "]", "\n", "default", ":", "current", "=", "nil", "\n", "}", "\n\n", "// do we need to access the item of an array?", "if", "index", ">", "-", "1", "{", "if", "array", ",", "ok", ":=", "interSlice", "(", "current", ")", ";", "ok", "{", "if", "index", "<", "len", "(", "array", ")", "{", "current", "=", "array", "[", "index", "]", "\n", "}", "else", "{", "current", "=", "nil", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "nextSel", "!=", "\"", "\"", "{", "current", "=", "access", "(", "current", ",", "nextSel", ",", "value", ",", "isSet", ")", "\n", "}", "\n", "return", "current", "\n", "}" ]
// access accesses the object using the selector and performs the // appropriate action.
[ "access", "accesses", "the", "object", "using", "the", "selector", "and", "performs", "the", "appropriate", "action", "." ]
35313a95ee26395aa17d366c71a2ccf788fa69b6
https://github.com/stretchr/objx/blob/35313a95ee26395aa17d366c71a2ccf788fa69b6/accessors.go#L116-L160
10,347
markcheno/go-talib
talib.go
Dema
func Dema(inReal []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inReal)) firstEMA := Ema(inReal, inTimePeriod) secondEMA := Ema(firstEMA[inTimePeriod-1:], inTimePeriod) for outIdx, secondEMAIdx := (inTimePeriod*2)-2, inTimePeriod-1; outIdx < len(inReal); outIdx, secondEMAIdx = outIdx+1, secondEMAIdx+1 { outReal[outIdx] = (2.0 * firstEMA[outIdx]) - secondEMA[secondEMAIdx] } return outReal }
go
func Dema(inReal []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inReal)) firstEMA := Ema(inReal, inTimePeriod) secondEMA := Ema(firstEMA[inTimePeriod-1:], inTimePeriod) for outIdx, secondEMAIdx := (inTimePeriod*2)-2, inTimePeriod-1; outIdx < len(inReal); outIdx, secondEMAIdx = outIdx+1, secondEMAIdx+1 { outReal[outIdx] = (2.0 * firstEMA[outIdx]) - secondEMA[secondEMAIdx] } return outReal }
[ "func", "Dema", "(", "inReal", "[", "]", "float64", ",", "inTimePeriod", "int", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n", "firstEMA", ":=", "Ema", "(", "inReal", ",", "inTimePeriod", ")", "\n", "secondEMA", ":=", "Ema", "(", "firstEMA", "[", "inTimePeriod", "-", "1", ":", "]", ",", "inTimePeriod", ")", "\n\n", "for", "outIdx", ",", "secondEMAIdx", ":=", "(", "inTimePeriod", "*", "2", ")", "-", "2", ",", "inTimePeriod", "-", "1", ";", "outIdx", "<", "len", "(", "inReal", ")", ";", "outIdx", ",", "secondEMAIdx", "=", "outIdx", "+", "1", ",", "secondEMAIdx", "+", "1", "{", "outReal", "[", "outIdx", "]", "=", "(", "2.0", "*", "firstEMA", "[", "outIdx", "]", ")", "-", "secondEMA", "[", "secondEMAIdx", "]", "\n", "}", "\n\n", "return", "outReal", "\n", "}" ]
// Dema - Double Exponential Moving Average
[ "Dema", "-", "Double", "Exponential", "Moving", "Average" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L90-L101
10,348
markcheno/go-talib
talib.go
Ma
func Ma(inReal []float64, inTimePeriod int, inMAType MaType) []float64 { outReal := make([]float64, len(inReal)) if inTimePeriod == 1 { copy(outReal, inReal) return outReal } switch inMAType { case SMA: outReal = Sma(inReal, inTimePeriod) case EMA: outReal = Ema(inReal, inTimePeriod) case WMA: outReal = Wma(inReal, inTimePeriod) case DEMA: outReal = Dema(inReal, inTimePeriod) case TEMA: outReal = Tema(inReal, inTimePeriod) case TRIMA: outReal = Trima(inReal, inTimePeriod) case KAMA: outReal = Kama(inReal, inTimePeriod) case MAMA: outReal, _ = Mama(inReal, 0.5, 0.05) case T3MA: outReal = T3(inReal, inTimePeriod, 0.7) } return outReal }
go
func Ma(inReal []float64, inTimePeriod int, inMAType MaType) []float64 { outReal := make([]float64, len(inReal)) if inTimePeriod == 1 { copy(outReal, inReal) return outReal } switch inMAType { case SMA: outReal = Sma(inReal, inTimePeriod) case EMA: outReal = Ema(inReal, inTimePeriod) case WMA: outReal = Wma(inReal, inTimePeriod) case DEMA: outReal = Dema(inReal, inTimePeriod) case TEMA: outReal = Tema(inReal, inTimePeriod) case TRIMA: outReal = Trima(inReal, inTimePeriod) case KAMA: outReal = Kama(inReal, inTimePeriod) case MAMA: outReal, _ = Mama(inReal, 0.5, 0.05) case T3MA: outReal = T3(inReal, inTimePeriod, 0.7) } return outReal }
[ "func", "Ma", "(", "inReal", "[", "]", "float64", ",", "inTimePeriod", "int", ",", "inMAType", "MaType", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n\n", "if", "inTimePeriod", "==", "1", "{", "copy", "(", "outReal", ",", "inReal", ")", "\n", "return", "outReal", "\n", "}", "\n\n", "switch", "inMAType", "{", "case", "SMA", ":", "outReal", "=", "Sma", "(", "inReal", ",", "inTimePeriod", ")", "\n", "case", "EMA", ":", "outReal", "=", "Ema", "(", "inReal", ",", "inTimePeriod", ")", "\n", "case", "WMA", ":", "outReal", "=", "Wma", "(", "inReal", ",", "inTimePeriod", ")", "\n", "case", "DEMA", ":", "outReal", "=", "Dema", "(", "inReal", ",", "inTimePeriod", ")", "\n", "case", "TEMA", ":", "outReal", "=", "Tema", "(", "inReal", ",", "inTimePeriod", ")", "\n", "case", "TRIMA", ":", "outReal", "=", "Trima", "(", "inReal", ",", "inTimePeriod", ")", "\n", "case", "KAMA", ":", "outReal", "=", "Kama", "(", "inReal", ",", "inTimePeriod", ")", "\n", "case", "MAMA", ":", "outReal", ",", "_", "=", "Mama", "(", "inReal", ",", "0.5", ",", "0.05", ")", "\n", "case", "T3MA", ":", "outReal", "=", "T3", "(", "inReal", ",", "inTimePeriod", ",", "0.7", ")", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// Ma - Moving average
[ "Ma", "-", "Moving", "average" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L462-L492
10,349
markcheno/go-talib
talib.go
MaVp
func MaVp(inReal []float64, inPeriods []float64, inMinPeriod int, inMaxPeriod int, inMAType MaType) []float64 { outReal := make([]float64, len(inReal)) startIdx := inMaxPeriod - 1 outputSize := len(inReal) localPeriodArray := make([]float64, outputSize) for i := startIdx; i < outputSize; i++ { tempInt := int(inPeriods[i]) if tempInt < inMinPeriod { tempInt = inMinPeriod } else if tempInt > inMaxPeriod { tempInt = inMaxPeriod } localPeriodArray[i] = float64(tempInt) } for i := startIdx; i < outputSize; i++ { curPeriod := int(localPeriodArray[i]) if curPeriod != 0 { localOutputArray := Ma(inReal, curPeriod, inMAType) outReal[i] = localOutputArray[i] for j := i + 1; j < outputSize; j++ { if localPeriodArray[j] == float64(curPeriod) { localPeriodArray[j] = 0 outReal[j] = localOutputArray[j] } } } } return outReal }
go
func MaVp(inReal []float64, inPeriods []float64, inMinPeriod int, inMaxPeriod int, inMAType MaType) []float64 { outReal := make([]float64, len(inReal)) startIdx := inMaxPeriod - 1 outputSize := len(inReal) localPeriodArray := make([]float64, outputSize) for i := startIdx; i < outputSize; i++ { tempInt := int(inPeriods[i]) if tempInt < inMinPeriod { tempInt = inMinPeriod } else if tempInt > inMaxPeriod { tempInt = inMaxPeriod } localPeriodArray[i] = float64(tempInt) } for i := startIdx; i < outputSize; i++ { curPeriod := int(localPeriodArray[i]) if curPeriod != 0 { localOutputArray := Ma(inReal, curPeriod, inMAType) outReal[i] = localOutputArray[i] for j := i + 1; j < outputSize; j++ { if localPeriodArray[j] == float64(curPeriod) { localPeriodArray[j] = 0 outReal[j] = localOutputArray[j] } } } } return outReal }
[ "func", "MaVp", "(", "inReal", "[", "]", "float64", ",", "inPeriods", "[", "]", "float64", ",", "inMinPeriod", "int", ",", "inMaxPeriod", "int", ",", "inMAType", "MaType", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n", "startIdx", ":=", "inMaxPeriod", "-", "1", "\n", "outputSize", ":=", "len", "(", "inReal", ")", "\n\n", "localPeriodArray", ":=", "make", "(", "[", "]", "float64", ",", "outputSize", ")", "\n", "for", "i", ":=", "startIdx", ";", "i", "<", "outputSize", ";", "i", "++", "{", "tempInt", ":=", "int", "(", "inPeriods", "[", "i", "]", ")", "\n", "if", "tempInt", "<", "inMinPeriod", "{", "tempInt", "=", "inMinPeriod", "\n", "}", "else", "if", "tempInt", ">", "inMaxPeriod", "{", "tempInt", "=", "inMaxPeriod", "\n", "}", "\n", "localPeriodArray", "[", "i", "]", "=", "float64", "(", "tempInt", ")", "\n", "}", "\n\n", "for", "i", ":=", "startIdx", ";", "i", "<", "outputSize", ";", "i", "++", "{", "curPeriod", ":=", "int", "(", "localPeriodArray", "[", "i", "]", ")", "\n", "if", "curPeriod", "!=", "0", "{", "localOutputArray", ":=", "Ma", "(", "inReal", ",", "curPeriod", ",", "inMAType", ")", "\n", "outReal", "[", "i", "]", "=", "localOutputArray", "[", "i", "]", "\n", "for", "j", ":=", "i", "+", "1", ";", "j", "<", "outputSize", ";", "j", "++", "{", "if", "localPeriodArray", "[", "j", "]", "==", "float64", "(", "curPeriod", ")", "{", "localPeriodArray", "[", "j", "]", "=", "0", "\n", "outReal", "[", "j", "]", "=", "localOutputArray", "[", "j", "]", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// MaVp - Moving average with variable period
[ "MaVp", "-", "Moving", "average", "with", "variable", "period" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L771-L802
10,350
markcheno/go-talib
talib.go
MidPoint
func MidPoint(inReal []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inReal)) nbInitialElementNeeded := inTimePeriod - 1 startIdx := nbInitialElementNeeded outIdx := inTimePeriod - 1 today := startIdx trailingIdx := startIdx - nbInitialElementNeeded for today < len(inReal) { lowest := inReal[trailingIdx] trailingIdx++ highest := lowest for i := trailingIdx; i <= today; i++ { tmp := inReal[i] if tmp < lowest { lowest = tmp } else if tmp > highest { highest = tmp } } outReal[outIdx] = (highest + lowest) / 2.0 outIdx++ today++ } return outReal }
go
func MidPoint(inReal []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inReal)) nbInitialElementNeeded := inTimePeriod - 1 startIdx := nbInitialElementNeeded outIdx := inTimePeriod - 1 today := startIdx trailingIdx := startIdx - nbInitialElementNeeded for today < len(inReal) { lowest := inReal[trailingIdx] trailingIdx++ highest := lowest for i := trailingIdx; i <= today; i++ { tmp := inReal[i] if tmp < lowest { lowest = tmp } else if tmp > highest { highest = tmp } } outReal[outIdx] = (highest + lowest) / 2.0 outIdx++ today++ } return outReal }
[ "func", "MidPoint", "(", "inReal", "[", "]", "float64", ",", "inTimePeriod", "int", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n", "nbInitialElementNeeded", ":=", "inTimePeriod", "-", "1", "\n", "startIdx", ":=", "nbInitialElementNeeded", "\n", "outIdx", ":=", "inTimePeriod", "-", "1", "\n", "today", ":=", "startIdx", "\n", "trailingIdx", ":=", "startIdx", "-", "nbInitialElementNeeded", "\n\n", "for", "today", "<", "len", "(", "inReal", ")", "{", "lowest", ":=", "inReal", "[", "trailingIdx", "]", "\n", "trailingIdx", "++", "\n", "highest", ":=", "lowest", "\n", "for", "i", ":=", "trailingIdx", ";", "i", "<=", "today", ";", "i", "++", "{", "tmp", ":=", "inReal", "[", "i", "]", "\n", "if", "tmp", "<", "lowest", "{", "lowest", "=", "tmp", "\n", "}", "else", "if", "tmp", ">", "highest", "{", "highest", "=", "tmp", "\n", "}", "\n", "}", "\n", "outReal", "[", "outIdx", "]", "=", "(", "highest", "+", "lowest", ")", "/", "2.0", "\n", "outIdx", "++", "\n", "today", "++", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// MidPoint - MidPoint over period
[ "MidPoint", "-", "MidPoint", "over", "period" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L805-L831
10,351
markcheno/go-talib
talib.go
MidPrice
func MidPrice(inHigh []float64, inLow []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inHigh)) nbInitialElementNeeded := inTimePeriod - 1 startIdx := nbInitialElementNeeded outIdx := inTimePeriod - 1 today := startIdx trailingIdx := startIdx - nbInitialElementNeeded for today < len(inHigh) { lowest := inLow[trailingIdx] highest := inHigh[trailingIdx] trailingIdx++ for i := trailingIdx; i <= today; i++ { tmp := inLow[i] if tmp < lowest { lowest = tmp } tmp = inHigh[i] if tmp > highest { highest = tmp } } outReal[outIdx] = (highest + lowest) / 2.0 outIdx++ today++ } return outReal }
go
func MidPrice(inHigh []float64, inLow []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inHigh)) nbInitialElementNeeded := inTimePeriod - 1 startIdx := nbInitialElementNeeded outIdx := inTimePeriod - 1 today := startIdx trailingIdx := startIdx - nbInitialElementNeeded for today < len(inHigh) { lowest := inLow[trailingIdx] highest := inHigh[trailingIdx] trailingIdx++ for i := trailingIdx; i <= today; i++ { tmp := inLow[i] if tmp < lowest { lowest = tmp } tmp = inHigh[i] if tmp > highest { highest = tmp } } outReal[outIdx] = (highest + lowest) / 2.0 outIdx++ today++ } return outReal }
[ "func", "MidPrice", "(", "inHigh", "[", "]", "float64", ",", "inLow", "[", "]", "float64", ",", "inTimePeriod", "int", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inHigh", ")", ")", "\n\n", "nbInitialElementNeeded", ":=", "inTimePeriod", "-", "1", "\n", "startIdx", ":=", "nbInitialElementNeeded", "\n", "outIdx", ":=", "inTimePeriod", "-", "1", "\n", "today", ":=", "startIdx", "\n", "trailingIdx", ":=", "startIdx", "-", "nbInitialElementNeeded", "\n", "for", "today", "<", "len", "(", "inHigh", ")", "{", "lowest", ":=", "inLow", "[", "trailingIdx", "]", "\n", "highest", ":=", "inHigh", "[", "trailingIdx", "]", "\n", "trailingIdx", "++", "\n", "for", "i", ":=", "trailingIdx", ";", "i", "<=", "today", ";", "i", "++", "{", "tmp", ":=", "inLow", "[", "i", "]", "\n", "if", "tmp", "<", "lowest", "{", "lowest", "=", "tmp", "\n", "}", "\n", "tmp", "=", "inHigh", "[", "i", "]", "\n", "if", "tmp", ">", "highest", "{", "highest", "=", "tmp", "\n", "}", "\n", "}", "\n", "outReal", "[", "outIdx", "]", "=", "(", "highest", "+", "lowest", ")", "/", "2.0", "\n", "outIdx", "++", "\n", "today", "++", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// MidPrice - Midpoint Price over period
[ "MidPrice", "-", "Midpoint", "Price", "over", "period" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L834-L862
10,352
markcheno/go-talib
talib.go
Sma
func Sma(inReal []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inReal)) lookbackTotal := inTimePeriod - 1 startIdx := lookbackTotal periodTotal := 0.0 trailingIdx := startIdx - lookbackTotal i := trailingIdx if inTimePeriod > 1 { for i < startIdx { periodTotal += inReal[i] i++ } } outIdx := startIdx for ok := true; ok; { periodTotal += inReal[i] tempReal := periodTotal periodTotal -= inReal[trailingIdx] outReal[outIdx] = tempReal / float64(inTimePeriod) trailingIdx++ i++ outIdx++ ok = i < len(outReal) } return outReal }
go
func Sma(inReal []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inReal)) lookbackTotal := inTimePeriod - 1 startIdx := lookbackTotal periodTotal := 0.0 trailingIdx := startIdx - lookbackTotal i := trailingIdx if inTimePeriod > 1 { for i < startIdx { periodTotal += inReal[i] i++ } } outIdx := startIdx for ok := true; ok; { periodTotal += inReal[i] tempReal := periodTotal periodTotal -= inReal[trailingIdx] outReal[outIdx] = tempReal / float64(inTimePeriod) trailingIdx++ i++ outIdx++ ok = i < len(outReal) } return outReal }
[ "func", "Sma", "(", "inReal", "[", "]", "float64", ",", "inTimePeriod", "int", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n\n", "lookbackTotal", ":=", "inTimePeriod", "-", "1", "\n", "startIdx", ":=", "lookbackTotal", "\n", "periodTotal", ":=", "0.0", "\n", "trailingIdx", ":=", "startIdx", "-", "lookbackTotal", "\n", "i", ":=", "trailingIdx", "\n", "if", "inTimePeriod", ">", "1", "{", "for", "i", "<", "startIdx", "{", "periodTotal", "+=", "inReal", "[", "i", "]", "\n", "i", "++", "\n", "}", "\n", "}", "\n", "outIdx", ":=", "startIdx", "\n", "for", "ok", ":=", "true", ";", "ok", ";", "{", "periodTotal", "+=", "inReal", "[", "i", "]", "\n", "tempReal", ":=", "periodTotal", "\n", "periodTotal", "-=", "inReal", "[", "trailingIdx", "]", "\n", "outReal", "[", "outIdx", "]", "=", "tempReal", "/", "float64", "(", "inTimePeriod", ")", "\n", "trailingIdx", "++", "\n", "i", "++", "\n", "outIdx", "++", "\n", "ok", "=", "i", "<", "len", "(", "outReal", ")", "\n", "}", "\n\n", "return", "outReal", "\n", "}" ]
// Sma - Simple Moving Average
[ "Sma", "-", "Simple", "Moving", "Average" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L1151-L1179
10,353
markcheno/go-talib
talib.go
Tema
func Tema(inReal []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inReal)) firstEMA := Ema(inReal, inTimePeriod) secondEMA := Ema(firstEMA[inTimePeriod-1:], inTimePeriod) thirdEMA := Ema(secondEMA[inTimePeriod-1:], inTimePeriod) outIdx := (inTimePeriod * 3) - 3 secondEMAIdx := (inTimePeriod * 2) - 2 thirdEMAIdx := inTimePeriod - 1 for outIdx < len(inReal) { outReal[outIdx] = thirdEMA[thirdEMAIdx] + ((3.0 * firstEMA[outIdx]) - (3.0 * secondEMA[secondEMAIdx])) outIdx++ secondEMAIdx++ thirdEMAIdx++ } return outReal }
go
func Tema(inReal []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inReal)) firstEMA := Ema(inReal, inTimePeriod) secondEMA := Ema(firstEMA[inTimePeriod-1:], inTimePeriod) thirdEMA := Ema(secondEMA[inTimePeriod-1:], inTimePeriod) outIdx := (inTimePeriod * 3) - 3 secondEMAIdx := (inTimePeriod * 2) - 2 thirdEMAIdx := inTimePeriod - 1 for outIdx < len(inReal) { outReal[outIdx] = thirdEMA[thirdEMAIdx] + ((3.0 * firstEMA[outIdx]) - (3.0 * secondEMA[secondEMAIdx])) outIdx++ secondEMAIdx++ thirdEMAIdx++ } return outReal }
[ "func", "Tema", "(", "inReal", "[", "]", "float64", ",", "inTimePeriod", "int", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n", "firstEMA", ":=", "Ema", "(", "inReal", ",", "inTimePeriod", ")", "\n", "secondEMA", ":=", "Ema", "(", "firstEMA", "[", "inTimePeriod", "-", "1", ":", "]", ",", "inTimePeriod", ")", "\n", "thirdEMA", ":=", "Ema", "(", "secondEMA", "[", "inTimePeriod", "-", "1", ":", "]", ",", "inTimePeriod", ")", "\n\n", "outIdx", ":=", "(", "inTimePeriod", "*", "3", ")", "-", "3", "\n", "secondEMAIdx", ":=", "(", "inTimePeriod", "*", "2", ")", "-", "2", "\n", "thirdEMAIdx", ":=", "inTimePeriod", "-", "1", "\n\n", "for", "outIdx", "<", "len", "(", "inReal", ")", "{", "outReal", "[", "outIdx", "]", "=", "thirdEMA", "[", "thirdEMAIdx", "]", "+", "(", "(", "3.0", "*", "firstEMA", "[", "outIdx", "]", ")", "-", "(", "3.0", "*", "secondEMA", "[", "secondEMAIdx", "]", ")", ")", "\n", "outIdx", "++", "\n", "secondEMAIdx", "++", "\n", "thirdEMAIdx", "++", "\n", "}", "\n\n", "return", "outReal", "\n", "}" ]
// Tema - Triple Exponential Moving Average
[ "Tema", "-", "Triple", "Exponential", "Moving", "Average" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L1276-L1295
10,354
markcheno/go-talib
talib.go
Wma
func Wma(inReal []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inReal)) lookbackTotal := inTimePeriod - 1 startIdx := lookbackTotal if inTimePeriod == 1 { copy(outReal, inReal) return outReal } divider := (inTimePeriod * (inTimePeriod + 1)) >> 1 outIdx := inTimePeriod - 1 trailingIdx := startIdx - lookbackTotal periodSum, periodSub := 0.0, 0.0 inIdx := trailingIdx i := 1 for inIdx < startIdx { tempReal := inReal[inIdx] periodSub += tempReal periodSum += tempReal * float64(i) inIdx++ i++ } trailingValue := 0.0 for inIdx < len(inReal) { tempReal := inReal[inIdx] periodSub += tempReal periodSub -= trailingValue periodSum += tempReal * float64(inTimePeriod) trailingValue = inReal[trailingIdx] outReal[outIdx] = periodSum / float64(divider) periodSum -= periodSub inIdx++ trailingIdx++ outIdx++ } return outReal }
go
func Wma(inReal []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inReal)) lookbackTotal := inTimePeriod - 1 startIdx := lookbackTotal if inTimePeriod == 1 { copy(outReal, inReal) return outReal } divider := (inTimePeriod * (inTimePeriod + 1)) >> 1 outIdx := inTimePeriod - 1 trailingIdx := startIdx - lookbackTotal periodSum, periodSub := 0.0, 0.0 inIdx := trailingIdx i := 1 for inIdx < startIdx { tempReal := inReal[inIdx] periodSub += tempReal periodSum += tempReal * float64(i) inIdx++ i++ } trailingValue := 0.0 for inIdx < len(inReal) { tempReal := inReal[inIdx] periodSub += tempReal periodSub -= trailingValue periodSum += tempReal * float64(inTimePeriod) trailingValue = inReal[trailingIdx] outReal[outIdx] = periodSum / float64(divider) periodSum -= periodSub inIdx++ trailingIdx++ outIdx++ } return outReal }
[ "func", "Wma", "(", "inReal", "[", "]", "float64", ",", "inTimePeriod", "int", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n\n", "lookbackTotal", ":=", "inTimePeriod", "-", "1", "\n", "startIdx", ":=", "lookbackTotal", "\n\n", "if", "inTimePeriod", "==", "1", "{", "copy", "(", "outReal", ",", "inReal", ")", "\n", "return", "outReal", "\n", "}", "\n", "divider", ":=", "(", "inTimePeriod", "*", "(", "inTimePeriod", "+", "1", ")", ")", ">>", "1", "\n", "outIdx", ":=", "inTimePeriod", "-", "1", "\n", "trailingIdx", ":=", "startIdx", "-", "lookbackTotal", "\n", "periodSum", ",", "periodSub", ":=", "0.0", ",", "0.0", "\n", "inIdx", ":=", "trailingIdx", "\n", "i", ":=", "1", "\n", "for", "inIdx", "<", "startIdx", "{", "tempReal", ":=", "inReal", "[", "inIdx", "]", "\n", "periodSub", "+=", "tempReal", "\n", "periodSum", "+=", "tempReal", "*", "float64", "(", "i", ")", "\n", "inIdx", "++", "\n", "i", "++", "\n", "}", "\n", "trailingValue", ":=", "0.0", "\n", "for", "inIdx", "<", "len", "(", "inReal", ")", "{", "tempReal", ":=", "inReal", "[", "inIdx", "]", "\n", "periodSub", "+=", "tempReal", "\n", "periodSub", "-=", "trailingValue", "\n", "periodSum", "+=", "tempReal", "*", "float64", "(", "inTimePeriod", ")", "\n", "trailingValue", "=", "inReal", "[", "trailingIdx", "]", "\n", "outReal", "[", "outIdx", "]", "=", "periodSum", "/", "float64", "(", "divider", ")", "\n", "periodSum", "-=", "periodSub", "\n", "inIdx", "++", "\n", "trailingIdx", "++", "\n", "outIdx", "++", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// Wma - Weighted Moving Average
[ "Wma", "-", "Weighted", "Moving", "Average" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L1403-L1441
10,355
markcheno/go-talib
talib.go
AdxR
func AdxR(inHigh []float64, inLow []float64, inClose []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inClose)) startIdx := (2 * inTimePeriod) - 1 tmpadx := Adx(inHigh, inLow, inClose, inTimePeriod) i := startIdx j := startIdx + inTimePeriod - 1 for outIdx := startIdx + inTimePeriod - 1; outIdx < len(inClose); outIdx, i, j = outIdx+1, i+1, j+1 { outReal[outIdx] = ((tmpadx[i] + tmpadx[j]) / 2.0) } return outReal }
go
func AdxR(inHigh []float64, inLow []float64, inClose []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inClose)) startIdx := (2 * inTimePeriod) - 1 tmpadx := Adx(inHigh, inLow, inClose, inTimePeriod) i := startIdx j := startIdx + inTimePeriod - 1 for outIdx := startIdx + inTimePeriod - 1; outIdx < len(inClose); outIdx, i, j = outIdx+1, i+1, j+1 { outReal[outIdx] = ((tmpadx[i] + tmpadx[j]) / 2.0) } return outReal }
[ "func", "AdxR", "(", "inHigh", "[", "]", "float64", ",", "inLow", "[", "]", "float64", ",", "inClose", "[", "]", "float64", ",", "inTimePeriod", "int", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inClose", ")", ")", "\n", "startIdx", ":=", "(", "2", "*", "inTimePeriod", ")", "-", "1", "\n", "tmpadx", ":=", "Adx", "(", "inHigh", ",", "inLow", ",", "inClose", ",", "inTimePeriod", ")", "\n", "i", ":=", "startIdx", "\n", "j", ":=", "startIdx", "+", "inTimePeriod", "-", "1", "\n", "for", "outIdx", ":=", "startIdx", "+", "inTimePeriod", "-", "1", ";", "outIdx", "<", "len", "(", "inClose", ")", ";", "outIdx", ",", "i", ",", "j", "=", "outIdx", "+", "1", ",", "i", "+", "1", ",", "j", "+", "1", "{", "outReal", "[", "outIdx", "]", "=", "(", "(", "tmpadx", "[", "i", "]", "+", "tmpadx", "[", "j", "]", ")", "/", "2.0", ")", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// AdxR - Average Directional Movement Index Rating
[ "AdxR", "-", "Average", "Directional", "Movement", "Index", "Rating" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L1572-L1583
10,356
markcheno/go-talib
talib.go
AroonOsc
func AroonOsc(inHigh []float64, inLow []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inHigh)) startIdx := inTimePeriod outIdx := startIdx today := startIdx trailingIdx := startIdx - inTimePeriod lowestIdx := -1 highestIdx := -1 lowest := 0.0 highest := 0.0 factor := 100.0 / float64(inTimePeriod) for today < len(inHigh) { tmp := inLow[today] if lowestIdx < trailingIdx { lowestIdx = trailingIdx lowest = inLow[lowestIdx] i := lowestIdx i++ for i <= today { tmp = inLow[i] if tmp <= lowest { lowestIdx = i lowest = tmp } i++ } } else if tmp <= lowest { lowestIdx = today lowest = tmp } tmp = inHigh[today] if highestIdx < trailingIdx { highestIdx = trailingIdx highest = inHigh[highestIdx] i := highestIdx i++ for i <= today { tmp = inHigh[i] if tmp >= highest { highestIdx = i highest = tmp } i++ } } else if tmp >= highest { highestIdx = today highest = tmp } aroon := factor * float64(highestIdx-lowestIdx) outReal[outIdx] = aroon outIdx++ trailingIdx++ today++ } return outReal }
go
func AroonOsc(inHigh []float64, inLow []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inHigh)) startIdx := inTimePeriod outIdx := startIdx today := startIdx trailingIdx := startIdx - inTimePeriod lowestIdx := -1 highestIdx := -1 lowest := 0.0 highest := 0.0 factor := 100.0 / float64(inTimePeriod) for today < len(inHigh) { tmp := inLow[today] if lowestIdx < trailingIdx { lowestIdx = trailingIdx lowest = inLow[lowestIdx] i := lowestIdx i++ for i <= today { tmp = inLow[i] if tmp <= lowest { lowestIdx = i lowest = tmp } i++ } } else if tmp <= lowest { lowestIdx = today lowest = tmp } tmp = inHigh[today] if highestIdx < trailingIdx { highestIdx = trailingIdx highest = inHigh[highestIdx] i := highestIdx i++ for i <= today { tmp = inHigh[i] if tmp >= highest { highestIdx = i highest = tmp } i++ } } else if tmp >= highest { highestIdx = today highest = tmp } aroon := factor * float64(highestIdx-lowestIdx) outReal[outIdx] = aroon outIdx++ trailingIdx++ today++ } return outReal }
[ "func", "AroonOsc", "(", "inHigh", "[", "]", "float64", ",", "inLow", "[", "]", "float64", ",", "inTimePeriod", "int", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inHigh", ")", ")", "\n\n", "startIdx", ":=", "inTimePeriod", "\n", "outIdx", ":=", "startIdx", "\n", "today", ":=", "startIdx", "\n", "trailingIdx", ":=", "startIdx", "-", "inTimePeriod", "\n", "lowestIdx", ":=", "-", "1", "\n", "highestIdx", ":=", "-", "1", "\n", "lowest", ":=", "0.0", "\n", "highest", ":=", "0.0", "\n", "factor", ":=", "100.0", "/", "float64", "(", "inTimePeriod", ")", "\n", "for", "today", "<", "len", "(", "inHigh", ")", "{", "tmp", ":=", "inLow", "[", "today", "]", "\n", "if", "lowestIdx", "<", "trailingIdx", "{", "lowestIdx", "=", "trailingIdx", "\n", "lowest", "=", "inLow", "[", "lowestIdx", "]", "\n", "i", ":=", "lowestIdx", "\n", "i", "++", "\n", "for", "i", "<=", "today", "{", "tmp", "=", "inLow", "[", "i", "]", "\n", "if", "tmp", "<=", "lowest", "{", "lowestIdx", "=", "i", "\n", "lowest", "=", "tmp", "\n", "}", "\n", "i", "++", "\n", "}", "\n", "}", "else", "if", "tmp", "<=", "lowest", "{", "lowestIdx", "=", "today", "\n", "lowest", "=", "tmp", "\n", "}", "\n", "tmp", "=", "inHigh", "[", "today", "]", "\n", "if", "highestIdx", "<", "trailingIdx", "{", "highestIdx", "=", "trailingIdx", "\n", "highest", "=", "inHigh", "[", "highestIdx", "]", "\n", "i", ":=", "highestIdx", "\n", "i", "++", "\n", "for", "i", "<=", "today", "{", "tmp", "=", "inHigh", "[", "i", "]", "\n", "if", "tmp", ">=", "highest", "{", "highestIdx", "=", "i", "\n", "highest", "=", "tmp", "\n", "}", "\n", "i", "++", "\n", "}", "\n", "}", "else", "if", "tmp", ">=", "highest", "{", "highestIdx", "=", "today", "\n", "highest", "=", "tmp", "\n", "}", "\n", "aroon", ":=", "factor", "*", "float64", "(", "highestIdx", "-", "lowestIdx", ")", "\n", "outReal", "[", "outIdx", "]", "=", "aroon", "\n", "outIdx", "++", "\n", "trailingIdx", "++", "\n", "today", "++", "\n", "}", "\n\n", "return", "outReal", "\n", "}" ]
// AroonOsc - Aroon Oscillator
[ "AroonOsc", "-", "Aroon", "Oscillator" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L1663-L1721
10,357
markcheno/go-talib
talib.go
Bop
func Bop(inOpen []float64, inHigh []float64, inLow []float64, inClose []float64) []float64 { outReal := make([]float64, len(inClose)) for i := 0; i < len(inClose); i++ { tempReal := inHigh[i] - inLow[i] if tempReal < (0.00000000000001) { outReal[i] = 0.0 } else { outReal[i] = (inClose[i] - inOpen[i]) / tempReal } } return outReal }
go
func Bop(inOpen []float64, inHigh []float64, inLow []float64, inClose []float64) []float64 { outReal := make([]float64, len(inClose)) for i := 0; i < len(inClose); i++ { tempReal := inHigh[i] - inLow[i] if tempReal < (0.00000000000001) { outReal[i] = 0.0 } else { outReal[i] = (inClose[i] - inOpen[i]) / tempReal } } return outReal }
[ "func", "Bop", "(", "inOpen", "[", "]", "float64", ",", "inHigh", "[", "]", "float64", ",", "inLow", "[", "]", "float64", ",", "inClose", "[", "]", "float64", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inClose", ")", ")", "\n\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "inClose", ")", ";", "i", "++", "{", "tempReal", ":=", "inHigh", "[", "i", "]", "-", "inLow", "[", "i", "]", "\n", "if", "tempReal", "<", "(", "0.00000000000001", ")", "{", "outReal", "[", "i", "]", "=", "0.0", "\n", "}", "else", "{", "outReal", "[", "i", "]", "=", "(", "inClose", "[", "i", "]", "-", "inOpen", "[", "i", "]", ")", "/", "tempReal", "\n", "}", "\n", "}", "\n\n", "return", "outReal", "\n", "}" ]
// Bop - Balance Of Power
[ "Bop", "-", "Balance", "Of", "Power" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L1724-L1738
10,358
markcheno/go-talib
talib.go
Cmo
func Cmo(inReal []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inReal)) lookbackTotal := inTimePeriod startIdx := lookbackTotal outIdx := startIdx if inTimePeriod == 1 { copy(outReal, inReal) return outReal } today := startIdx - lookbackTotal prevValue := inReal[today] prevGain := 0.0 prevLoss := 0.0 today++ for i := inTimePeriod; i > 0; i-- { tempValue1 := inReal[today] tempValue2 := tempValue1 - prevValue prevValue = tempValue1 if tempValue2 < 0 { prevLoss -= tempValue2 } else { prevGain += tempValue2 } today++ } prevLoss /= float64(inTimePeriod) prevGain /= float64(inTimePeriod) if today > startIdx { tempValue1 := prevGain + prevLoss if !(((-(0.00000000000001)) < tempValue1) && (tempValue1 < (0.00000000000001))) { outReal[outIdx] = 100.0 * ((prevGain - prevLoss) / tempValue1) } else { outReal[outIdx] = 0.0 } outIdx++ } else { for today < startIdx { tempValue1 := inReal[today] tempValue2 := tempValue1 - prevValue prevValue = tempValue1 prevLoss *= float64(inTimePeriod - 1) prevGain *= float64(inTimePeriod - 1) if tempValue2 < 0 { prevLoss -= tempValue2 } else { prevGain += tempValue2 } prevLoss /= float64(inTimePeriod) prevGain /= float64(inTimePeriod) today++ } } for today < len(inReal) { tempValue1 := inReal[today] today++ tempValue2 := tempValue1 - prevValue prevValue = tempValue1 prevLoss *= float64(inTimePeriod - 1) prevGain *= float64(inTimePeriod - 1) if tempValue2 < 0 { prevLoss -= tempValue2 } else { prevGain += tempValue2 } prevLoss /= float64(inTimePeriod) prevGain /= float64(inTimePeriod) tempValue1 = prevGain + prevLoss if !(((-(0.00000000000001)) < tempValue1) && (tempValue1 < (0.00000000000001))) { outReal[outIdx] = 100.0 * ((prevGain - prevLoss) / tempValue1) } else { outReal[outIdx] = 0.0 } outIdx++ } return outReal }
go
func Cmo(inReal []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inReal)) lookbackTotal := inTimePeriod startIdx := lookbackTotal outIdx := startIdx if inTimePeriod == 1 { copy(outReal, inReal) return outReal } today := startIdx - lookbackTotal prevValue := inReal[today] prevGain := 0.0 prevLoss := 0.0 today++ for i := inTimePeriod; i > 0; i-- { tempValue1 := inReal[today] tempValue2 := tempValue1 - prevValue prevValue = tempValue1 if tempValue2 < 0 { prevLoss -= tempValue2 } else { prevGain += tempValue2 } today++ } prevLoss /= float64(inTimePeriod) prevGain /= float64(inTimePeriod) if today > startIdx { tempValue1 := prevGain + prevLoss if !(((-(0.00000000000001)) < tempValue1) && (tempValue1 < (0.00000000000001))) { outReal[outIdx] = 100.0 * ((prevGain - prevLoss) / tempValue1) } else { outReal[outIdx] = 0.0 } outIdx++ } else { for today < startIdx { tempValue1 := inReal[today] tempValue2 := tempValue1 - prevValue prevValue = tempValue1 prevLoss *= float64(inTimePeriod - 1) prevGain *= float64(inTimePeriod - 1) if tempValue2 < 0 { prevLoss -= tempValue2 } else { prevGain += tempValue2 } prevLoss /= float64(inTimePeriod) prevGain /= float64(inTimePeriod) today++ } } for today < len(inReal) { tempValue1 := inReal[today] today++ tempValue2 := tempValue1 - prevValue prevValue = tempValue1 prevLoss *= float64(inTimePeriod - 1) prevGain *= float64(inTimePeriod - 1) if tempValue2 < 0 { prevLoss -= tempValue2 } else { prevGain += tempValue2 } prevLoss /= float64(inTimePeriod) prevGain /= float64(inTimePeriod) tempValue1 = prevGain + prevLoss if !(((-(0.00000000000001)) < tempValue1) && (tempValue1 < (0.00000000000001))) { outReal[outIdx] = 100.0 * ((prevGain - prevLoss) / tempValue1) } else { outReal[outIdx] = 0.0 } outIdx++ } return outReal }
[ "func", "Cmo", "(", "inReal", "[", "]", "float64", ",", "inTimePeriod", "int", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n\n", "lookbackTotal", ":=", "inTimePeriod", "\n", "startIdx", ":=", "lookbackTotal", "\n", "outIdx", ":=", "startIdx", "\n", "if", "inTimePeriod", "==", "1", "{", "copy", "(", "outReal", ",", "inReal", ")", "\n", "return", "outReal", "\n", "}", "\n", "today", ":=", "startIdx", "-", "lookbackTotal", "\n", "prevValue", ":=", "inReal", "[", "today", "]", "\n", "prevGain", ":=", "0.0", "\n", "prevLoss", ":=", "0.0", "\n", "today", "++", "\n", "for", "i", ":=", "inTimePeriod", ";", "i", ">", "0", ";", "i", "--", "{", "tempValue1", ":=", "inReal", "[", "today", "]", "\n", "tempValue2", ":=", "tempValue1", "-", "prevValue", "\n", "prevValue", "=", "tempValue1", "\n", "if", "tempValue2", "<", "0", "{", "prevLoss", "-=", "tempValue2", "\n", "}", "else", "{", "prevGain", "+=", "tempValue2", "\n", "}", "\n", "today", "++", "\n", "}", "\n", "prevLoss", "/=", "float64", "(", "inTimePeriod", ")", "\n", "prevGain", "/=", "float64", "(", "inTimePeriod", ")", "\n", "if", "today", ">", "startIdx", "{", "tempValue1", ":=", "prevGain", "+", "prevLoss", "\n", "if", "!", "(", "(", "(", "-", "(", "0.00000000000001", ")", ")", "<", "tempValue1", ")", "&&", "(", "tempValue1", "<", "(", "0.00000000000001", ")", ")", ")", "{", "outReal", "[", "outIdx", "]", "=", "100.0", "*", "(", "(", "prevGain", "-", "prevLoss", ")", "/", "tempValue1", ")", "\n", "}", "else", "{", "outReal", "[", "outIdx", "]", "=", "0.0", "\n", "}", "\n", "outIdx", "++", "\n", "}", "else", "{", "for", "today", "<", "startIdx", "{", "tempValue1", ":=", "inReal", "[", "today", "]", "\n", "tempValue2", ":=", "tempValue1", "-", "prevValue", "\n", "prevValue", "=", "tempValue1", "\n", "prevLoss", "*=", "float64", "(", "inTimePeriod", "-", "1", ")", "\n", "prevGain", "*=", "float64", "(", "inTimePeriod", "-", "1", ")", "\n", "if", "tempValue2", "<", "0", "{", "prevLoss", "-=", "tempValue2", "\n", "}", "else", "{", "prevGain", "+=", "tempValue2", "\n", "}", "\n", "prevLoss", "/=", "float64", "(", "inTimePeriod", ")", "\n", "prevGain", "/=", "float64", "(", "inTimePeriod", ")", "\n", "today", "++", "\n", "}", "\n", "}", "\n", "for", "today", "<", "len", "(", "inReal", ")", "{", "tempValue1", ":=", "inReal", "[", "today", "]", "\n", "today", "++", "\n", "tempValue2", ":=", "tempValue1", "-", "prevValue", "\n", "prevValue", "=", "tempValue1", "\n", "prevLoss", "*=", "float64", "(", "inTimePeriod", "-", "1", ")", "\n", "prevGain", "*=", "float64", "(", "inTimePeriod", "-", "1", ")", "\n", "if", "tempValue2", "<", "0", "{", "prevLoss", "-=", "tempValue2", "\n", "}", "else", "{", "prevGain", "+=", "tempValue2", "\n", "}", "\n", "prevLoss", "/=", "float64", "(", "inTimePeriod", ")", "\n", "prevGain", "/=", "float64", "(", "inTimePeriod", ")", "\n", "tempValue1", "=", "prevGain", "+", "prevLoss", "\n", "if", "!", "(", "(", "(", "-", "(", "0.00000000000001", ")", ")", "<", "tempValue1", ")", "&&", "(", "tempValue1", "<", "(", "0.00000000000001", ")", ")", ")", "{", "outReal", "[", "outIdx", "]", "=", "100.0", "*", "(", "(", "prevGain", "-", "prevLoss", ")", "/", "tempValue1", ")", "\n", "}", "else", "{", "outReal", "[", "outIdx", "]", "=", "0.0", "\n", "}", "\n", "outIdx", "++", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// Cmo - Chande Momentum Oscillator
[ "Cmo", "-", "Chande", "Momentum", "Oscillator" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L1741-L1818
10,359
markcheno/go-talib
talib.go
Cci
func Cci(inHigh []float64, inLow []float64, inClose []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inClose)) circBufferIdx := 0 lookbackTotal := inTimePeriod - 1 startIdx := lookbackTotal circBuffer := make([]float64, inTimePeriod) maxIdxCircBuffer := (inTimePeriod - 1) i := startIdx - lookbackTotal if inTimePeriod > 1 { for i < startIdx { circBuffer[circBufferIdx] = (inHigh[i] + inLow[i] + inClose[i]) / 3 i++ circBufferIdx++ if circBufferIdx > maxIdxCircBuffer { circBufferIdx = 0 } } } outIdx := inTimePeriod - 1 for i < len(inClose) { lastValue := (inHigh[i] + inLow[i] + inClose[i]) / 3 circBuffer[circBufferIdx] = lastValue theAverage := 0.0 for j := 0; j < inTimePeriod; j++ { theAverage += circBuffer[j] } theAverage /= float64(inTimePeriod) tempReal2 := 0.0 for j := 0; j < inTimePeriod; j++ { tempReal2 += math.Abs(circBuffer[j] - theAverage) } tempReal := lastValue - theAverage if (tempReal != 0.0) && (tempReal2 != 0.0) { outReal[outIdx] = tempReal / (0.015 * (tempReal2 / float64(inTimePeriod))) } else { outReal[outIdx] = 0.0 } { circBufferIdx++ if circBufferIdx > maxIdxCircBuffer { circBufferIdx = 0 } } outIdx++ i++ } return outReal }
go
func Cci(inHigh []float64, inLow []float64, inClose []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inClose)) circBufferIdx := 0 lookbackTotal := inTimePeriod - 1 startIdx := lookbackTotal circBuffer := make([]float64, inTimePeriod) maxIdxCircBuffer := (inTimePeriod - 1) i := startIdx - lookbackTotal if inTimePeriod > 1 { for i < startIdx { circBuffer[circBufferIdx] = (inHigh[i] + inLow[i] + inClose[i]) / 3 i++ circBufferIdx++ if circBufferIdx > maxIdxCircBuffer { circBufferIdx = 0 } } } outIdx := inTimePeriod - 1 for i < len(inClose) { lastValue := (inHigh[i] + inLow[i] + inClose[i]) / 3 circBuffer[circBufferIdx] = lastValue theAverage := 0.0 for j := 0; j < inTimePeriod; j++ { theAverage += circBuffer[j] } theAverage /= float64(inTimePeriod) tempReal2 := 0.0 for j := 0; j < inTimePeriod; j++ { tempReal2 += math.Abs(circBuffer[j] - theAverage) } tempReal := lastValue - theAverage if (tempReal != 0.0) && (tempReal2 != 0.0) { outReal[outIdx] = tempReal / (0.015 * (tempReal2 / float64(inTimePeriod))) } else { outReal[outIdx] = 0.0 } { circBufferIdx++ if circBufferIdx > maxIdxCircBuffer { circBufferIdx = 0 } } outIdx++ i++ } return outReal }
[ "func", "Cci", "(", "inHigh", "[", "]", "float64", ",", "inLow", "[", "]", "float64", ",", "inClose", "[", "]", "float64", ",", "inTimePeriod", "int", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inClose", ")", ")", "\n\n", "circBufferIdx", ":=", "0", "\n", "lookbackTotal", ":=", "inTimePeriod", "-", "1", "\n", "startIdx", ":=", "lookbackTotal", "\n", "circBuffer", ":=", "make", "(", "[", "]", "float64", ",", "inTimePeriod", ")", "\n", "maxIdxCircBuffer", ":=", "(", "inTimePeriod", "-", "1", ")", "\n", "i", ":=", "startIdx", "-", "lookbackTotal", "\n", "if", "inTimePeriod", ">", "1", "{", "for", "i", "<", "startIdx", "{", "circBuffer", "[", "circBufferIdx", "]", "=", "(", "inHigh", "[", "i", "]", "+", "inLow", "[", "i", "]", "+", "inClose", "[", "i", "]", ")", "/", "3", "\n", "i", "++", "\n", "circBufferIdx", "++", "\n", "if", "circBufferIdx", ">", "maxIdxCircBuffer", "{", "circBufferIdx", "=", "0", "\n", "}", "\n\n", "}", "\n", "}", "\n", "outIdx", ":=", "inTimePeriod", "-", "1", "\n", "for", "i", "<", "len", "(", "inClose", ")", "{", "lastValue", ":=", "(", "inHigh", "[", "i", "]", "+", "inLow", "[", "i", "]", "+", "inClose", "[", "i", "]", ")", "/", "3", "\n", "circBuffer", "[", "circBufferIdx", "]", "=", "lastValue", "\n", "theAverage", ":=", "0.0", "\n", "for", "j", ":=", "0", ";", "j", "<", "inTimePeriod", ";", "j", "++", "{", "theAverage", "+=", "circBuffer", "[", "j", "]", "\n", "}", "\n\n", "theAverage", "/=", "float64", "(", "inTimePeriod", ")", "\n", "tempReal2", ":=", "0.0", "\n", "for", "j", ":=", "0", ";", "j", "<", "inTimePeriod", ";", "j", "++", "{", "tempReal2", "+=", "math", ".", "Abs", "(", "circBuffer", "[", "j", "]", "-", "theAverage", ")", "\n", "}", "\n", "tempReal", ":=", "lastValue", "-", "theAverage", "\n", "if", "(", "tempReal", "!=", "0.0", ")", "&&", "(", "tempReal2", "!=", "0.0", ")", "{", "outReal", "[", "outIdx", "]", "=", "tempReal", "/", "(", "0.015", "*", "(", "tempReal2", "/", "float64", "(", "inTimePeriod", ")", ")", ")", "\n", "}", "else", "{", "outReal", "[", "outIdx", "]", "=", "0.0", "\n", "}", "\n", "{", "circBufferIdx", "++", "\n", "if", "circBufferIdx", ">", "maxIdxCircBuffer", "{", "circBufferIdx", "=", "0", "\n", "}", "\n", "}", "\n", "outIdx", "++", "\n", "i", "++", "\n", "}", "\n\n", "return", "outReal", "\n", "}" ]
// Cci - Commodity Channel Index
[ "Cci", "-", "Commodity", "Channel", "Index" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L1821-L1873
10,360
markcheno/go-talib
talib.go
MacdExt
func MacdExt(inReal []float64, inFastPeriod int, inFastMAType MaType, inSlowPeriod int, inSlowMAType MaType, inSignalPeriod int, inSignalMAType MaType) ([]float64, []float64, []float64) { lookbackLargest := 0 if inFastPeriod < inSlowPeriod { lookbackLargest = inSlowPeriod } else { lookbackLargest = inFastPeriod } lookbackTotal := (inSignalPeriod - 1) + (lookbackLargest - 1) outMACD := make([]float64, len(inReal)) outMACDSignal := make([]float64, len(inReal)) outMACDHist := make([]float64, len(inReal)) slowMABuffer := Ma(inReal, inSlowPeriod, inSlowMAType) fastMABuffer := Ma(inReal, inFastPeriod, inFastMAType) tempBuffer1 := make([]float64, len(inReal)) for i := 0; i < len(slowMABuffer); i++ { tempBuffer1[i] = fastMABuffer[i] - slowMABuffer[i] } tempBuffer2 := Ma(tempBuffer1, inSignalPeriod, inSignalMAType) for i := lookbackTotal; i < len(outMACDHist); i++ { outMACD[i] = tempBuffer1[i] outMACDSignal[i] = tempBuffer2[i] outMACDHist[i] = outMACD[i] - outMACDSignal[i] } return outMACD, outMACDSignal, outMACDHist }
go
func MacdExt(inReal []float64, inFastPeriod int, inFastMAType MaType, inSlowPeriod int, inSlowMAType MaType, inSignalPeriod int, inSignalMAType MaType) ([]float64, []float64, []float64) { lookbackLargest := 0 if inFastPeriod < inSlowPeriod { lookbackLargest = inSlowPeriod } else { lookbackLargest = inFastPeriod } lookbackTotal := (inSignalPeriod - 1) + (lookbackLargest - 1) outMACD := make([]float64, len(inReal)) outMACDSignal := make([]float64, len(inReal)) outMACDHist := make([]float64, len(inReal)) slowMABuffer := Ma(inReal, inSlowPeriod, inSlowMAType) fastMABuffer := Ma(inReal, inFastPeriod, inFastMAType) tempBuffer1 := make([]float64, len(inReal)) for i := 0; i < len(slowMABuffer); i++ { tempBuffer1[i] = fastMABuffer[i] - slowMABuffer[i] } tempBuffer2 := Ma(tempBuffer1, inSignalPeriod, inSignalMAType) for i := lookbackTotal; i < len(outMACDHist); i++ { outMACD[i] = tempBuffer1[i] outMACDSignal[i] = tempBuffer2[i] outMACDHist[i] = outMACD[i] - outMACDSignal[i] } return outMACD, outMACDSignal, outMACDHist }
[ "func", "MacdExt", "(", "inReal", "[", "]", "float64", ",", "inFastPeriod", "int", ",", "inFastMAType", "MaType", ",", "inSlowPeriod", "int", ",", "inSlowMAType", "MaType", ",", "inSignalPeriod", "int", ",", "inSignalMAType", "MaType", ")", "(", "[", "]", "float64", ",", "[", "]", "float64", ",", "[", "]", "float64", ")", "{", "lookbackLargest", ":=", "0", "\n", "if", "inFastPeriod", "<", "inSlowPeriod", "{", "lookbackLargest", "=", "inSlowPeriod", "\n", "}", "else", "{", "lookbackLargest", "=", "inFastPeriod", "\n", "}", "\n", "lookbackTotal", ":=", "(", "inSignalPeriod", "-", "1", ")", "+", "(", "lookbackLargest", "-", "1", ")", "\n\n", "outMACD", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n", "outMACDSignal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n", "outMACDHist", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n\n", "slowMABuffer", ":=", "Ma", "(", "inReal", ",", "inSlowPeriod", ",", "inSlowMAType", ")", "\n", "fastMABuffer", ":=", "Ma", "(", "inReal", ",", "inFastPeriod", ",", "inFastMAType", ")", "\n", "tempBuffer1", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "slowMABuffer", ")", ";", "i", "++", "{", "tempBuffer1", "[", "i", "]", "=", "fastMABuffer", "[", "i", "]", "-", "slowMABuffer", "[", "i", "]", "\n", "}", "\n", "tempBuffer2", ":=", "Ma", "(", "tempBuffer1", ",", "inSignalPeriod", ",", "inSignalMAType", ")", "\n\n", "for", "i", ":=", "lookbackTotal", ";", "i", "<", "len", "(", "outMACDHist", ")", ";", "i", "++", "{", "outMACD", "[", "i", "]", "=", "tempBuffer1", "[", "i", "]", "\n", "outMACDSignal", "[", "i", "]", "=", "tempBuffer2", "[", "i", "]", "\n", "outMACDHist", "[", "i", "]", "=", "outMACD", "[", "i", "]", "-", "outMACDSignal", "[", "i", "]", "\n", "}", "\n\n", "return", "outMACD", ",", "outMACDSignal", ",", "outMACDHist", "\n", "}" ]
// MacdExt - MACD with controllable MA type // unstable period ~= 100
[ "MacdExt", "-", "MACD", "with", "controllable", "MA", "type", "unstable", "period", "~", "=", "100" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L2029-L2059
10,361
markcheno/go-talib
talib.go
MinusDM
func MinusDM(inHigh []float64, inLow []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inHigh)) lookbackTotal := 1 if inTimePeriod > 1 { lookbackTotal = inTimePeriod - 1 } startIdx := lookbackTotal outIdx := startIdx today := startIdx prevHigh := 0.0 prevLow := 0.0 if inTimePeriod <= 1 { today = startIdx - 1 prevHigh = inHigh[today] prevLow = inLow[today] for today < len(inHigh)-1 { today++ tempReal := inHigh[today] diffP := tempReal - prevHigh prevHigh = tempReal tempReal = inLow[today] diffM := prevLow - tempReal prevLow = tempReal if (diffM > 0) && (diffP < diffM) { outReal[outIdx] = diffM } else { outReal[outIdx] = 0 } outIdx++ } return outReal } prevMinusDM := 0.0 today = startIdx - lookbackTotal prevHigh = inHigh[today] prevLow = inLow[today] i := inTimePeriod - 1 for i > 0 { i-- today++ tempReal := inHigh[today] diffP := tempReal - prevHigh prevHigh = tempReal tempReal = inLow[today] diffM := prevLow - tempReal prevLow = tempReal if (diffM > 0) && (diffP < diffM) { prevMinusDM += diffM } } i = 0 for i != 0 { i-- today++ tempReal := inHigh[today] diffP := tempReal - prevHigh prevHigh = tempReal tempReal = inLow[today] diffM := prevLow - tempReal prevLow = tempReal if (diffM > 0) && (diffP < diffM) { prevMinusDM = prevMinusDM - (prevMinusDM / float64(inTimePeriod)) + diffM } else { prevMinusDM = prevMinusDM - (prevMinusDM / float64(inTimePeriod)) } } outReal[startIdx] = prevMinusDM outIdx = startIdx + 1 for today < len(inHigh)-1 { today++ tempReal := inHigh[today] diffP := tempReal - prevHigh prevHigh = tempReal tempReal = inLow[today] diffM := prevLow - tempReal prevLow = tempReal if (diffM > 0) && (diffP < diffM) { prevMinusDM = prevMinusDM - (prevMinusDM / float64(inTimePeriod)) + diffM } else { prevMinusDM = prevMinusDM - (prevMinusDM / float64(inTimePeriod)) } outReal[outIdx] = prevMinusDM outIdx++ } return outReal }
go
func MinusDM(inHigh []float64, inLow []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inHigh)) lookbackTotal := 1 if inTimePeriod > 1 { lookbackTotal = inTimePeriod - 1 } startIdx := lookbackTotal outIdx := startIdx today := startIdx prevHigh := 0.0 prevLow := 0.0 if inTimePeriod <= 1 { today = startIdx - 1 prevHigh = inHigh[today] prevLow = inLow[today] for today < len(inHigh)-1 { today++ tempReal := inHigh[today] diffP := tempReal - prevHigh prevHigh = tempReal tempReal = inLow[today] diffM := prevLow - tempReal prevLow = tempReal if (diffM > 0) && (diffP < diffM) { outReal[outIdx] = diffM } else { outReal[outIdx] = 0 } outIdx++ } return outReal } prevMinusDM := 0.0 today = startIdx - lookbackTotal prevHigh = inHigh[today] prevLow = inLow[today] i := inTimePeriod - 1 for i > 0 { i-- today++ tempReal := inHigh[today] diffP := tempReal - prevHigh prevHigh = tempReal tempReal = inLow[today] diffM := prevLow - tempReal prevLow = tempReal if (diffM > 0) && (diffP < diffM) { prevMinusDM += diffM } } i = 0 for i != 0 { i-- today++ tempReal := inHigh[today] diffP := tempReal - prevHigh prevHigh = tempReal tempReal = inLow[today] diffM := prevLow - tempReal prevLow = tempReal if (diffM > 0) && (diffP < diffM) { prevMinusDM = prevMinusDM - (prevMinusDM / float64(inTimePeriod)) + diffM } else { prevMinusDM = prevMinusDM - (prevMinusDM / float64(inTimePeriod)) } } outReal[startIdx] = prevMinusDM outIdx = startIdx + 1 for today < len(inHigh)-1 { today++ tempReal := inHigh[today] diffP := tempReal - prevHigh prevHigh = tempReal tempReal = inLow[today] diffM := prevLow - tempReal prevLow = tempReal if (diffM > 0) && (diffP < diffM) { prevMinusDM = prevMinusDM - (prevMinusDM / float64(inTimePeriod)) + diffM } else { prevMinusDM = prevMinusDM - (prevMinusDM / float64(inTimePeriod)) } outReal[outIdx] = prevMinusDM outIdx++ } return outReal }
[ "func", "MinusDM", "(", "inHigh", "[", "]", "float64", ",", "inLow", "[", "]", "float64", ",", "inTimePeriod", "int", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inHigh", ")", ")", "\n\n", "lookbackTotal", ":=", "1", "\n", "if", "inTimePeriod", ">", "1", "{", "lookbackTotal", "=", "inTimePeriod", "-", "1", "\n", "}", "\n", "startIdx", ":=", "lookbackTotal", "\n", "outIdx", ":=", "startIdx", "\n", "today", ":=", "startIdx", "\n", "prevHigh", ":=", "0.0", "\n", "prevLow", ":=", "0.0", "\n", "if", "inTimePeriod", "<=", "1", "{", "today", "=", "startIdx", "-", "1", "\n", "prevHigh", "=", "inHigh", "[", "today", "]", "\n", "prevLow", "=", "inLow", "[", "today", "]", "\n", "for", "today", "<", "len", "(", "inHigh", ")", "-", "1", "{", "today", "++", "\n", "tempReal", ":=", "inHigh", "[", "today", "]", "\n", "diffP", ":=", "tempReal", "-", "prevHigh", "\n", "prevHigh", "=", "tempReal", "\n", "tempReal", "=", "inLow", "[", "today", "]", "\n", "diffM", ":=", "prevLow", "-", "tempReal", "\n", "prevLow", "=", "tempReal", "\n", "if", "(", "diffM", ">", "0", ")", "&&", "(", "diffP", "<", "diffM", ")", "{", "outReal", "[", "outIdx", "]", "=", "diffM", "\n", "}", "else", "{", "outReal", "[", "outIdx", "]", "=", "0", "\n", "}", "\n", "outIdx", "++", "\n", "}", "\n", "return", "outReal", "\n", "}", "\n", "prevMinusDM", ":=", "0.0", "\n", "today", "=", "startIdx", "-", "lookbackTotal", "\n", "prevHigh", "=", "inHigh", "[", "today", "]", "\n", "prevLow", "=", "inLow", "[", "today", "]", "\n", "i", ":=", "inTimePeriod", "-", "1", "\n", "for", "i", ">", "0", "{", "i", "--", "\n", "today", "++", "\n", "tempReal", ":=", "inHigh", "[", "today", "]", "\n", "diffP", ":=", "tempReal", "-", "prevHigh", "\n", "prevHigh", "=", "tempReal", "\n", "tempReal", "=", "inLow", "[", "today", "]", "\n", "diffM", ":=", "prevLow", "-", "tempReal", "\n", "prevLow", "=", "tempReal", "\n", "if", "(", "diffM", ">", "0", ")", "&&", "(", "diffP", "<", "diffM", ")", "{", "prevMinusDM", "+=", "diffM", "\n", "}", "\n", "}", "\n", "i", "=", "0", "\n", "for", "i", "!=", "0", "{", "i", "--", "\n", "today", "++", "\n", "tempReal", ":=", "inHigh", "[", "today", "]", "\n", "diffP", ":=", "tempReal", "-", "prevHigh", "\n", "prevHigh", "=", "tempReal", "\n", "tempReal", "=", "inLow", "[", "today", "]", "\n", "diffM", ":=", "prevLow", "-", "tempReal", "\n", "prevLow", "=", "tempReal", "\n", "if", "(", "diffM", ">", "0", ")", "&&", "(", "diffP", "<", "diffM", ")", "{", "prevMinusDM", "=", "prevMinusDM", "-", "(", "prevMinusDM", "/", "float64", "(", "inTimePeriod", ")", ")", "+", "diffM", "\n", "}", "else", "{", "prevMinusDM", "=", "prevMinusDM", "-", "(", "prevMinusDM", "/", "float64", "(", "inTimePeriod", ")", ")", "\n", "}", "\n", "}", "\n", "outReal", "[", "startIdx", "]", "=", "prevMinusDM", "\n", "outIdx", "=", "startIdx", "+", "1", "\n", "for", "today", "<", "len", "(", "inHigh", ")", "-", "1", "{", "today", "++", "\n", "tempReal", ":=", "inHigh", "[", "today", "]", "\n", "diffP", ":=", "tempReal", "-", "prevHigh", "\n", "prevHigh", "=", "tempReal", "\n", "tempReal", "=", "inLow", "[", "today", "]", "\n", "diffM", ":=", "prevLow", "-", "tempReal", "\n", "prevLow", "=", "tempReal", "\n", "if", "(", "diffM", ">", "0", ")", "&&", "(", "diffP", "<", "diffM", ")", "{", "prevMinusDM", "=", "prevMinusDM", "-", "(", "prevMinusDM", "/", "float64", "(", "inTimePeriod", ")", ")", "+", "diffM", "\n", "}", "else", "{", "prevMinusDM", "=", "prevMinusDM", "-", "(", "prevMinusDM", "/", "float64", "(", "inTimePeriod", ")", ")", "\n", "}", "\n", "outReal", "[", "outIdx", "]", "=", "prevMinusDM", "\n", "outIdx", "++", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// MinusDM - Minus Directional Movement
[ "MinusDM", "-", "Minus", "Directional", "Movement" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L2225-L2312
10,362
markcheno/go-talib
talib.go
Mom
func Mom(inReal []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inReal)) inIdx, outIdx, trailingIdx := inTimePeriod, inTimePeriod, 0 for inIdx < len(inReal) { outReal[outIdx] = inReal[inIdx] - inReal[trailingIdx] inIdx, outIdx, trailingIdx = inIdx+1, outIdx+1, trailingIdx+1 } return outReal }
go
func Mom(inReal []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inReal)) inIdx, outIdx, trailingIdx := inTimePeriod, inTimePeriod, 0 for inIdx < len(inReal) { outReal[outIdx] = inReal[inIdx] - inReal[trailingIdx] inIdx, outIdx, trailingIdx = inIdx+1, outIdx+1, trailingIdx+1 } return outReal }
[ "func", "Mom", "(", "inReal", "[", "]", "float64", ",", "inTimePeriod", "int", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n\n", "inIdx", ",", "outIdx", ",", "trailingIdx", ":=", "inTimePeriod", ",", "inTimePeriod", ",", "0", "\n", "for", "inIdx", "<", "len", "(", "inReal", ")", "{", "outReal", "[", "outIdx", "]", "=", "inReal", "[", "inIdx", "]", "-", "inReal", "[", "trailingIdx", "]", "\n", "inIdx", ",", "outIdx", ",", "trailingIdx", "=", "inIdx", "+", "1", ",", "outIdx", "+", "1", ",", "trailingIdx", "+", "1", "\n", "}", "\n\n", "return", "outReal", "\n", "}" ]
// Mom - Momentum
[ "Mom", "-", "Momentum" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L2425-L2436
10,363
markcheno/go-talib
talib.go
Ppo
func Ppo(inReal []float64, inFastPeriod int, inSlowPeriod int, inMAType MaType) []float64 { if inSlowPeriod < inFastPeriod { inSlowPeriod, inFastPeriod = inFastPeriod, inSlowPeriod } tempBuffer := Ma(inReal, inFastPeriod, inMAType) outReal := Ma(inReal, inSlowPeriod, inMAType) for i := inSlowPeriod - 1; i < len(inReal); i++ { tempReal := outReal[i] if !(((-(0.00000000000001)) < tempReal) && (tempReal < (0.00000000000001))) { outReal[i] = ((tempBuffer[i] - tempReal) / tempReal) * 100.0 } else { outReal[i] = 0.0 } } return outReal }
go
func Ppo(inReal []float64, inFastPeriod int, inSlowPeriod int, inMAType MaType) []float64 { if inSlowPeriod < inFastPeriod { inSlowPeriod, inFastPeriod = inFastPeriod, inSlowPeriod } tempBuffer := Ma(inReal, inFastPeriod, inMAType) outReal := Ma(inReal, inSlowPeriod, inMAType) for i := inSlowPeriod - 1; i < len(inReal); i++ { tempReal := outReal[i] if !(((-(0.00000000000001)) < tempReal) && (tempReal < (0.00000000000001))) { outReal[i] = ((tempBuffer[i] - tempReal) / tempReal) * 100.0 } else { outReal[i] = 0.0 } } return outReal }
[ "func", "Ppo", "(", "inReal", "[", "]", "float64", ",", "inFastPeriod", "int", ",", "inSlowPeriod", "int", ",", "inMAType", "MaType", ")", "[", "]", "float64", "{", "if", "inSlowPeriod", "<", "inFastPeriod", "{", "inSlowPeriod", ",", "inFastPeriod", "=", "inFastPeriod", ",", "inSlowPeriod", "\n", "}", "\n", "tempBuffer", ":=", "Ma", "(", "inReal", ",", "inFastPeriod", ",", "inMAType", ")", "\n", "outReal", ":=", "Ma", "(", "inReal", ",", "inSlowPeriod", ",", "inMAType", ")", "\n\n", "for", "i", ":=", "inSlowPeriod", "-", "1", ";", "i", "<", "len", "(", "inReal", ")", ";", "i", "++", "{", "tempReal", ":=", "outReal", "[", "i", "]", "\n", "if", "!", "(", "(", "(", "-", "(", "0.00000000000001", ")", ")", "<", "tempReal", ")", "&&", "(", "tempReal", "<", "(", "0.00000000000001", ")", ")", ")", "{", "outReal", "[", "i", "]", "=", "(", "(", "tempBuffer", "[", "i", "]", "-", "tempReal", ")", "/", "tempReal", ")", "*", "100.0", "\n", "}", "else", "{", "outReal", "[", "i", "]", "=", "0.0", "\n", "}", "\n", "}", "\n\n", "return", "outReal", "\n", "}" ]
// Ppo - Percentage Price Oscillator
[ "Ppo", "-", "Percentage", "Price", "Oscillator" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L2686-L2704
10,364
markcheno/go-talib
talib.go
Rsi
func Rsi(inReal []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inReal)) if inTimePeriod < 2 { return outReal } // variable declarations tempValue1 := 0.0 tempValue2 := 0.0 outIdx := inTimePeriod today := 0 prevValue := inReal[today] prevGain := 0.0 prevLoss := 0.0 today++ for i := inTimePeriod; i > 0; i-- { tempValue1 = inReal[today] today++ tempValue2 = tempValue1 - prevValue prevValue = tempValue1 if tempValue2 < 0 { prevLoss -= tempValue2 } else { prevGain += tempValue2 } } prevLoss /= float64(inTimePeriod) prevGain /= float64(inTimePeriod) if today > 0 { tempValue1 = prevGain + prevLoss if !((-0.00000000000001 < tempValue1) && (tempValue1 < 0.00000000000001)) { outReal[outIdx] = 100.0 * (prevGain / tempValue1) } else { outReal[outIdx] = 0.0 } outIdx++ } else { for today < 0 { tempValue1 = inReal[today] tempValue2 = tempValue1 - prevValue prevValue = tempValue1 prevLoss *= float64(inTimePeriod - 1) prevGain *= float64(inTimePeriod - 1) if tempValue2 < 0 { prevLoss -= tempValue2 } else { prevGain += tempValue2 } prevLoss /= float64(inTimePeriod) prevGain /= float64(inTimePeriod) today++ } } for today < len(inReal) { tempValue1 = inReal[today] today++ tempValue2 = tempValue1 - prevValue prevValue = tempValue1 prevLoss *= float64(inTimePeriod - 1) prevGain *= float64(inTimePeriod - 1) if tempValue2 < 0 { prevLoss -= tempValue2 } else { prevGain += tempValue2 } prevLoss /= float64(inTimePeriod) prevGain /= float64(inTimePeriod) tempValue1 = prevGain + prevLoss if !((-0.00000000000001 < tempValue1) && (tempValue1 < 0.00000000000001)) { outReal[outIdx] = 100.0 * (prevGain / tempValue1) } else { outReal[outIdx] = 0.0 } outIdx++ } return outReal }
go
func Rsi(inReal []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inReal)) if inTimePeriod < 2 { return outReal } // variable declarations tempValue1 := 0.0 tempValue2 := 0.0 outIdx := inTimePeriod today := 0 prevValue := inReal[today] prevGain := 0.0 prevLoss := 0.0 today++ for i := inTimePeriod; i > 0; i-- { tempValue1 = inReal[today] today++ tempValue2 = tempValue1 - prevValue prevValue = tempValue1 if tempValue2 < 0 { prevLoss -= tempValue2 } else { prevGain += tempValue2 } } prevLoss /= float64(inTimePeriod) prevGain /= float64(inTimePeriod) if today > 0 { tempValue1 = prevGain + prevLoss if !((-0.00000000000001 < tempValue1) && (tempValue1 < 0.00000000000001)) { outReal[outIdx] = 100.0 * (prevGain / tempValue1) } else { outReal[outIdx] = 0.0 } outIdx++ } else { for today < 0 { tempValue1 = inReal[today] tempValue2 = tempValue1 - prevValue prevValue = tempValue1 prevLoss *= float64(inTimePeriod - 1) prevGain *= float64(inTimePeriod - 1) if tempValue2 < 0 { prevLoss -= tempValue2 } else { prevGain += tempValue2 } prevLoss /= float64(inTimePeriod) prevGain /= float64(inTimePeriod) today++ } } for today < len(inReal) { tempValue1 = inReal[today] today++ tempValue2 = tempValue1 - prevValue prevValue = tempValue1 prevLoss *= float64(inTimePeriod - 1) prevGain *= float64(inTimePeriod - 1) if tempValue2 < 0 { prevLoss -= tempValue2 } else { prevGain += tempValue2 } prevLoss /= float64(inTimePeriod) prevGain /= float64(inTimePeriod) tempValue1 = prevGain + prevLoss if !((-0.00000000000001 < tempValue1) && (tempValue1 < 0.00000000000001)) { outReal[outIdx] = 100.0 * (prevGain / tempValue1) } else { outReal[outIdx] = 0.0 } outIdx++ } return outReal }
[ "func", "Rsi", "(", "inReal", "[", "]", "float64", ",", "inTimePeriod", "int", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n\n", "if", "inTimePeriod", "<", "2", "{", "return", "outReal", "\n", "}", "\n\n", "// variable declarations", "tempValue1", ":=", "0.0", "\n", "tempValue2", ":=", "0.0", "\n", "outIdx", ":=", "inTimePeriod", "\n", "today", ":=", "0", "\n", "prevValue", ":=", "inReal", "[", "today", "]", "\n", "prevGain", ":=", "0.0", "\n", "prevLoss", ":=", "0.0", "\n", "today", "++", "\n\n", "for", "i", ":=", "inTimePeriod", ";", "i", ">", "0", ";", "i", "--", "{", "tempValue1", "=", "inReal", "[", "today", "]", "\n", "today", "++", "\n", "tempValue2", "=", "tempValue1", "-", "prevValue", "\n", "prevValue", "=", "tempValue1", "\n", "if", "tempValue2", "<", "0", "{", "prevLoss", "-=", "tempValue2", "\n", "}", "else", "{", "prevGain", "+=", "tempValue2", "\n", "}", "\n", "}", "\n\n", "prevLoss", "/=", "float64", "(", "inTimePeriod", ")", "\n", "prevGain", "/=", "float64", "(", "inTimePeriod", ")", "\n\n", "if", "today", ">", "0", "{", "tempValue1", "=", "prevGain", "+", "prevLoss", "\n", "if", "!", "(", "(", "-", "0.00000000000001", "<", "tempValue1", ")", "&&", "(", "tempValue1", "<", "0.00000000000001", ")", ")", "{", "outReal", "[", "outIdx", "]", "=", "100.0", "*", "(", "prevGain", "/", "tempValue1", ")", "\n", "}", "else", "{", "outReal", "[", "outIdx", "]", "=", "0.0", "\n", "}", "\n", "outIdx", "++", "\n\n", "}", "else", "{", "for", "today", "<", "0", "{", "tempValue1", "=", "inReal", "[", "today", "]", "\n", "tempValue2", "=", "tempValue1", "-", "prevValue", "\n", "prevValue", "=", "tempValue1", "\n", "prevLoss", "*=", "float64", "(", "inTimePeriod", "-", "1", ")", "\n", "prevGain", "*=", "float64", "(", "inTimePeriod", "-", "1", ")", "\n", "if", "tempValue2", "<", "0", "{", "prevLoss", "-=", "tempValue2", "\n", "}", "else", "{", "prevGain", "+=", "tempValue2", "\n", "}", "\n", "prevLoss", "/=", "float64", "(", "inTimePeriod", ")", "\n", "prevGain", "/=", "float64", "(", "inTimePeriod", ")", "\n", "today", "++", "\n", "}", "\n", "}", "\n\n", "for", "today", "<", "len", "(", "inReal", ")", "{", "tempValue1", "=", "inReal", "[", "today", "]", "\n", "today", "++", "\n", "tempValue2", "=", "tempValue1", "-", "prevValue", "\n", "prevValue", "=", "tempValue1", "\n", "prevLoss", "*=", "float64", "(", "inTimePeriod", "-", "1", ")", "\n", "prevGain", "*=", "float64", "(", "inTimePeriod", "-", "1", ")", "\n", "if", "tempValue2", "<", "0", "{", "prevLoss", "-=", "tempValue2", "\n", "}", "else", "{", "prevGain", "+=", "tempValue2", "\n", "}", "\n", "prevLoss", "/=", "float64", "(", "inTimePeriod", ")", "\n", "prevGain", "/=", "float64", "(", "inTimePeriod", ")", "\n", "tempValue1", "=", "prevGain", "+", "prevLoss", "\n", "if", "!", "(", "(", "-", "0.00000000000001", "<", "tempValue1", ")", "&&", "(", "tempValue1", "<", "0.00000000000001", ")", ")", "{", "outReal", "[", "outIdx", "]", "=", "100.0", "*", "(", "prevGain", "/", "tempValue1", ")", "\n", "}", "else", "{", "outReal", "[", "outIdx", "]", "=", "0.0", "\n", "}", "\n", "outIdx", "++", "\n", "}", "\n\n", "return", "outReal", "\n", "}" ]
// Rsi - Relative strength index
[ "Rsi", "-", "Relative", "strength", "index" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L2807-L2894
10,365
markcheno/go-talib
talib.go
Stoch
func Stoch(inHigh []float64, inLow []float64, inClose []float64, inFastKPeriod int, inSlowKPeriod int, inSlowKMAType MaType, inSlowDPeriod int, inSlowDMAType MaType) ([]float64, []float64) { outSlowK := make([]float64, len(inClose)) outSlowD := make([]float64, len(inClose)) lookbackK := inFastKPeriod - 1 lookbackKSlow := inSlowKPeriod - 1 lookbackDSlow := inSlowDPeriod - 1 lookbackTotal := lookbackK + lookbackDSlow + lookbackKSlow startIdx := lookbackTotal outIdx := 0 trailingIdx := startIdx - lookbackTotal today := trailingIdx + lookbackK lowestIdx, highestIdx := -1, -1 diff, highest, lowest := 0.0, 0.0, 0.0 tempBuffer := make([]float64, len(inClose)-today+1) for today < len(inClose) { tmp := inLow[today] if lowestIdx < trailingIdx { lowestIdx = trailingIdx lowest = inLow[lowestIdx] i := lowestIdx + 1 for i <= today { tmp := inLow[i] if tmp < lowest { lowestIdx = i lowest = tmp } i++ } diff = (highest - lowest) / 100.0 } else if tmp <= lowest { lowestIdx = today lowest = tmp diff = (highest - lowest) / 100.0 } tmp = inHigh[today] if highestIdx < trailingIdx { highestIdx = trailingIdx highest = inHigh[highestIdx] i := highestIdx + 1 for i <= today { tmp := inHigh[i] if tmp > highest { highestIdx = i highest = tmp } i++ } diff = (highest - lowest) / 100.0 } else if tmp >= highest { highestIdx = today highest = tmp diff = (highest - lowest) / 100.0 } if diff != 0.0 { tempBuffer[outIdx] = (inClose[today] - lowest) / diff } else { tempBuffer[outIdx] = 0.0 } outIdx++ trailingIdx++ today++ } tempBuffer1 := Ma(tempBuffer, inSlowKPeriod, inSlowKMAType) tempBuffer2 := Ma(tempBuffer1, inSlowDPeriod, inSlowDMAType) //for i, j := lookbackK, lookbackTotal; j < len(inClose); i, j = i+1, j+1 { for i, j := lookbackDSlow+lookbackKSlow, lookbackTotal; j < len(inClose); i, j = i+1, j+1 { outSlowK[j] = tempBuffer1[i] outSlowD[j] = tempBuffer2[i] } return outSlowK, outSlowD }
go
func Stoch(inHigh []float64, inLow []float64, inClose []float64, inFastKPeriod int, inSlowKPeriod int, inSlowKMAType MaType, inSlowDPeriod int, inSlowDMAType MaType) ([]float64, []float64) { outSlowK := make([]float64, len(inClose)) outSlowD := make([]float64, len(inClose)) lookbackK := inFastKPeriod - 1 lookbackKSlow := inSlowKPeriod - 1 lookbackDSlow := inSlowDPeriod - 1 lookbackTotal := lookbackK + lookbackDSlow + lookbackKSlow startIdx := lookbackTotal outIdx := 0 trailingIdx := startIdx - lookbackTotal today := trailingIdx + lookbackK lowestIdx, highestIdx := -1, -1 diff, highest, lowest := 0.0, 0.0, 0.0 tempBuffer := make([]float64, len(inClose)-today+1) for today < len(inClose) { tmp := inLow[today] if lowestIdx < trailingIdx { lowestIdx = trailingIdx lowest = inLow[lowestIdx] i := lowestIdx + 1 for i <= today { tmp := inLow[i] if tmp < lowest { lowestIdx = i lowest = tmp } i++ } diff = (highest - lowest) / 100.0 } else if tmp <= lowest { lowestIdx = today lowest = tmp diff = (highest - lowest) / 100.0 } tmp = inHigh[today] if highestIdx < trailingIdx { highestIdx = trailingIdx highest = inHigh[highestIdx] i := highestIdx + 1 for i <= today { tmp := inHigh[i] if tmp > highest { highestIdx = i highest = tmp } i++ } diff = (highest - lowest) / 100.0 } else if tmp >= highest { highestIdx = today highest = tmp diff = (highest - lowest) / 100.0 } if diff != 0.0 { tempBuffer[outIdx] = (inClose[today] - lowest) / diff } else { tempBuffer[outIdx] = 0.0 } outIdx++ trailingIdx++ today++ } tempBuffer1 := Ma(tempBuffer, inSlowKPeriod, inSlowKMAType) tempBuffer2 := Ma(tempBuffer1, inSlowDPeriod, inSlowDMAType) //for i, j := lookbackK, lookbackTotal; j < len(inClose); i, j = i+1, j+1 { for i, j := lookbackDSlow+lookbackKSlow, lookbackTotal; j < len(inClose); i, j = i+1, j+1 { outSlowK[j] = tempBuffer1[i] outSlowD[j] = tempBuffer2[i] } return outSlowK, outSlowD }
[ "func", "Stoch", "(", "inHigh", "[", "]", "float64", ",", "inLow", "[", "]", "float64", ",", "inClose", "[", "]", "float64", ",", "inFastKPeriod", "int", ",", "inSlowKPeriod", "int", ",", "inSlowKMAType", "MaType", ",", "inSlowDPeriod", "int", ",", "inSlowDMAType", "MaType", ")", "(", "[", "]", "float64", ",", "[", "]", "float64", ")", "{", "outSlowK", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inClose", ")", ")", "\n", "outSlowD", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inClose", ")", ")", "\n\n", "lookbackK", ":=", "inFastKPeriod", "-", "1", "\n", "lookbackKSlow", ":=", "inSlowKPeriod", "-", "1", "\n", "lookbackDSlow", ":=", "inSlowDPeriod", "-", "1", "\n", "lookbackTotal", ":=", "lookbackK", "+", "lookbackDSlow", "+", "lookbackKSlow", "\n", "startIdx", ":=", "lookbackTotal", "\n", "outIdx", ":=", "0", "\n", "trailingIdx", ":=", "startIdx", "-", "lookbackTotal", "\n", "today", ":=", "trailingIdx", "+", "lookbackK", "\n", "lowestIdx", ",", "highestIdx", ":=", "-", "1", ",", "-", "1", "\n", "diff", ",", "highest", ",", "lowest", ":=", "0.0", ",", "0.0", ",", "0.0", "\n", "tempBuffer", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inClose", ")", "-", "today", "+", "1", ")", "\n", "for", "today", "<", "len", "(", "inClose", ")", "{", "tmp", ":=", "inLow", "[", "today", "]", "\n", "if", "lowestIdx", "<", "trailingIdx", "{", "lowestIdx", "=", "trailingIdx", "\n", "lowest", "=", "inLow", "[", "lowestIdx", "]", "\n", "i", ":=", "lowestIdx", "+", "1", "\n", "for", "i", "<=", "today", "{", "tmp", ":=", "inLow", "[", "i", "]", "\n", "if", "tmp", "<", "lowest", "{", "lowestIdx", "=", "i", "\n", "lowest", "=", "tmp", "\n", "}", "\n", "i", "++", "\n", "}", "\n", "diff", "=", "(", "highest", "-", "lowest", ")", "/", "100.0", "\n", "}", "else", "if", "tmp", "<=", "lowest", "{", "lowestIdx", "=", "today", "\n", "lowest", "=", "tmp", "\n", "diff", "=", "(", "highest", "-", "lowest", ")", "/", "100.0", "\n", "}", "\n", "tmp", "=", "inHigh", "[", "today", "]", "\n", "if", "highestIdx", "<", "trailingIdx", "{", "highestIdx", "=", "trailingIdx", "\n", "highest", "=", "inHigh", "[", "highestIdx", "]", "\n", "i", ":=", "highestIdx", "+", "1", "\n", "for", "i", "<=", "today", "{", "tmp", ":=", "inHigh", "[", "i", "]", "\n", "if", "tmp", ">", "highest", "{", "highestIdx", "=", "i", "\n", "highest", "=", "tmp", "\n", "}", "\n", "i", "++", "\n", "}", "\n", "diff", "=", "(", "highest", "-", "lowest", ")", "/", "100.0", "\n", "}", "else", "if", "tmp", ">=", "highest", "{", "highestIdx", "=", "today", "\n", "highest", "=", "tmp", "\n", "diff", "=", "(", "highest", "-", "lowest", ")", "/", "100.0", "\n", "}", "\n", "if", "diff", "!=", "0.0", "{", "tempBuffer", "[", "outIdx", "]", "=", "(", "inClose", "[", "today", "]", "-", "lowest", ")", "/", "diff", "\n", "}", "else", "{", "tempBuffer", "[", "outIdx", "]", "=", "0.0", "\n", "}", "\n", "outIdx", "++", "\n", "trailingIdx", "++", "\n", "today", "++", "\n", "}", "\n\n", "tempBuffer1", ":=", "Ma", "(", "tempBuffer", ",", "inSlowKPeriod", ",", "inSlowKMAType", ")", "\n", "tempBuffer2", ":=", "Ma", "(", "tempBuffer1", ",", "inSlowDPeriod", ",", "inSlowDMAType", ")", "\n", "//for i, j := lookbackK, lookbackTotal; j < len(inClose); i, j = i+1, j+1 {", "for", "i", ",", "j", ":=", "lookbackDSlow", "+", "lookbackKSlow", ",", "lookbackTotal", ";", "j", "<", "len", "(", "inClose", ")", ";", "i", ",", "j", "=", "i", "+", "1", ",", "j", "+", "1", "{", "outSlowK", "[", "j", "]", "=", "tempBuffer1", "[", "i", "]", "\n", "outSlowD", "[", "j", "]", "=", "tempBuffer2", "[", "i", "]", "\n", "}", "\n\n", "return", "outSlowK", ",", "outSlowD", "\n", "}" ]
// Stoch - Stochastic
[ "Stoch", "-", "Stochastic" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L2897-L2972
10,366
markcheno/go-talib
talib.go
StochF
func StochF(inHigh []float64, inLow []float64, inClose []float64, inFastKPeriod int, inFastDPeriod int, inFastDMAType MaType) ([]float64, []float64) { outFastK := make([]float64, len(inClose)) outFastD := make([]float64, len(inClose)) lookbackK := inFastKPeriod - 1 lookbackFastD := inFastDPeriod - 1 lookbackTotal := lookbackK + lookbackFastD startIdx := lookbackTotal outIdx := 0 trailingIdx := startIdx - lookbackTotal today := trailingIdx + lookbackK lowestIdx, highestIdx := -1, -1 diff, highest, lowest := 0.0, 0.0, 0.0 tempBuffer := make([]float64, (len(inClose) - today + 1)) for today < len(inClose) { tmp := inLow[today] if lowestIdx < trailingIdx { lowestIdx = trailingIdx lowest = inLow[lowestIdx] i := lowestIdx i++ for i <= today { tmp = inLow[i] if tmp < lowest { lowestIdx = i lowest = tmp } i++ } diff = (highest - lowest) / 100.0 } else if tmp <= lowest { lowestIdx = today lowest = tmp diff = (highest - lowest) / 100.0 } tmp = inHigh[today] if highestIdx < trailingIdx { highestIdx = trailingIdx highest = inHigh[highestIdx] i := highestIdx i++ for i <= today { tmp = inHigh[i] if tmp > highest { highestIdx = i highest = tmp } i++ } diff = (highest - lowest) / 100.0 } else if tmp >= highest { highestIdx = today highest = tmp diff = (highest - lowest) / 100.0 } if diff != 0.0 { tempBuffer[outIdx] = (inClose[today] - lowest) / diff } else { tempBuffer[outIdx] = 0.0 } outIdx++ trailingIdx++ today++ } tempBuffer1 := Ma(tempBuffer, inFastDPeriod, inFastDMAType) for i, j := lookbackFastD, lookbackTotal; j < len(inClose); i, j = i+1, j+1 { outFastK[j] = tempBuffer[i] outFastD[j] = tempBuffer1[i] } return outFastK, outFastD }
go
func StochF(inHigh []float64, inLow []float64, inClose []float64, inFastKPeriod int, inFastDPeriod int, inFastDMAType MaType) ([]float64, []float64) { outFastK := make([]float64, len(inClose)) outFastD := make([]float64, len(inClose)) lookbackK := inFastKPeriod - 1 lookbackFastD := inFastDPeriod - 1 lookbackTotal := lookbackK + lookbackFastD startIdx := lookbackTotal outIdx := 0 trailingIdx := startIdx - lookbackTotal today := trailingIdx + lookbackK lowestIdx, highestIdx := -1, -1 diff, highest, lowest := 0.0, 0.0, 0.0 tempBuffer := make([]float64, (len(inClose) - today + 1)) for today < len(inClose) { tmp := inLow[today] if lowestIdx < trailingIdx { lowestIdx = trailingIdx lowest = inLow[lowestIdx] i := lowestIdx i++ for i <= today { tmp = inLow[i] if tmp < lowest { lowestIdx = i lowest = tmp } i++ } diff = (highest - lowest) / 100.0 } else if tmp <= lowest { lowestIdx = today lowest = tmp diff = (highest - lowest) / 100.0 } tmp = inHigh[today] if highestIdx < trailingIdx { highestIdx = trailingIdx highest = inHigh[highestIdx] i := highestIdx i++ for i <= today { tmp = inHigh[i] if tmp > highest { highestIdx = i highest = tmp } i++ } diff = (highest - lowest) / 100.0 } else if tmp >= highest { highestIdx = today highest = tmp diff = (highest - lowest) / 100.0 } if diff != 0.0 { tempBuffer[outIdx] = (inClose[today] - lowest) / diff } else { tempBuffer[outIdx] = 0.0 } outIdx++ trailingIdx++ today++ } tempBuffer1 := Ma(tempBuffer, inFastDPeriod, inFastDMAType) for i, j := lookbackFastD, lookbackTotal; j < len(inClose); i, j = i+1, j+1 { outFastK[j] = tempBuffer[i] outFastD[j] = tempBuffer1[i] } return outFastK, outFastD }
[ "func", "StochF", "(", "inHigh", "[", "]", "float64", ",", "inLow", "[", "]", "float64", ",", "inClose", "[", "]", "float64", ",", "inFastKPeriod", "int", ",", "inFastDPeriod", "int", ",", "inFastDMAType", "MaType", ")", "(", "[", "]", "float64", ",", "[", "]", "float64", ")", "{", "outFastK", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inClose", ")", ")", "\n", "outFastD", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inClose", ")", ")", "\n\n", "lookbackK", ":=", "inFastKPeriod", "-", "1", "\n", "lookbackFastD", ":=", "inFastDPeriod", "-", "1", "\n", "lookbackTotal", ":=", "lookbackK", "+", "lookbackFastD", "\n", "startIdx", ":=", "lookbackTotal", "\n", "outIdx", ":=", "0", "\n", "trailingIdx", ":=", "startIdx", "-", "lookbackTotal", "\n", "today", ":=", "trailingIdx", "+", "lookbackK", "\n", "lowestIdx", ",", "highestIdx", ":=", "-", "1", ",", "-", "1", "\n", "diff", ",", "highest", ",", "lowest", ":=", "0.0", ",", "0.0", ",", "0.0", "\n", "tempBuffer", ":=", "make", "(", "[", "]", "float64", ",", "(", "len", "(", "inClose", ")", "-", "today", "+", "1", ")", ")", "\n\n", "for", "today", "<", "len", "(", "inClose", ")", "{", "tmp", ":=", "inLow", "[", "today", "]", "\n", "if", "lowestIdx", "<", "trailingIdx", "{", "lowestIdx", "=", "trailingIdx", "\n", "lowest", "=", "inLow", "[", "lowestIdx", "]", "\n", "i", ":=", "lowestIdx", "\n", "i", "++", "\n", "for", "i", "<=", "today", "{", "tmp", "=", "inLow", "[", "i", "]", "\n", "if", "tmp", "<", "lowest", "{", "lowestIdx", "=", "i", "\n", "lowest", "=", "tmp", "\n", "}", "\n", "i", "++", "\n", "}", "\n", "diff", "=", "(", "highest", "-", "lowest", ")", "/", "100.0", "\n", "}", "else", "if", "tmp", "<=", "lowest", "{", "lowestIdx", "=", "today", "\n", "lowest", "=", "tmp", "\n", "diff", "=", "(", "highest", "-", "lowest", ")", "/", "100.0", "\n", "}", "\n", "tmp", "=", "inHigh", "[", "today", "]", "\n", "if", "highestIdx", "<", "trailingIdx", "{", "highestIdx", "=", "trailingIdx", "\n", "highest", "=", "inHigh", "[", "highestIdx", "]", "\n", "i", ":=", "highestIdx", "\n", "i", "++", "\n", "for", "i", "<=", "today", "{", "tmp", "=", "inHigh", "[", "i", "]", "\n", "if", "tmp", ">", "highest", "{", "highestIdx", "=", "i", "\n", "highest", "=", "tmp", "\n", "}", "\n", "i", "++", "\n", "}", "\n", "diff", "=", "(", "highest", "-", "lowest", ")", "/", "100.0", "\n", "}", "else", "if", "tmp", ">=", "highest", "{", "highestIdx", "=", "today", "\n", "highest", "=", "tmp", "\n", "diff", "=", "(", "highest", "-", "lowest", ")", "/", "100.0", "\n", "}", "\n", "if", "diff", "!=", "0.0", "{", "tempBuffer", "[", "outIdx", "]", "=", "(", "inClose", "[", "today", "]", "-", "lowest", ")", "/", "diff", "\n\n", "}", "else", "{", "tempBuffer", "[", "outIdx", "]", "=", "0.0", "\n", "}", "\n", "outIdx", "++", "\n", "trailingIdx", "++", "\n", "today", "++", "\n", "}", "\n\n", "tempBuffer1", ":=", "Ma", "(", "tempBuffer", ",", "inFastDPeriod", ",", "inFastDMAType", ")", "\n", "for", "i", ",", "j", ":=", "lookbackFastD", ",", "lookbackTotal", ";", "j", "<", "len", "(", "inClose", ")", ";", "i", ",", "j", "=", "i", "+", "1", ",", "j", "+", "1", "{", "outFastK", "[", "j", "]", "=", "tempBuffer", "[", "i", "]", "\n", "outFastD", "[", "j", "]", "=", "tempBuffer1", "[", "i", "]", "\n", "}", "\n\n", "return", "outFastK", ",", "outFastD", "\n", "}" ]
// StochF - Stochastic Fast
[ "StochF", "-", "Stochastic", "Fast" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L2975-L3050
10,367
markcheno/go-talib
talib.go
StochRsi
func StochRsi(inReal []float64, inTimePeriod int, inFastKPeriod int, inFastDPeriod int, inFastDMAType MaType) ([]float64, []float64) { outFastK := make([]float64, len(inReal)) outFastD := make([]float64, len(inReal)) lookbackSTOCHF := (inFastKPeriod - 1) + (inFastDPeriod - 1) lookbackTotal := inTimePeriod + lookbackSTOCHF startIdx := lookbackTotal tempRSIBuffer := Rsi(inReal, inTimePeriod) tempk, tempd := StochF(tempRSIBuffer, tempRSIBuffer, tempRSIBuffer, inFastKPeriod, inFastDPeriod, inFastDMAType) for i := startIdx; i < len(inReal); i++ { outFastK[i] = tempk[i] outFastD[i] = tempd[i] } return outFastK, outFastD }
go
func StochRsi(inReal []float64, inTimePeriod int, inFastKPeriod int, inFastDPeriod int, inFastDMAType MaType) ([]float64, []float64) { outFastK := make([]float64, len(inReal)) outFastD := make([]float64, len(inReal)) lookbackSTOCHF := (inFastKPeriod - 1) + (inFastDPeriod - 1) lookbackTotal := inTimePeriod + lookbackSTOCHF startIdx := lookbackTotal tempRSIBuffer := Rsi(inReal, inTimePeriod) tempk, tempd := StochF(tempRSIBuffer, tempRSIBuffer, tempRSIBuffer, inFastKPeriod, inFastDPeriod, inFastDMAType) for i := startIdx; i < len(inReal); i++ { outFastK[i] = tempk[i] outFastD[i] = tempd[i] } return outFastK, outFastD }
[ "func", "StochRsi", "(", "inReal", "[", "]", "float64", ",", "inTimePeriod", "int", ",", "inFastKPeriod", "int", ",", "inFastDPeriod", "int", ",", "inFastDMAType", "MaType", ")", "(", "[", "]", "float64", ",", "[", "]", "float64", ")", "{", "outFastK", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n", "outFastD", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n\n", "lookbackSTOCHF", ":=", "(", "inFastKPeriod", "-", "1", ")", "+", "(", "inFastDPeriod", "-", "1", ")", "\n", "lookbackTotal", ":=", "inTimePeriod", "+", "lookbackSTOCHF", "\n", "startIdx", ":=", "lookbackTotal", "\n", "tempRSIBuffer", ":=", "Rsi", "(", "inReal", ",", "inTimePeriod", ")", "\n", "tempk", ",", "tempd", ":=", "StochF", "(", "tempRSIBuffer", ",", "tempRSIBuffer", ",", "tempRSIBuffer", ",", "inFastKPeriod", ",", "inFastDPeriod", ",", "inFastDMAType", ")", "\n\n", "for", "i", ":=", "startIdx", ";", "i", "<", "len", "(", "inReal", ")", ";", "i", "++", "{", "outFastK", "[", "i", "]", "=", "tempk", "[", "i", "]", "\n", "outFastD", "[", "i", "]", "=", "tempd", "[", "i", "]", "\n", "}", "\n\n", "return", "outFastK", ",", "outFastD", "\n", "}" ]
// StochRsi - Stochastic Relative Strength Index
[ "StochRsi", "-", "Stochastic", "Relative", "Strength", "Index" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L3053-L3070
10,368
markcheno/go-talib
talib.go
WillR
func WillR(inHigh []float64, inLow []float64, inClose []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inClose)) nbInitialElementNeeded := (inTimePeriod - 1) diff := 0.0 outIdx := inTimePeriod - 1 startIdx := inTimePeriod - 1 today := startIdx trailingIdx := startIdx - nbInitialElementNeeded highestIdx := -1 lowestIdx := -1 highest := 0.0 lowest := 0.0 i := 0 for today < len(inClose) { tmp := inLow[today] if lowestIdx < trailingIdx { lowestIdx = trailingIdx lowest = inLow[lowestIdx] i = lowestIdx i++ for i <= today { tmp = inLow[i] if tmp < lowest { lowestIdx = i lowest = tmp } i++ } diff = (highest - lowest) / (-100.0) } else if tmp <= lowest { lowestIdx = today lowest = tmp diff = (highest - lowest) / (-100.0) } tmp = inHigh[today] if highestIdx < trailingIdx { highestIdx = trailingIdx highest = inHigh[highestIdx] i = highestIdx i++ for i <= today { tmp = inHigh[i] if tmp > highest { highestIdx = i highest = tmp } i++ } diff = (highest - lowest) / (-100.0) } else if tmp >= highest { highestIdx = today highest = tmp diff = (highest - lowest) / (-100.0) } if diff != 0.0 { outReal[outIdx] = (highest - inClose[today]) / diff } else { outReal[outIdx] = 0.0 } outIdx++ trailingIdx++ today++ } return outReal }
go
func WillR(inHigh []float64, inLow []float64, inClose []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inClose)) nbInitialElementNeeded := (inTimePeriod - 1) diff := 0.0 outIdx := inTimePeriod - 1 startIdx := inTimePeriod - 1 today := startIdx trailingIdx := startIdx - nbInitialElementNeeded highestIdx := -1 lowestIdx := -1 highest := 0.0 lowest := 0.0 i := 0 for today < len(inClose) { tmp := inLow[today] if lowestIdx < trailingIdx { lowestIdx = trailingIdx lowest = inLow[lowestIdx] i = lowestIdx i++ for i <= today { tmp = inLow[i] if tmp < lowest { lowestIdx = i lowest = tmp } i++ } diff = (highest - lowest) / (-100.0) } else if tmp <= lowest { lowestIdx = today lowest = tmp diff = (highest - lowest) / (-100.0) } tmp = inHigh[today] if highestIdx < trailingIdx { highestIdx = trailingIdx highest = inHigh[highestIdx] i = highestIdx i++ for i <= today { tmp = inHigh[i] if tmp > highest { highestIdx = i highest = tmp } i++ } diff = (highest - lowest) / (-100.0) } else if tmp >= highest { highestIdx = today highest = tmp diff = (highest - lowest) / (-100.0) } if diff != 0.0 { outReal[outIdx] = (highest - inClose[today]) / diff } else { outReal[outIdx] = 0.0 } outIdx++ trailingIdx++ today++ } return outReal }
[ "func", "WillR", "(", "inHigh", "[", "]", "float64", ",", "inLow", "[", "]", "float64", ",", "inClose", "[", "]", "float64", ",", "inTimePeriod", "int", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inClose", ")", ")", "\n", "nbInitialElementNeeded", ":=", "(", "inTimePeriod", "-", "1", ")", "\n", "diff", ":=", "0.0", "\n", "outIdx", ":=", "inTimePeriod", "-", "1", "\n", "startIdx", ":=", "inTimePeriod", "-", "1", "\n", "today", ":=", "startIdx", "\n", "trailingIdx", ":=", "startIdx", "-", "nbInitialElementNeeded", "\n", "highestIdx", ":=", "-", "1", "\n", "lowestIdx", ":=", "-", "1", "\n", "highest", ":=", "0.0", "\n", "lowest", ":=", "0.0", "\n", "i", ":=", "0", "\n", "for", "today", "<", "len", "(", "inClose", ")", "{", "tmp", ":=", "inLow", "[", "today", "]", "\n", "if", "lowestIdx", "<", "trailingIdx", "{", "lowestIdx", "=", "trailingIdx", "\n", "lowest", "=", "inLow", "[", "lowestIdx", "]", "\n", "i", "=", "lowestIdx", "\n", "i", "++", "\n", "for", "i", "<=", "today", "{", "tmp", "=", "inLow", "[", "i", "]", "\n", "if", "tmp", "<", "lowest", "{", "lowestIdx", "=", "i", "\n", "lowest", "=", "tmp", "\n", "}", "\n", "i", "++", "\n", "}", "\n", "diff", "=", "(", "highest", "-", "lowest", ")", "/", "(", "-", "100.0", ")", "\n", "}", "else", "if", "tmp", "<=", "lowest", "{", "lowestIdx", "=", "today", "\n", "lowest", "=", "tmp", "\n", "diff", "=", "(", "highest", "-", "lowest", ")", "/", "(", "-", "100.0", ")", "\n", "}", "\n", "tmp", "=", "inHigh", "[", "today", "]", "\n", "if", "highestIdx", "<", "trailingIdx", "{", "highestIdx", "=", "trailingIdx", "\n", "highest", "=", "inHigh", "[", "highestIdx", "]", "\n", "i", "=", "highestIdx", "\n", "i", "++", "\n", "for", "i", "<=", "today", "{", "tmp", "=", "inHigh", "[", "i", "]", "\n", "if", "tmp", ">", "highest", "{", "highestIdx", "=", "i", "\n", "highest", "=", "tmp", "\n", "}", "\n", "i", "++", "\n", "}", "\n", "diff", "=", "(", "highest", "-", "lowest", ")", "/", "(", "-", "100.0", ")", "\n", "}", "else", "if", "tmp", ">=", "highest", "{", "highestIdx", "=", "today", "\n", "highest", "=", "tmp", "\n", "diff", "=", "(", "highest", "-", "lowest", ")", "/", "(", "-", "100.0", ")", "\n", "}", "\n", "if", "diff", "!=", "0.0", "{", "outReal", "[", "outIdx", "]", "=", "(", "highest", "-", "inClose", "[", "today", "]", ")", "/", "diff", "\n", "}", "else", "{", "outReal", "[", "outIdx", "]", "=", "0.0", "\n", "}", "\n", "outIdx", "++", "\n", "trailingIdx", "++", "\n", "today", "++", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// WillR - Williams' %R
[ "WillR", "-", "Williams", "%R" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L3339-L3404
10,369
markcheno/go-talib
talib.go
Obv
func Obv(inReal []float64, inVolume []float64) []float64 { outReal := make([]float64, len(inReal)) startIdx := 0 prevOBV := inVolume[startIdx] prevReal := inReal[startIdx] outIdx := 0 for i := startIdx; i < len(inReal); i++ { tempReal := inReal[i] if tempReal > prevReal { prevOBV += inVolume[i] } else if tempReal < prevReal { prevOBV -= inVolume[i] } outReal[outIdx] = prevOBV prevReal = tempReal outIdx++ } return outReal }
go
func Obv(inReal []float64, inVolume []float64) []float64 { outReal := make([]float64, len(inReal)) startIdx := 0 prevOBV := inVolume[startIdx] prevReal := inReal[startIdx] outIdx := 0 for i := startIdx; i < len(inReal); i++ { tempReal := inReal[i] if tempReal > prevReal { prevOBV += inVolume[i] } else if tempReal < prevReal { prevOBV -= inVolume[i] } outReal[outIdx] = prevOBV prevReal = tempReal outIdx++ } return outReal }
[ "func", "Obv", "(", "inReal", "[", "]", "float64", ",", "inVolume", "[", "]", "float64", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n", "startIdx", ":=", "0", "\n", "prevOBV", ":=", "inVolume", "[", "startIdx", "]", "\n", "prevReal", ":=", "inReal", "[", "startIdx", "]", "\n", "outIdx", ":=", "0", "\n", "for", "i", ":=", "startIdx", ";", "i", "<", "len", "(", "inReal", ")", ";", "i", "++", "{", "tempReal", ":=", "inReal", "[", "i", "]", "\n", "if", "tempReal", ">", "prevReal", "{", "prevOBV", "+=", "inVolume", "[", "i", "]", "\n", "}", "else", "if", "tempReal", "<", "prevReal", "{", "prevOBV", "-=", "inVolume", "[", "i", "]", "\n", "}", "\n", "outReal", "[", "outIdx", "]", "=", "prevOBV", "\n", "prevReal", "=", "tempReal", "\n", "outIdx", "++", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// Obv - On Balance Volume
[ "Obv", "-", "On", "Balance", "Volume" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L3501-L3520
10,370
markcheno/go-talib
talib.go
TRange
func TRange(inHigh []float64, inLow []float64, inClose []float64) []float64 { outReal := make([]float64, len(inClose)) startIdx := 1 outIdx := startIdx today := startIdx for today < len(inClose) { tempLT := inLow[today] tempHT := inHigh[today] tempCY := inClose[today-1] greatest := tempHT - tempLT val2 := math.Abs(tempCY - tempHT) if val2 > greatest { greatest = val2 } val3 := math.Abs(tempCY - tempLT) if val3 > greatest { greatest = val3 } outReal[outIdx] = greatest outIdx++ today++ } return outReal }
go
func TRange(inHigh []float64, inLow []float64, inClose []float64) []float64 { outReal := make([]float64, len(inClose)) startIdx := 1 outIdx := startIdx today := startIdx for today < len(inClose) { tempLT := inLow[today] tempHT := inHigh[today] tempCY := inClose[today-1] greatest := tempHT - tempLT val2 := math.Abs(tempCY - tempHT) if val2 > greatest { greatest = val2 } val3 := math.Abs(tempCY - tempLT) if val3 > greatest { greatest = val3 } outReal[outIdx] = greatest outIdx++ today++ } return outReal }
[ "func", "TRange", "(", "inHigh", "[", "]", "float64", ",", "inLow", "[", "]", "float64", ",", "inClose", "[", "]", "float64", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inClose", ")", ")", "\n\n", "startIdx", ":=", "1", "\n", "outIdx", ":=", "startIdx", "\n", "today", ":=", "startIdx", "\n", "for", "today", "<", "len", "(", "inClose", ")", "{", "tempLT", ":=", "inLow", "[", "today", "]", "\n", "tempHT", ":=", "inHigh", "[", "today", "]", "\n", "tempCY", ":=", "inClose", "[", "today", "-", "1", "]", "\n", "greatest", ":=", "tempHT", "-", "tempLT", "\n", "val2", ":=", "math", ".", "Abs", "(", "tempCY", "-", "tempHT", ")", "\n", "if", "val2", ">", "greatest", "{", "greatest", "=", "val2", "\n", "}", "\n", "val3", ":=", "math", ".", "Abs", "(", "tempCY", "-", "tempLT", ")", "\n", "if", "val3", ">", "greatest", "{", "greatest", "=", "val3", "\n", "}", "\n", "outReal", "[", "outIdx", "]", "=", "greatest", "\n", "outIdx", "++", "\n", "today", "++", "\n", "}", "\n\n", "return", "outReal", "\n", "}" ]
// TRange - True Range
[ "TRange", "-", "True", "Range" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L3603-L3629
10,371
markcheno/go-talib
talib.go
LinearReg
func LinearReg(inReal []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inReal)) inTimePeriodF := float64(inTimePeriod) lookbackTotal := inTimePeriod startIdx := lookbackTotal outIdx := startIdx - 1 today := startIdx - 1 sumX := inTimePeriodF * (inTimePeriodF - 1) * 0.5 sumXSqr := inTimePeriodF * (inTimePeriodF - 1) * (2*inTimePeriodF - 1) / 6 divisor := sumX*sumX - inTimePeriodF*sumXSqr //initialize values of sumY and sumXY over first (inTimePeriod) input values sumXY := 0.0 sumY := 0.0 i := inTimePeriod for i != 0 { i-- tempValue1 := inReal[today-i] sumY += tempValue1 sumXY += float64(i) * tempValue1 } for today < len(inReal) { //sumX and sumXY are already available for first output value if today > startIdx-1 { tempValue2 := inReal[today-inTimePeriod] sumXY += sumY - inTimePeriodF*tempValue2 sumY += inReal[today] - tempValue2 } m := (inTimePeriodF*sumXY - sumX*sumY) / divisor b := (sumY - m*sumX) / inTimePeriodF outReal[outIdx] = b + m*(inTimePeriodF-1) outIdx++ today++ } return outReal }
go
func LinearReg(inReal []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inReal)) inTimePeriodF := float64(inTimePeriod) lookbackTotal := inTimePeriod startIdx := lookbackTotal outIdx := startIdx - 1 today := startIdx - 1 sumX := inTimePeriodF * (inTimePeriodF - 1) * 0.5 sumXSqr := inTimePeriodF * (inTimePeriodF - 1) * (2*inTimePeriodF - 1) / 6 divisor := sumX*sumX - inTimePeriodF*sumXSqr //initialize values of sumY and sumXY over first (inTimePeriod) input values sumXY := 0.0 sumY := 0.0 i := inTimePeriod for i != 0 { i-- tempValue1 := inReal[today-i] sumY += tempValue1 sumXY += float64(i) * tempValue1 } for today < len(inReal) { //sumX and sumXY are already available for first output value if today > startIdx-1 { tempValue2 := inReal[today-inTimePeriod] sumXY += sumY - inTimePeriodF*tempValue2 sumY += inReal[today] - tempValue2 } m := (inTimePeriodF*sumXY - sumX*sumY) / divisor b := (sumY - m*sumX) / inTimePeriodF outReal[outIdx] = b + m*(inTimePeriodF-1) outIdx++ today++ } return outReal }
[ "func", "LinearReg", "(", "inReal", "[", "]", "float64", ",", "inTimePeriod", "int", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n\n", "inTimePeriodF", ":=", "float64", "(", "inTimePeriod", ")", "\n", "lookbackTotal", ":=", "inTimePeriod", "\n", "startIdx", ":=", "lookbackTotal", "\n", "outIdx", ":=", "startIdx", "-", "1", "\n", "today", ":=", "startIdx", "-", "1", "\n", "sumX", ":=", "inTimePeriodF", "*", "(", "inTimePeriodF", "-", "1", ")", "*", "0.5", "\n", "sumXSqr", ":=", "inTimePeriodF", "*", "(", "inTimePeriodF", "-", "1", ")", "*", "(", "2", "*", "inTimePeriodF", "-", "1", ")", "/", "6", "\n", "divisor", ":=", "sumX", "*", "sumX", "-", "inTimePeriodF", "*", "sumXSqr", "\n", "//initialize values of sumY and sumXY over first (inTimePeriod) input values", "sumXY", ":=", "0.0", "\n", "sumY", ":=", "0.0", "\n", "i", ":=", "inTimePeriod", "\n", "for", "i", "!=", "0", "{", "i", "--", "\n", "tempValue1", ":=", "inReal", "[", "today", "-", "i", "]", "\n", "sumY", "+=", "tempValue1", "\n", "sumXY", "+=", "float64", "(", "i", ")", "*", "tempValue1", "\n", "}", "\n", "for", "today", "<", "len", "(", "inReal", ")", "{", "//sumX and sumXY are already available for first output value", "if", "today", ">", "startIdx", "-", "1", "{", "tempValue2", ":=", "inReal", "[", "today", "-", "inTimePeriod", "]", "\n", "sumXY", "+=", "sumY", "-", "inTimePeriodF", "*", "tempValue2", "\n", "sumY", "+=", "inReal", "[", "today", "]", "-", "tempValue2", "\n", "}", "\n", "m", ":=", "(", "inTimePeriodF", "*", "sumXY", "-", "sumX", "*", "sumY", ")", "/", "divisor", "\n", "b", ":=", "(", "sumY", "-", "m", "*", "sumX", ")", "/", "inTimePeriodF", "\n", "outReal", "[", "outIdx", "]", "=", "b", "+", "m", "*", "(", "inTimePeriodF", "-", "1", ")", "\n", "outIdx", "++", "\n", "today", "++", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// LinearReg - Linear Regression
[ "LinearReg", "-", "Linear", "Regression" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L5108-L5144
10,372
markcheno/go-talib
talib.go
StdDev
func StdDev(inReal []float64, inTimePeriod int, inNbDev float64) []float64 { outReal := Var(inReal, inTimePeriod) if inNbDev != 1.0 { for i := 0; i < len(inReal); i++ { tempReal := outReal[i] if !(tempReal < 0.00000000000001) { outReal[i] = math.Sqrt(tempReal) * inNbDev } else { outReal[i] = 0.0 } } } else { for i := 0; i < len(inReal); i++ { tempReal := outReal[i] if !(tempReal < 0.00000000000001) { outReal[i] = math.Sqrt(tempReal) } else { outReal[i] = 0.0 } } } return outReal }
go
func StdDev(inReal []float64, inTimePeriod int, inNbDev float64) []float64 { outReal := Var(inReal, inTimePeriod) if inNbDev != 1.0 { for i := 0; i < len(inReal); i++ { tempReal := outReal[i] if !(tempReal < 0.00000000000001) { outReal[i] = math.Sqrt(tempReal) * inNbDev } else { outReal[i] = 0.0 } } } else { for i := 0; i < len(inReal); i++ { tempReal := outReal[i] if !(tempReal < 0.00000000000001) { outReal[i] = math.Sqrt(tempReal) } else { outReal[i] = 0.0 } } } return outReal }
[ "func", "StdDev", "(", "inReal", "[", "]", "float64", ",", "inTimePeriod", "int", ",", "inNbDev", "float64", ")", "[", "]", "float64", "{", "outReal", ":=", "Var", "(", "inReal", ",", "inTimePeriod", ")", "\n\n", "if", "inNbDev", "!=", "1.0", "{", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "inReal", ")", ";", "i", "++", "{", "tempReal", ":=", "outReal", "[", "i", "]", "\n", "if", "!", "(", "tempReal", "<", "0.00000000000001", ")", "{", "outReal", "[", "i", "]", "=", "math", ".", "Sqrt", "(", "tempReal", ")", "*", "inNbDev", "\n", "}", "else", "{", "outReal", "[", "i", "]", "=", "0.0", "\n", "}", "\n", "}", "\n", "}", "else", "{", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "inReal", ")", ";", "i", "++", "{", "tempReal", ":=", "outReal", "[", "i", "]", "\n", "if", "!", "(", "tempReal", "<", "0.00000000000001", ")", "{", "outReal", "[", "i", "]", "=", "math", ".", "Sqrt", "(", "tempReal", ")", "\n", "}", "else", "{", "outReal", "[", "i", "]", "=", "0.0", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// StdDev - Standard Deviation
[ "StdDev", "-", "Standard", "Deviation" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L5260-L5284
10,373
markcheno/go-talib
talib.go
Var
func Var(inReal []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inReal)) nbInitialElementNeeded := inTimePeriod - 1 startIdx := nbInitialElementNeeded periodTotal1 := 0.0 periodTotal2 := 0.0 trailingIdx := startIdx - nbInitialElementNeeded i := trailingIdx if inTimePeriod > 1 { for i < startIdx { tempReal := inReal[i] periodTotal1 += tempReal tempReal *= tempReal periodTotal2 += tempReal i++ } } outIdx := startIdx for ok := true; ok; { tempReal := inReal[i] periodTotal1 += tempReal tempReal *= tempReal periodTotal2 += tempReal meanValue1 := periodTotal1 / float64(inTimePeriod) meanValue2 := periodTotal2 / float64(inTimePeriod) tempReal = inReal[trailingIdx] periodTotal1 -= tempReal tempReal *= tempReal periodTotal2 -= tempReal outReal[outIdx] = meanValue2 - meanValue1*meanValue1 i++ trailingIdx++ outIdx++ ok = i < len(inReal) } return outReal }
go
func Var(inReal []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inReal)) nbInitialElementNeeded := inTimePeriod - 1 startIdx := nbInitialElementNeeded periodTotal1 := 0.0 periodTotal2 := 0.0 trailingIdx := startIdx - nbInitialElementNeeded i := trailingIdx if inTimePeriod > 1 { for i < startIdx { tempReal := inReal[i] periodTotal1 += tempReal tempReal *= tempReal periodTotal2 += tempReal i++ } } outIdx := startIdx for ok := true; ok; { tempReal := inReal[i] periodTotal1 += tempReal tempReal *= tempReal periodTotal2 += tempReal meanValue1 := periodTotal1 / float64(inTimePeriod) meanValue2 := periodTotal2 / float64(inTimePeriod) tempReal = inReal[trailingIdx] periodTotal1 -= tempReal tempReal *= tempReal periodTotal2 -= tempReal outReal[outIdx] = meanValue2 - meanValue1*meanValue1 i++ trailingIdx++ outIdx++ ok = i < len(inReal) } return outReal }
[ "func", "Var", "(", "inReal", "[", "]", "float64", ",", "inTimePeriod", "int", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n\n", "nbInitialElementNeeded", ":=", "inTimePeriod", "-", "1", "\n", "startIdx", ":=", "nbInitialElementNeeded", "\n", "periodTotal1", ":=", "0.0", "\n", "periodTotal2", ":=", "0.0", "\n", "trailingIdx", ":=", "startIdx", "-", "nbInitialElementNeeded", "\n", "i", ":=", "trailingIdx", "\n", "if", "inTimePeriod", ">", "1", "{", "for", "i", "<", "startIdx", "{", "tempReal", ":=", "inReal", "[", "i", "]", "\n", "periodTotal1", "+=", "tempReal", "\n", "tempReal", "*=", "tempReal", "\n", "periodTotal2", "+=", "tempReal", "\n", "i", "++", "\n", "}", "\n", "}", "\n", "outIdx", ":=", "startIdx", "\n", "for", "ok", ":=", "true", ";", "ok", ";", "{", "tempReal", ":=", "inReal", "[", "i", "]", "\n", "periodTotal1", "+=", "tempReal", "\n", "tempReal", "*=", "tempReal", "\n", "periodTotal2", "+=", "tempReal", "\n", "meanValue1", ":=", "periodTotal1", "/", "float64", "(", "inTimePeriod", ")", "\n", "meanValue2", ":=", "periodTotal2", "/", "float64", "(", "inTimePeriod", ")", "\n", "tempReal", "=", "inReal", "[", "trailingIdx", "]", "\n", "periodTotal1", "-=", "tempReal", "\n", "tempReal", "*=", "tempReal", "\n", "periodTotal2", "-=", "tempReal", "\n", "outReal", "[", "outIdx", "]", "=", "meanValue2", "-", "meanValue1", "*", "meanValue1", "\n", "i", "++", "\n", "trailingIdx", "++", "\n", "outIdx", "++", "\n", "ok", "=", "i", "<", "len", "(", "inReal", ")", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// Var - Variance
[ "Var", "-", "Variance" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L5326-L5364
10,374
markcheno/go-talib
talib.go
Asin
func Asin(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Asin(inReal[i]) } return outReal }
go
func Asin(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Asin(inReal[i]) } return outReal }
[ "func", "Asin", "(", "inReal", "[", "]", "float64", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "inReal", ")", ";", "i", "++", "{", "outReal", "[", "i", "]", "=", "math", ".", "Asin", "(", "inReal", "[", "i", "]", ")", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// Asin - Vector Trigonometric ASIN
[ "Asin", "-", "Vector", "Trigonometric", "ASIN" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L5378-L5384
10,375
markcheno/go-talib
talib.go
Atan
func Atan(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Atan(inReal[i]) } return outReal }
go
func Atan(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Atan(inReal[i]) } return outReal }
[ "func", "Atan", "(", "inReal", "[", "]", "float64", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "inReal", ")", ";", "i", "++", "{", "outReal", "[", "i", "]", "=", "math", ".", "Atan", "(", "inReal", "[", "i", "]", ")", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// Atan - Vector Trigonometric ATAN
[ "Atan", "-", "Vector", "Trigonometric", "ATAN" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L5387-L5393
10,376
markcheno/go-talib
talib.go
Ceil
func Ceil(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Ceil(inReal[i]) } return outReal }
go
func Ceil(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Ceil(inReal[i]) } return outReal }
[ "func", "Ceil", "(", "inReal", "[", "]", "float64", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "inReal", ")", ";", "i", "++", "{", "outReal", "[", "i", "]", "=", "math", ".", "Ceil", "(", "inReal", "[", "i", "]", ")", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// Ceil - Vector CEIL
[ "Ceil", "-", "Vector", "CEIL" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L5396-L5402
10,377
markcheno/go-talib
talib.go
Cos
func Cos(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Cos(inReal[i]) } return outReal }
go
func Cos(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Cos(inReal[i]) } return outReal }
[ "func", "Cos", "(", "inReal", "[", "]", "float64", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "inReal", ")", ";", "i", "++", "{", "outReal", "[", "i", "]", "=", "math", ".", "Cos", "(", "inReal", "[", "i", "]", ")", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// Cos - Vector Trigonometric COS
[ "Cos", "-", "Vector", "Trigonometric", "COS" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L5405-L5411
10,378
markcheno/go-talib
talib.go
Cosh
func Cosh(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Cosh(inReal[i]) } return outReal }
go
func Cosh(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Cosh(inReal[i]) } return outReal }
[ "func", "Cosh", "(", "inReal", "[", "]", "float64", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "inReal", ")", ";", "i", "++", "{", "outReal", "[", "i", "]", "=", "math", ".", "Cosh", "(", "inReal", "[", "i", "]", ")", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// Cosh - Vector Trigonometric COSH
[ "Cosh", "-", "Vector", "Trigonometric", "COSH" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L5414-L5420
10,379
markcheno/go-talib
talib.go
Exp
func Exp(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Exp(inReal[i]) } return outReal }
go
func Exp(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Exp(inReal[i]) } return outReal }
[ "func", "Exp", "(", "inReal", "[", "]", "float64", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "inReal", ")", ";", "i", "++", "{", "outReal", "[", "i", "]", "=", "math", ".", "Exp", "(", "inReal", "[", "i", "]", ")", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// Exp - Vector atrithmetic EXP
[ "Exp", "-", "Vector", "atrithmetic", "EXP" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L5423-L5429
10,380
markcheno/go-talib
talib.go
Floor
func Floor(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Floor(inReal[i]) } return outReal }
go
func Floor(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Floor(inReal[i]) } return outReal }
[ "func", "Floor", "(", "inReal", "[", "]", "float64", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "inReal", ")", ";", "i", "++", "{", "outReal", "[", "i", "]", "=", "math", ".", "Floor", "(", "inReal", "[", "i", "]", ")", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// Floor - Vector FLOOR
[ "Floor", "-", "Vector", "FLOOR" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L5432-L5438
10,381
markcheno/go-talib
talib.go
Ln
func Ln(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Log(inReal[i]) } return outReal }
go
func Ln(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Log(inReal[i]) } return outReal }
[ "func", "Ln", "(", "inReal", "[", "]", "float64", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "inReal", ")", ";", "i", "++", "{", "outReal", "[", "i", "]", "=", "math", ".", "Log", "(", "inReal", "[", "i", "]", ")", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// Ln - Vector natural log LN
[ "Ln", "-", "Vector", "natural", "log", "LN" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L5441-L5447
10,382
markcheno/go-talib
talib.go
Log10
func Log10(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Log10(inReal[i]) } return outReal }
go
func Log10(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Log10(inReal[i]) } return outReal }
[ "func", "Log10", "(", "inReal", "[", "]", "float64", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "inReal", ")", ";", "i", "++", "{", "outReal", "[", "i", "]", "=", "math", ".", "Log10", "(", "inReal", "[", "i", "]", ")", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// Log10 - Vector LOG10
[ "Log10", "-", "Vector", "LOG10" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L5450-L5456
10,383
markcheno/go-talib
talib.go
Sin
func Sin(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Sin(inReal[i]) } return outReal }
go
func Sin(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Sin(inReal[i]) } return outReal }
[ "func", "Sin", "(", "inReal", "[", "]", "float64", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "inReal", ")", ";", "i", "++", "{", "outReal", "[", "i", "]", "=", "math", ".", "Sin", "(", "inReal", "[", "i", "]", ")", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// Sin - Vector Trigonometric SIN
[ "Sin", "-", "Vector", "Trigonometric", "SIN" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L5459-L5465
10,384
markcheno/go-talib
talib.go
Sinh
func Sinh(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Sinh(inReal[i]) } return outReal }
go
func Sinh(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Sinh(inReal[i]) } return outReal }
[ "func", "Sinh", "(", "inReal", "[", "]", "float64", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "inReal", ")", ";", "i", "++", "{", "outReal", "[", "i", "]", "=", "math", ".", "Sinh", "(", "inReal", "[", "i", "]", ")", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// Sinh - Vector Trigonometric SINH
[ "Sinh", "-", "Vector", "Trigonometric", "SINH" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L5468-L5474
10,385
markcheno/go-talib
talib.go
Sqrt
func Sqrt(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Sqrt(inReal[i]) } return outReal }
go
func Sqrt(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Sqrt(inReal[i]) } return outReal }
[ "func", "Sqrt", "(", "inReal", "[", "]", "float64", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "inReal", ")", ";", "i", "++", "{", "outReal", "[", "i", "]", "=", "math", ".", "Sqrt", "(", "inReal", "[", "i", "]", ")", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// Sqrt - Vector SQRT
[ "Sqrt", "-", "Vector", "SQRT" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L5477-L5483
10,386
markcheno/go-talib
talib.go
Tan
func Tan(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Tan(inReal[i]) } return outReal }
go
func Tan(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Tan(inReal[i]) } return outReal }
[ "func", "Tan", "(", "inReal", "[", "]", "float64", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "inReal", ")", ";", "i", "++", "{", "outReal", "[", "i", "]", "=", "math", ".", "Tan", "(", "inReal", "[", "i", "]", ")", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// Tan - Vector Trigonometric TAN
[ "Tan", "-", "Vector", "Trigonometric", "TAN" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L5486-L5492
10,387
markcheno/go-talib
talib.go
Tanh
func Tanh(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Tanh(inReal[i]) } return outReal }
go
func Tanh(inReal []float64) []float64 { outReal := make([]float64, len(inReal)) for i := 0; i < len(inReal); i++ { outReal[i] = math.Tanh(inReal[i]) } return outReal }
[ "func", "Tanh", "(", "inReal", "[", "]", "float64", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "inReal", ")", ";", "i", "++", "{", "outReal", "[", "i", "]", "=", "math", ".", "Tanh", "(", "inReal", "[", "i", "]", ")", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// Tanh - Vector Trigonometric TANH
[ "Tanh", "-", "Vector", "Trigonometric", "TANH" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L5495-L5501
10,388
markcheno/go-talib
talib.go
Div
func Div(inReal0 []float64, inReal1 []float64) []float64 { outReal := make([]float64, len(inReal0)) for i := 0; i < len(inReal0); i++ { outReal[i] = inReal0[i] / inReal1[i] } return outReal }
go
func Div(inReal0 []float64, inReal1 []float64) []float64 { outReal := make([]float64, len(inReal0)) for i := 0; i < len(inReal0); i++ { outReal[i] = inReal0[i] / inReal1[i] } return outReal }
[ "func", "Div", "(", "inReal0", "[", "]", "float64", ",", "inReal1", "[", "]", "float64", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal0", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "inReal0", ")", ";", "i", "++", "{", "outReal", "[", "i", "]", "=", "inReal0", "[", "i", "]", "/", "inReal1", "[", "i", "]", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// Div - Vector arithmetic division
[ "Div", "-", "Vector", "arithmetic", "division" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L5515-L5521
10,389
markcheno/go-talib
talib.go
Max
func Max(inReal []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inReal)) if inTimePeriod < 2 { return outReal } nbInitialElementNeeded := inTimePeriod - 1 startIdx := nbInitialElementNeeded outIdx := startIdx today := startIdx trailingIdx := startIdx - nbInitialElementNeeded highestIdx := -1 highest := 0.0 for today < len(outReal) { tmp := inReal[today] if highestIdx < trailingIdx { highestIdx = trailingIdx highest = inReal[highestIdx] i := highestIdx + 1 for i <= today { tmp = inReal[i] if tmp > highest { highestIdx = i highest = tmp } i++ } } else if tmp >= highest { highestIdx = today highest = tmp } outReal[outIdx] = highest outIdx++ trailingIdx++ today++ } return outReal }
go
func Max(inReal []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inReal)) if inTimePeriod < 2 { return outReal } nbInitialElementNeeded := inTimePeriod - 1 startIdx := nbInitialElementNeeded outIdx := startIdx today := startIdx trailingIdx := startIdx - nbInitialElementNeeded highestIdx := -1 highest := 0.0 for today < len(outReal) { tmp := inReal[today] if highestIdx < trailingIdx { highestIdx = trailingIdx highest = inReal[highestIdx] i := highestIdx + 1 for i <= today { tmp = inReal[i] if tmp > highest { highestIdx = i highest = tmp } i++ } } else if tmp >= highest { highestIdx = today highest = tmp } outReal[outIdx] = highest outIdx++ trailingIdx++ today++ } return outReal }
[ "func", "Max", "(", "inReal", "[", "]", "float64", ",", "inTimePeriod", "int", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n\n", "if", "inTimePeriod", "<", "2", "{", "return", "outReal", "\n", "}", "\n\n", "nbInitialElementNeeded", ":=", "inTimePeriod", "-", "1", "\n", "startIdx", ":=", "nbInitialElementNeeded", "\n", "outIdx", ":=", "startIdx", "\n", "today", ":=", "startIdx", "\n", "trailingIdx", ":=", "startIdx", "-", "nbInitialElementNeeded", "\n", "highestIdx", ":=", "-", "1", "\n", "highest", ":=", "0.0", "\n\n", "for", "today", "<", "len", "(", "outReal", ")", "{", "tmp", ":=", "inReal", "[", "today", "]", "\n\n", "if", "highestIdx", "<", "trailingIdx", "{", "highestIdx", "=", "trailingIdx", "\n", "highest", "=", "inReal", "[", "highestIdx", "]", "\n", "i", ":=", "highestIdx", "+", "1", "\n", "for", "i", "<=", "today", "{", "tmp", "=", "inReal", "[", "i", "]", "\n", "if", "tmp", ">", "highest", "{", "highestIdx", "=", "i", "\n", "highest", "=", "tmp", "\n", "}", "\n", "i", "++", "\n", "}", "\n", "}", "else", "if", "tmp", ">=", "highest", "{", "highestIdx", "=", "today", "\n", "highest", "=", "tmp", "\n", "}", "\n", "outReal", "[", "outIdx", "]", "=", "highest", "\n", "outIdx", "++", "\n", "trailingIdx", "++", "\n", "today", "++", "\n", "}", "\n\n", "return", "outReal", "\n", "}" ]
// Max - Highest value over a period
[ "Max", "-", "Highest", "value", "over", "a", "period" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L5524-L5567
10,390
markcheno/go-talib
talib.go
Min
func Min(inReal []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inReal)) if inTimePeriod < 2 { return outReal } nbInitialElementNeeded := inTimePeriod - 1 startIdx := nbInitialElementNeeded outIdx := startIdx today := startIdx trailingIdx := startIdx - nbInitialElementNeeded lowestIdx := -1 lowest := 0.0 for today < len(outReal) { tmp := inReal[today] if lowestIdx < trailingIdx { lowestIdx = trailingIdx lowest = inReal[lowestIdx] i := lowestIdx + 1 for i <= today { tmp = inReal[i] if tmp < lowest { lowestIdx = i lowest = tmp } i++ } } else if tmp <= lowest { lowestIdx = today lowest = tmp } outReal[outIdx] = lowest outIdx++ trailingIdx++ today++ } return outReal }
go
func Min(inReal []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inReal)) if inTimePeriod < 2 { return outReal } nbInitialElementNeeded := inTimePeriod - 1 startIdx := nbInitialElementNeeded outIdx := startIdx today := startIdx trailingIdx := startIdx - nbInitialElementNeeded lowestIdx := -1 lowest := 0.0 for today < len(outReal) { tmp := inReal[today] if lowestIdx < trailingIdx { lowestIdx = trailingIdx lowest = inReal[lowestIdx] i := lowestIdx + 1 for i <= today { tmp = inReal[i] if tmp < lowest { lowestIdx = i lowest = tmp } i++ } } else if tmp <= lowest { lowestIdx = today lowest = tmp } outReal[outIdx] = lowest outIdx++ trailingIdx++ today++ } return outReal }
[ "func", "Min", "(", "inReal", "[", "]", "float64", ",", "inTimePeriod", "int", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n\n", "if", "inTimePeriod", "<", "2", "{", "return", "outReal", "\n", "}", "\n\n", "nbInitialElementNeeded", ":=", "inTimePeriod", "-", "1", "\n", "startIdx", ":=", "nbInitialElementNeeded", "\n", "outIdx", ":=", "startIdx", "\n", "today", ":=", "startIdx", "\n", "trailingIdx", ":=", "startIdx", "-", "nbInitialElementNeeded", "\n", "lowestIdx", ":=", "-", "1", "\n", "lowest", ":=", "0.0", "\n", "for", "today", "<", "len", "(", "outReal", ")", "{", "tmp", ":=", "inReal", "[", "today", "]", "\n\n", "if", "lowestIdx", "<", "trailingIdx", "{", "lowestIdx", "=", "trailingIdx", "\n", "lowest", "=", "inReal", "[", "lowestIdx", "]", "\n", "i", ":=", "lowestIdx", "+", "1", "\n", "for", "i", "<=", "today", "{", "tmp", "=", "inReal", "[", "i", "]", "\n", "if", "tmp", "<", "lowest", "{", "lowestIdx", "=", "i", "\n", "lowest", "=", "tmp", "\n", "}", "\n", "i", "++", "\n", "}", "\n", "}", "else", "if", "tmp", "<=", "lowest", "{", "lowestIdx", "=", "today", "\n", "lowest", "=", "tmp", "\n", "}", "\n", "outReal", "[", "outIdx", "]", "=", "lowest", "\n", "outIdx", "++", "\n", "trailingIdx", "++", "\n", "today", "++", "\n", "}", "\n\n", "return", "outReal", "\n", "}" ]
// Min - Lowest value over a period
[ "Min", "-", "Lowest", "value", "over", "a", "period" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L5613-L5655
10,391
markcheno/go-talib
talib.go
MinMax
func MinMax(inReal []float64, inTimePeriod int) ([]float64, []float64) { outMin := make([]float64, len(inReal)) outMax := make([]float64, len(inReal)) nbInitialElementNeeded := (inTimePeriod - 1) startIdx := nbInitialElementNeeded outIdx := startIdx today := startIdx trailingIdx := startIdx - nbInitialElementNeeded highestIdx := -1 highest := 0.0 lowestIdx := -1 lowest := 0.0 for today < len(inReal) { tmpLow, tmpHigh := inReal[today], inReal[today] if highestIdx < trailingIdx { highestIdx = trailingIdx highest = inReal[highestIdx] i := highestIdx i++ for i <= today { tmpHigh = inReal[i] if tmpHigh > highest { highestIdx = i highest = tmpHigh } i++ } } else if tmpHigh >= highest { highestIdx = today highest = tmpHigh } if lowestIdx < trailingIdx { lowestIdx = trailingIdx lowest = inReal[lowestIdx] i := lowestIdx i++ for i <= today { tmpLow = inReal[i] if tmpLow < lowest { lowestIdx = i lowest = tmpLow } i++ } } else if tmpLow <= lowest { lowestIdx = today lowest = tmpLow } outMax[outIdx] = highest outMin[outIdx] = lowest outIdx++ trailingIdx++ today++ } return outMin, outMax }
go
func MinMax(inReal []float64, inTimePeriod int) ([]float64, []float64) { outMin := make([]float64, len(inReal)) outMax := make([]float64, len(inReal)) nbInitialElementNeeded := (inTimePeriod - 1) startIdx := nbInitialElementNeeded outIdx := startIdx today := startIdx trailingIdx := startIdx - nbInitialElementNeeded highestIdx := -1 highest := 0.0 lowestIdx := -1 lowest := 0.0 for today < len(inReal) { tmpLow, tmpHigh := inReal[today], inReal[today] if highestIdx < trailingIdx { highestIdx = trailingIdx highest = inReal[highestIdx] i := highestIdx i++ for i <= today { tmpHigh = inReal[i] if tmpHigh > highest { highestIdx = i highest = tmpHigh } i++ } } else if tmpHigh >= highest { highestIdx = today highest = tmpHigh } if lowestIdx < trailingIdx { lowestIdx = trailingIdx lowest = inReal[lowestIdx] i := lowestIdx i++ for i <= today { tmpLow = inReal[i] if tmpLow < lowest { lowestIdx = i lowest = tmpLow } i++ } } else if tmpLow <= lowest { lowestIdx = today lowest = tmpLow } outMax[outIdx] = highest outMin[outIdx] = lowest outIdx++ trailingIdx++ today++ } return outMin, outMax }
[ "func", "MinMax", "(", "inReal", "[", "]", "float64", ",", "inTimePeriod", "int", ")", "(", "[", "]", "float64", ",", "[", "]", "float64", ")", "{", "outMin", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n", "outMax", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n\n", "nbInitialElementNeeded", ":=", "(", "inTimePeriod", "-", "1", ")", "\n", "startIdx", ":=", "nbInitialElementNeeded", "\n", "outIdx", ":=", "startIdx", "\n", "today", ":=", "startIdx", "\n", "trailingIdx", ":=", "startIdx", "-", "nbInitialElementNeeded", "\n", "highestIdx", ":=", "-", "1", "\n", "highest", ":=", "0.0", "\n", "lowestIdx", ":=", "-", "1", "\n", "lowest", ":=", "0.0", "\n", "for", "today", "<", "len", "(", "inReal", ")", "{", "tmpLow", ",", "tmpHigh", ":=", "inReal", "[", "today", "]", ",", "inReal", "[", "today", "]", "\n", "if", "highestIdx", "<", "trailingIdx", "{", "highestIdx", "=", "trailingIdx", "\n", "highest", "=", "inReal", "[", "highestIdx", "]", "\n", "i", ":=", "highestIdx", "\n", "i", "++", "\n", "for", "i", "<=", "today", "{", "tmpHigh", "=", "inReal", "[", "i", "]", "\n", "if", "tmpHigh", ">", "highest", "{", "highestIdx", "=", "i", "\n", "highest", "=", "tmpHigh", "\n", "}", "\n", "i", "++", "\n", "}", "\n", "}", "else", "if", "tmpHigh", ">=", "highest", "{", "highestIdx", "=", "today", "\n", "highest", "=", "tmpHigh", "\n", "}", "\n", "if", "lowestIdx", "<", "trailingIdx", "{", "lowestIdx", "=", "trailingIdx", "\n", "lowest", "=", "inReal", "[", "lowestIdx", "]", "\n", "i", ":=", "lowestIdx", "\n", "i", "++", "\n", "for", "i", "<=", "today", "{", "tmpLow", "=", "inReal", "[", "i", "]", "\n", "if", "tmpLow", "<", "lowest", "{", "lowestIdx", "=", "i", "\n", "lowest", "=", "tmpLow", "\n", "}", "\n", "i", "++", "\n", "}", "\n", "}", "else", "if", "tmpLow", "<=", "lowest", "{", "lowestIdx", "=", "today", "\n", "lowest", "=", "tmpLow", "\n", "}", "\n", "outMax", "[", "outIdx", "]", "=", "highest", "\n", "outMin", "[", "outIdx", "]", "=", "lowest", "\n", "outIdx", "++", "\n", "trailingIdx", "++", "\n", "today", "++", "\n", "}", "\n", "return", "outMin", ",", "outMax", "\n", "}" ]
// MinMax - Lowest and highest values over a specified period
[ "MinMax", "-", "Lowest", "and", "highest", "values", "over", "a", "specified", "period" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L5700-L5757
10,392
markcheno/go-talib
talib.go
MinMaxIndex
func MinMaxIndex(inReal []float64, inTimePeriod int) ([]float64, []float64) { outMinIdx := make([]float64, len(inReal)) outMaxIdx := make([]float64, len(inReal)) nbInitialElementNeeded := (inTimePeriod - 1) startIdx := nbInitialElementNeeded outIdx := startIdx today := startIdx trailingIdx := startIdx - nbInitialElementNeeded highestIdx := -1 highest := 0.0 lowestIdx := -1 lowest := 0.0 for today < len(inReal) { tmpLow, tmpHigh := inReal[today], inReal[today] if highestIdx < trailingIdx { highestIdx = trailingIdx highest = inReal[highestIdx] i := highestIdx i++ for i <= today { tmpHigh = inReal[i] if tmpHigh > highest { highestIdx = i highest = tmpHigh } i++ } } else if tmpHigh >= highest { highestIdx = today highest = tmpHigh } if lowestIdx < trailingIdx { lowestIdx = trailingIdx lowest = inReal[lowestIdx] i := lowestIdx i++ for i <= today { tmpLow = inReal[i] if tmpLow < lowest { lowestIdx = i lowest = tmpLow } i++ } } else if tmpLow <= lowest { lowestIdx = today lowest = tmpLow } outMaxIdx[outIdx] = float64(highestIdx) outMinIdx[outIdx] = float64(lowestIdx) outIdx++ trailingIdx++ today++ } return outMinIdx, outMaxIdx }
go
func MinMaxIndex(inReal []float64, inTimePeriod int) ([]float64, []float64) { outMinIdx := make([]float64, len(inReal)) outMaxIdx := make([]float64, len(inReal)) nbInitialElementNeeded := (inTimePeriod - 1) startIdx := nbInitialElementNeeded outIdx := startIdx today := startIdx trailingIdx := startIdx - nbInitialElementNeeded highestIdx := -1 highest := 0.0 lowestIdx := -1 lowest := 0.0 for today < len(inReal) { tmpLow, tmpHigh := inReal[today], inReal[today] if highestIdx < trailingIdx { highestIdx = trailingIdx highest = inReal[highestIdx] i := highestIdx i++ for i <= today { tmpHigh = inReal[i] if tmpHigh > highest { highestIdx = i highest = tmpHigh } i++ } } else if tmpHigh >= highest { highestIdx = today highest = tmpHigh } if lowestIdx < trailingIdx { lowestIdx = trailingIdx lowest = inReal[lowestIdx] i := lowestIdx i++ for i <= today { tmpLow = inReal[i] if tmpLow < lowest { lowestIdx = i lowest = tmpLow } i++ } } else if tmpLow <= lowest { lowestIdx = today lowest = tmpLow } outMaxIdx[outIdx] = float64(highestIdx) outMinIdx[outIdx] = float64(lowestIdx) outIdx++ trailingIdx++ today++ } return outMinIdx, outMaxIdx }
[ "func", "MinMaxIndex", "(", "inReal", "[", "]", "float64", ",", "inTimePeriod", "int", ")", "(", "[", "]", "float64", ",", "[", "]", "float64", ")", "{", "outMinIdx", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n", "outMaxIdx", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n\n", "nbInitialElementNeeded", ":=", "(", "inTimePeriod", "-", "1", ")", "\n", "startIdx", ":=", "nbInitialElementNeeded", "\n", "outIdx", ":=", "startIdx", "\n", "today", ":=", "startIdx", "\n", "trailingIdx", ":=", "startIdx", "-", "nbInitialElementNeeded", "\n", "highestIdx", ":=", "-", "1", "\n", "highest", ":=", "0.0", "\n", "lowestIdx", ":=", "-", "1", "\n", "lowest", ":=", "0.0", "\n", "for", "today", "<", "len", "(", "inReal", ")", "{", "tmpLow", ",", "tmpHigh", ":=", "inReal", "[", "today", "]", ",", "inReal", "[", "today", "]", "\n", "if", "highestIdx", "<", "trailingIdx", "{", "highestIdx", "=", "trailingIdx", "\n", "highest", "=", "inReal", "[", "highestIdx", "]", "\n", "i", ":=", "highestIdx", "\n", "i", "++", "\n", "for", "i", "<=", "today", "{", "tmpHigh", "=", "inReal", "[", "i", "]", "\n", "if", "tmpHigh", ">", "highest", "{", "highestIdx", "=", "i", "\n", "highest", "=", "tmpHigh", "\n", "}", "\n", "i", "++", "\n", "}", "\n", "}", "else", "if", "tmpHigh", ">=", "highest", "{", "highestIdx", "=", "today", "\n", "highest", "=", "tmpHigh", "\n", "}", "\n", "if", "lowestIdx", "<", "trailingIdx", "{", "lowestIdx", "=", "trailingIdx", "\n", "lowest", "=", "inReal", "[", "lowestIdx", "]", "\n", "i", ":=", "lowestIdx", "\n", "i", "++", "\n", "for", "i", "<=", "today", "{", "tmpLow", "=", "inReal", "[", "i", "]", "\n", "if", "tmpLow", "<", "lowest", "{", "lowestIdx", "=", "i", "\n", "lowest", "=", "tmpLow", "\n", "}", "\n", "i", "++", "\n", "}", "\n", "}", "else", "if", "tmpLow", "<=", "lowest", "{", "lowestIdx", "=", "today", "\n", "lowest", "=", "tmpLow", "\n", "}", "\n", "outMaxIdx", "[", "outIdx", "]", "=", "float64", "(", "highestIdx", ")", "\n", "outMinIdx", "[", "outIdx", "]", "=", "float64", "(", "lowestIdx", ")", "\n", "outIdx", "++", "\n", "trailingIdx", "++", "\n", "today", "++", "\n", "}", "\n", "return", "outMinIdx", ",", "outMaxIdx", "\n", "}" ]
// MinMaxIndex - Indexes of lowest and highest values over a specified period
[ "MinMaxIndex", "-", "Indexes", "of", "lowest", "and", "highest", "values", "over", "a", "specified", "period" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L5760-L5817
10,393
markcheno/go-talib
talib.go
Mult
func Mult(inReal0 []float64, inReal1 []float64) []float64 { outReal := make([]float64, len(inReal0)) for i := 0; i < len(inReal0); i++ { outReal[i] = inReal0[i] * inReal1[i] } return outReal }
go
func Mult(inReal0 []float64, inReal1 []float64) []float64 { outReal := make([]float64, len(inReal0)) for i := 0; i < len(inReal0); i++ { outReal[i] = inReal0[i] * inReal1[i] } return outReal }
[ "func", "Mult", "(", "inReal0", "[", "]", "float64", ",", "inReal1", "[", "]", "float64", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal0", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "inReal0", ")", ";", "i", "++", "{", "outReal", "[", "i", "]", "=", "inReal0", "[", "i", "]", "*", "inReal1", "[", "i", "]", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// Mult - Vector arithmetic multiply
[ "Mult", "-", "Vector", "arithmetic", "multiply" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L5820-L5826
10,394
markcheno/go-talib
talib.go
Sub
func Sub(inReal0 []float64, inReal1 []float64) []float64 { outReal := make([]float64, len(inReal0)) for i := 0; i < len(inReal0); i++ { outReal[i] = inReal0[i] - inReal1[i] } return outReal }
go
func Sub(inReal0 []float64, inReal1 []float64) []float64 { outReal := make([]float64, len(inReal0)) for i := 0; i < len(inReal0); i++ { outReal[i] = inReal0[i] - inReal1[i] } return outReal }
[ "func", "Sub", "(", "inReal0", "[", "]", "float64", ",", "inReal1", "[", "]", "float64", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal0", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "inReal0", ")", ";", "i", "++", "{", "outReal", "[", "i", "]", "=", "inReal0", "[", "i", "]", "-", "inReal1", "[", "i", "]", "\n", "}", "\n", "return", "outReal", "\n", "}" ]
// Sub - Vector arithmetic subtraction
[ "Sub", "-", "Vector", "arithmetic", "subtraction" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L5829-L5835
10,395
markcheno/go-talib
talib.go
Sum
func Sum(inReal []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inReal)) lookbackTotal := inTimePeriod - 1 startIdx := lookbackTotal periodTotal := 0.0 trailingIdx := startIdx - lookbackTotal i := trailingIdx if inTimePeriod > 1 { for i < startIdx { periodTotal += inReal[i] i++ } } outIdx := startIdx for i < len(inReal) { periodTotal += inReal[i] tempReal := periodTotal periodTotal -= inReal[trailingIdx] outReal[outIdx] = tempReal i++ trailingIdx++ outIdx++ } return outReal }
go
func Sum(inReal []float64, inTimePeriod int) []float64 { outReal := make([]float64, len(inReal)) lookbackTotal := inTimePeriod - 1 startIdx := lookbackTotal periodTotal := 0.0 trailingIdx := startIdx - lookbackTotal i := trailingIdx if inTimePeriod > 1 { for i < startIdx { periodTotal += inReal[i] i++ } } outIdx := startIdx for i < len(inReal) { periodTotal += inReal[i] tempReal := periodTotal periodTotal -= inReal[trailingIdx] outReal[outIdx] = tempReal i++ trailingIdx++ outIdx++ } return outReal }
[ "func", "Sum", "(", "inReal", "[", "]", "float64", ",", "inTimePeriod", "int", ")", "[", "]", "float64", "{", "outReal", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "inReal", ")", ")", "\n\n", "lookbackTotal", ":=", "inTimePeriod", "-", "1", "\n", "startIdx", ":=", "lookbackTotal", "\n", "periodTotal", ":=", "0.0", "\n", "trailingIdx", ":=", "startIdx", "-", "lookbackTotal", "\n", "i", ":=", "trailingIdx", "\n", "if", "inTimePeriod", ">", "1", "{", "for", "i", "<", "startIdx", "{", "periodTotal", "+=", "inReal", "[", "i", "]", "\n", "i", "++", "\n", "}", "\n", "}", "\n", "outIdx", ":=", "startIdx", "\n", "for", "i", "<", "len", "(", "inReal", ")", "{", "periodTotal", "+=", "inReal", "[", "i", "]", "\n", "tempReal", ":=", "periodTotal", "\n", "periodTotal", "-=", "inReal", "[", "trailingIdx", "]", "\n", "outReal", "[", "outIdx", "]", "=", "tempReal", "\n", "i", "++", "\n", "trailingIdx", "++", "\n", "outIdx", "++", "\n", "}", "\n\n", "return", "outReal", "\n", "}" ]
// Sum - Vector summation
[ "Sum", "-", "Vector", "summation" ]
cd53a9264d70bedcff891f59bf153275f524c100
https://github.com/markcheno/go-talib/blob/cd53a9264d70bedcff891f59bf153275f524c100/talib.go#L5838-L5865
10,396
mdlayher/vsock
ioctl_linux.go
contextID
func contextID() (uint32, error) { // Fetch the context ID using a real filesystem. var cid uint32 if err := sysContextID(sysFS{}, &cid); err != nil { return 0, err } return cid, nil }
go
func contextID() (uint32, error) { // Fetch the context ID using a real filesystem. var cid uint32 if err := sysContextID(sysFS{}, &cid); err != nil { return 0, err } return cid, nil }
[ "func", "contextID", "(", ")", "(", "uint32", ",", "error", ")", "{", "// Fetch the context ID using a real filesystem.", "var", "cid", "uint32", "\n", "if", "err", ":=", "sysContextID", "(", "sysFS", "{", "}", ",", "&", "cid", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "return", "cid", ",", "nil", "\n", "}" ]
// contextID retrieves the local context ID for this system.
[ "contextID", "retrieves", "the", "local", "context", "ID", "for", "this", "system", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/ioctl_linux.go#L18-L26
10,397
mdlayher/vsock
ioctl_linux.go
sysContextID
func sysContextID(fs fs, cid *uint32) error { f, err := fs.Open(devVsock) if err != nil { return err } defer f.Close() // Retrieve the context ID of this machine from /dev/vsock. return fs.Ioctl(f.Fd(), unix.IOCTL_VM_SOCKETS_GET_LOCAL_CID, unsafe.Pointer(cid)) }
go
func sysContextID(fs fs, cid *uint32) error { f, err := fs.Open(devVsock) if err != nil { return err } defer f.Close() // Retrieve the context ID of this machine from /dev/vsock. return fs.Ioctl(f.Fd(), unix.IOCTL_VM_SOCKETS_GET_LOCAL_CID, unsafe.Pointer(cid)) }
[ "func", "sysContextID", "(", "fs", "fs", ",", "cid", "*", "uint32", ")", "error", "{", "f", ",", "err", ":=", "fs", ".", "Open", "(", "devVsock", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "f", ".", "Close", "(", ")", "\n\n", "// Retrieve the context ID of this machine from /dev/vsock.", "return", "fs", ".", "Ioctl", "(", "f", ".", "Fd", "(", ")", ",", "unix", ".", "IOCTL_VM_SOCKETS_GET_LOCAL_CID", ",", "unsafe", ".", "Pointer", "(", "cid", ")", ")", "\n", "}" ]
// sysContextID retrieves the local context ID for this system, using the // methods from fs. The context ID is stored in cid for later use. // // This method uses this signature to enable easier testing without unsafe // usage of unsafe.Pointer.
[ "sysContextID", "retrieves", "the", "local", "context", "ID", "for", "this", "system", "using", "the", "methods", "from", "fs", ".", "The", "context", "ID", "is", "stored", "in", "cid", "for", "later", "use", ".", "This", "method", "uses", "this", "signature", "to", "enable", "easier", "testing", "without", "unsafe", "usage", "of", "unsafe", ".", "Pointer", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/ioctl_linux.go#L33-L42
10,398
mdlayher/vsock
internal/vsutil/vsutil.go
Accept
func Accept(l net.Listener, timeout time.Duration) (net.Conn, error) { // This function accommodates both Go1.12+ and Go1.11 functionality to allow // net.Listener.Accept to be canceled by net.Listener.Close. // // If a timeout is set, set up a timer to close the listener and either: // - Go 1.12+: unblock the call to Accept // - Go 1.11 : eventually halt the loop due to closed file descriptor // // For Go 1.12+, we could use vsock.Listener.SetDeadline, but this approach // using a timer works for Go 1.11 as well. cancel := func() {} if timeout != 0 { timer := time.AfterFunc(timeout, func() { _ = l.Close() }) cancel = func() { timer.Stop() } } for { c, err := l.Accept() if err != nil { if nerr, ok := err.(net.Error); ok && nerr.Temporary() { time.Sleep(250 * time.Millisecond) continue } return nil, err } // Got a connection, stop the timer. cancel() return c, nil } }
go
func Accept(l net.Listener, timeout time.Duration) (net.Conn, error) { // This function accommodates both Go1.12+ and Go1.11 functionality to allow // net.Listener.Accept to be canceled by net.Listener.Close. // // If a timeout is set, set up a timer to close the listener and either: // - Go 1.12+: unblock the call to Accept // - Go 1.11 : eventually halt the loop due to closed file descriptor // // For Go 1.12+, we could use vsock.Listener.SetDeadline, but this approach // using a timer works for Go 1.11 as well. cancel := func() {} if timeout != 0 { timer := time.AfterFunc(timeout, func() { _ = l.Close() }) cancel = func() { timer.Stop() } } for { c, err := l.Accept() if err != nil { if nerr, ok := err.(net.Error); ok && nerr.Temporary() { time.Sleep(250 * time.Millisecond) continue } return nil, err } // Got a connection, stop the timer. cancel() return c, nil } }
[ "func", "Accept", "(", "l", "net", ".", "Listener", ",", "timeout", "time", ".", "Duration", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "// This function accommodates both Go1.12+ and Go1.11 functionality to allow", "// net.Listener.Accept to be canceled by net.Listener.Close.", "//", "// If a timeout is set, set up a timer to close the listener and either:", "// - Go 1.12+: unblock the call to Accept", "// - Go 1.11 : eventually halt the loop due to closed file descriptor", "//", "// For Go 1.12+, we could use vsock.Listener.SetDeadline, but this approach", "// using a timer works for Go 1.11 as well.", "cancel", ":=", "func", "(", ")", "{", "}", "\n", "if", "timeout", "!=", "0", "{", "timer", ":=", "time", ".", "AfterFunc", "(", "timeout", ",", "func", "(", ")", "{", "_", "=", "l", ".", "Close", "(", ")", "}", ")", "\n", "cancel", "=", "func", "(", ")", "{", "timer", ".", "Stop", "(", ")", "}", "\n", "}", "\n\n", "for", "{", "c", ",", "err", ":=", "l", ".", "Accept", "(", ")", "\n", "if", "err", "!=", "nil", "{", "if", "nerr", ",", "ok", ":=", "err", ".", "(", "net", ".", "Error", ")", ";", "ok", "&&", "nerr", ".", "Temporary", "(", ")", "{", "time", ".", "Sleep", "(", "250", "*", "time", ".", "Millisecond", ")", "\n", "continue", "\n", "}", "\n\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Got a connection, stop the timer.", "cancel", "(", ")", "\n", "return", "c", ",", "nil", "\n", "}", "\n", "}" ]
// Accept blocks until a single connection is accepted by the net.Listener. // // If timeout is non-zero, the listener will be closed after the timeout // expires, even if no connection was accepted.
[ "Accept", "blocks", "until", "a", "single", "connection", "is", "accepted", "by", "the", "net", ".", "Listener", ".", "If", "timeout", "is", "non", "-", "zero", "the", "listener", "will", "be", "closed", "after", "the", "timeout", "expires", "even", "if", "no", "connection", "was", "accepted", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/internal/vsutil/vsutil.go#L17-L48
10,399
mdlayher/vsock
internal/vsutil/vsutil.go
SkipHostIntegration
func SkipHostIntegration(t *testing.T) { t.Helper() if IsHypervisor(t) { t.Skip("skipping, this integration test must be run in a guest") } }
go
func SkipHostIntegration(t *testing.T) { t.Helper() if IsHypervisor(t) { t.Skip("skipping, this integration test must be run in a guest") } }
[ "func", "SkipHostIntegration", "(", "t", "*", "testing", ".", "T", ")", "{", "t", ".", "Helper", "(", ")", "\n\n", "if", "IsHypervisor", "(", "t", ")", "{", "t", ".", "Skip", "(", "\"", "\"", ")", "\n", "}", "\n", "}" ]
// SkipHostIntegration skips this test if this machine is a host and cannot // perform a given test.
[ "SkipHostIntegration", "skips", "this", "test", "if", "this", "machine", "is", "a", "host", "and", "cannot", "perform", "a", "given", "test", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/internal/vsutil/vsutil.go#L87-L93