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", ...
// 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...
// 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 ...
// 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"...
// 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", ".", "Default...
// 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"...
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...
// 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...
// 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", ",", "}"...
// 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", "_", ",...
// 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", "{"...
// 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", "(...
// 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", ":=", "...
// 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", "("...
// 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", "=", ...
// 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", "=",...
// 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", ...
// 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", "}"...
// 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", ".", "(", "[", ...
// 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", ":=...
// 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", "(", ")",...
// 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", ...
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...
// 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"...
// 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", "re...
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", "(", ")", ...
// 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",...
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", ".", "Es...
// 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",...
// 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", "=",...
// 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", ...
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", ".", "Default...
// 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", "\...
// 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", "(", ...
// 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", "(", ...
// 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", "(", ...
// 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", "(", ...
// 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", "(", ...
// 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", ...
// 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", "resu...
// 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", "\""...
// 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", "...
// 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...
// 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", "(", ")", "...
// 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", ...
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", ":=", "\"...
// 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", "in...
// 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", ","...
// 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", "inTimePerio...
// 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"...
// 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...
// 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", "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", "-", ...
// 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", ","...
// 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", "-", ...
// 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", "(...
// 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", "s...
// 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", ",", ...
// 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", ...
// 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", "("...
// 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", ")", "(", "[", "]", "f...
// 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", "lo...
// 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", ...
// 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", "=", "...
// 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", "{", "retu...
// 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", ",", "inSlow...
// 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", ",", ...
// 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", "...
// 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", "...
// 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", "pr...
// 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", ")", ")", ...
// 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", "(", ...
// 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...
// 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", ...
// 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", ")", ...
// 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", ")", ...
// 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", ")", ...
// 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", ")", "...
// 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", ")", ...
// 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", ")", "...
// 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", ")", ...
// 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", ")", ";...
// 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", ")", ...
// 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", ")", "...
// 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", ")", ...
// 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", ")", ...
// 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", ")", "...
// 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", ")", ...
// 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", ";", "...
// 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", "{", "retu...
// 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", "{", "retu...
// 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", "out...
// 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"...
// 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", ";", ...
// 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", ";", "...
// 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", "-", ...
// 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"...
// 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", ".", "Cl...
// 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", "signatu...
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...
// 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", ...
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