id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
9,700 | remind101/pkg | reporter/hb2/internal/honeybadger-go/honeybadger.go | Notify | func Notify(err interface{}, extra ...interface{}) (string, error) {
return DefaultClient.Notify(newError(err, 2), extra...)
} | go | func Notify(err interface{}, extra ...interface{}) (string, error) {
return DefaultClient.Notify(newError(err, 2), extra...)
} | [
"func",
"Notify",
"(",
"err",
"interface",
"{",
"}",
",",
"extra",
"...",
"interface",
"{",
"}",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"DefaultClient",
".",
"Notify",
"(",
"newError",
"(",
"err",
",",
"2",
")",
",",
"extra",
"...",
")",
"\n",
"}"
] | // Notify reports the error err to the Honeybadger service.
//
// The first argument err may be an error, a string, or any other type in which
// case its formatted value will be used.
//
// It returns a string UUID which can be used to reference the error from the
// Honeybadger service, and an error as a second argument. | [
"Notify",
"reports",
"the",
"error",
"err",
"to",
"the",
"Honeybadger",
"service",
".",
"The",
"first",
"argument",
"err",
"may",
"be",
"an",
"error",
"a",
"string",
"or",
"any",
"other",
"type",
"in",
"which",
"case",
"its",
"formatted",
"value",
"will",
"be",
"used",
".",
"It",
"returns",
"a",
"string",
"UUID",
"which",
"can",
"be",
"used",
"to",
"reference",
"the",
"error",
"from",
"the",
"Honeybadger",
"service",
"and",
"an",
"error",
"as",
"a",
"second",
"argument",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/reporter/hb2/internal/honeybadger-go/honeybadger.go#L70-L72 |
9,701 | remind101/pkg | httpx/middleware/logger.go | LogTo | func LogTo(h httpx.Handler, g loggerGenerator) httpx.Handler {
return InsertLogger(Log(h), g)
} | go | func LogTo(h httpx.Handler, g loggerGenerator) httpx.Handler {
return InsertLogger(Log(h), g)
} | [
"func",
"LogTo",
"(",
"h",
"httpx",
".",
"Handler",
",",
"g",
"loggerGenerator",
")",
"httpx",
".",
"Handler",
"{",
"return",
"InsertLogger",
"(",
"Log",
"(",
"h",
")",
",",
"g",
")",
"\n",
"}"
] | // LogTo is an httpx middleware that wraps the handler to insert a logger and
// log the request to it. | [
"LogTo",
"is",
"an",
"httpx",
"middleware",
"that",
"wraps",
"the",
"handler",
"to",
"insert",
"a",
"logger",
"and",
"log",
"the",
"request",
"to",
"it",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/httpx/middleware/logger.go#L37-L39 |
9,702 | remind101/pkg | httpx/middleware/logger.go | InsertLogger | func InsertLogger(h httpx.Handler, g loggerGenerator) httpx.Handler {
return httpx.HandlerFunc(func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
l := g(ctx, r)
ctx = logger.WithLogger(ctx, l)
r = r.WithContext(ctx)
return h.ServeHTTPContext(ctx, w, r)
})
} | go | func InsertLogger(h httpx.Handler, g loggerGenerator) httpx.Handler {
return httpx.HandlerFunc(func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
l := g(ctx, r)
ctx = logger.WithLogger(ctx, l)
r = r.WithContext(ctx)
return h.ServeHTTPContext(ctx, w, r)
})
} | [
"func",
"InsertLogger",
"(",
"h",
"httpx",
".",
"Handler",
",",
"g",
"loggerGenerator",
")",
"httpx",
".",
"Handler",
"{",
"return",
"httpx",
".",
"HandlerFunc",
"(",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"l",
":=",
"g",
"(",
"ctx",
",",
"r",
")",
"\n\n",
"ctx",
"=",
"logger",
".",
"WithLogger",
"(",
"ctx",
",",
"l",
")",
"\n",
"r",
"=",
"r",
".",
"WithContext",
"(",
"ctx",
")",
"\n\n",
"return",
"h",
".",
"ServeHTTPContext",
"(",
"ctx",
",",
"w",
",",
"r",
")",
"\n",
"}",
")",
"\n",
"}"
] | // InsertLogger returns an httpx.Handler middleware that will call f to generate
// a logger, then insert it into the context. | [
"InsertLogger",
"returns",
"an",
"httpx",
".",
"Handler",
"middleware",
"that",
"will",
"call",
"f",
"to",
"generate",
"a",
"logger",
"then",
"insert",
"it",
"into",
"the",
"context",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/httpx/middleware/logger.go#L43-L52 |
9,703 | remind101/pkg | logger/logger.go | New | func New(l *log.Logger, ll Level) Logger {
return &logger{
Logger: l,
Level: ll,
ctxPairs: []interface{}{},
}
} | go | func New(l *log.Logger, ll Level) Logger {
return &logger{
Logger: l,
Level: ll,
ctxPairs: []interface{}{},
}
} | [
"func",
"New",
"(",
"l",
"*",
"log",
".",
"Logger",
",",
"ll",
"Level",
")",
"Logger",
"{",
"return",
"&",
"logger",
"{",
"Logger",
":",
"l",
",",
"Level",
":",
"ll",
",",
"ctxPairs",
":",
"[",
"]",
"interface",
"{",
"}",
"{",
"}",
",",
"}",
"\n",
"}"
] | // New wraps the log.Logger to implement the Logger interface. | [
"New",
"wraps",
"the",
"log",
".",
"Logger",
"to",
"implement",
"the",
"Logger",
"interface",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/logger/logger.go#L60-L66 |
9,704 | remind101/pkg | logger/logger.go | With | func (l *logger) With(pairs ...interface{}) Logger {
return &logger{
Logger: l.Logger,
Level: l.Level,
ctxPairs: append(l.ctxPairs, pairs...),
}
} | go | func (l *logger) With(pairs ...interface{}) Logger {
return &logger{
Logger: l.Logger,
Level: l.Level,
ctxPairs: append(l.ctxPairs, pairs...),
}
} | [
"func",
"(",
"l",
"*",
"logger",
")",
"With",
"(",
"pairs",
"...",
"interface",
"{",
"}",
")",
"Logger",
"{",
"return",
"&",
"logger",
"{",
"Logger",
":",
"l",
".",
"Logger",
",",
"Level",
":",
"l",
".",
"Level",
",",
"ctxPairs",
":",
"append",
"(",
"l",
".",
"ctxPairs",
",",
"pairs",
"...",
")",
",",
"}",
"\n",
"}"
] | // With returns a new logger with the given key value pairs added to each log message. | [
"With",
"returns",
"a",
"new",
"logger",
"with",
"the",
"given",
"key",
"value",
"pairs",
"added",
"to",
"each",
"log",
"message",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/logger/logger.go#L69-L75 |
9,705 | remind101/pkg | logger/logger.go | WithLogger | func WithLogger(ctx context.Context, l Logger) context.Context {
return context.WithValue(ctx, loggerKey, l)
} | go | func WithLogger(ctx context.Context, l Logger) context.Context {
return context.WithValue(ctx, loggerKey, l)
} | [
"func",
"WithLogger",
"(",
"ctx",
"context",
".",
"Context",
",",
"l",
"Logger",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"loggerKey",
",",
"l",
")",
"\n",
"}"
] | // WithLogger inserts a log.Logger into the provided context. | [
"WithLogger",
"inserts",
"a",
"log",
".",
"Logger",
"into",
"the",
"provided",
"context",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/logger/logger.go#L120-L122 |
9,706 | remind101/pkg | logger/logger.go | FromContext | func FromContext(ctx context.Context) (Logger, bool) {
l, ok := ctx.Value(loggerKey).(Logger)
return l, ok
} | go | func FromContext(ctx context.Context) (Logger, bool) {
l, ok := ctx.Value(loggerKey).(Logger)
return l, ok
} | [
"func",
"FromContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"Logger",
",",
"bool",
")",
"{",
"l",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"loggerKey",
")",
".",
"(",
"Logger",
")",
"\n",
"return",
"l",
",",
"ok",
"\n",
"}"
] | // FromContext returns a log.Logger from the context. | [
"FromContext",
"returns",
"a",
"log",
".",
"Logger",
"from",
"the",
"context",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/logger/logger.go#L125-L128 |
9,707 | remind101/pkg | client/request/request.go | New | func New(httpReq *http.Request, info metadata.ClientInfo, handlers Handlers, params interface{}, data interface{}) *Request {
r := &Request{
ClientInfo: info,
HTTPClient: http.DefaultClient,
Handlers: handlers.Copy(),
Time: time.Now(),
HTTPRequest: httpReq,
Params: params,
Data: data,
}
return r
} | go | func New(httpReq *http.Request, info metadata.ClientInfo, handlers Handlers, params interface{}, data interface{}) *Request {
r := &Request{
ClientInfo: info,
HTTPClient: http.DefaultClient,
Handlers: handlers.Copy(),
Time: time.Now(),
HTTPRequest: httpReq,
Params: params,
Data: data,
}
return r
} | [
"func",
"New",
"(",
"httpReq",
"*",
"http",
".",
"Request",
",",
"info",
"metadata",
".",
"ClientInfo",
",",
"handlers",
"Handlers",
",",
"params",
"interface",
"{",
"}",
",",
"data",
"interface",
"{",
"}",
")",
"*",
"Request",
"{",
"r",
":=",
"&",
"Request",
"{",
"ClientInfo",
":",
"info",
",",
"HTTPClient",
":",
"http",
".",
"DefaultClient",
",",
"Handlers",
":",
"handlers",
".",
"Copy",
"(",
")",
",",
"Time",
":",
"time",
".",
"Now",
"(",
")",
",",
"HTTPRequest",
":",
"httpReq",
",",
"Params",
":",
"params",
",",
"Data",
":",
"data",
",",
"}",
"\n\n",
"return",
"r",
"\n",
"}"
] | // New creates a new Request. | [
"New",
"creates",
"a",
"new",
"Request",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/client/request/request.go#L26-L38 |
9,708 | remind101/pkg | client/request/request.go | Send | func (r *Request) Send() error {
// Always run Complete handlers
defer func() {
r.Handlers.Complete.Run(r)
}()
// Build and Sign the request.
r.Build()
if r.Error != nil {
return r.Error
}
// Send the request. r.HTTPResponse should be populated after these handlers run.
r.Handlers.Send.Run(r)
if r.Error != nil {
return r.Error
}
// Validate the response. This is a good place to create a r.Error if
// the response is not a 2xx status code.
r.Handlers.ValidateResponse.Run(r)
if r.Error != nil {
// Run DecodeError handlers. This is a good place to add custom error response
// parsing.
r.Handlers.DecodeError.Run(r)
return r.Error
}
// Decode the response. Commonly will populate r.Data variable with a parsed response body.
r.Handlers.Decode.Run(r)
return r.Error
} | go | func (r *Request) Send() error {
// Always run Complete handlers
defer func() {
r.Handlers.Complete.Run(r)
}()
// Build and Sign the request.
r.Build()
if r.Error != nil {
return r.Error
}
// Send the request. r.HTTPResponse should be populated after these handlers run.
r.Handlers.Send.Run(r)
if r.Error != nil {
return r.Error
}
// Validate the response. This is a good place to create a r.Error if
// the response is not a 2xx status code.
r.Handlers.ValidateResponse.Run(r)
if r.Error != nil {
// Run DecodeError handlers. This is a good place to add custom error response
// parsing.
r.Handlers.DecodeError.Run(r)
return r.Error
}
// Decode the response. Commonly will populate r.Data variable with a parsed response body.
r.Handlers.Decode.Run(r)
return r.Error
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"Send",
"(",
")",
"error",
"{",
"// Always run Complete handlers",
"defer",
"func",
"(",
")",
"{",
"r",
".",
"Handlers",
".",
"Complete",
".",
"Run",
"(",
"r",
")",
"\n",
"}",
"(",
")",
"\n\n",
"// Build and Sign the request.",
"r",
".",
"Build",
"(",
")",
"\n",
"if",
"r",
".",
"Error",
"!=",
"nil",
"{",
"return",
"r",
".",
"Error",
"\n",
"}",
"\n\n",
"// Send the request. r.HTTPResponse should be populated after these handlers run.",
"r",
".",
"Handlers",
".",
"Send",
".",
"Run",
"(",
"r",
")",
"\n",
"if",
"r",
".",
"Error",
"!=",
"nil",
"{",
"return",
"r",
".",
"Error",
"\n",
"}",
"\n\n",
"// Validate the response. This is a good place to create a r.Error if",
"// the response is not a 2xx status code.",
"r",
".",
"Handlers",
".",
"ValidateResponse",
".",
"Run",
"(",
"r",
")",
"\n",
"if",
"r",
".",
"Error",
"!=",
"nil",
"{",
"// Run DecodeError handlers. This is a good place to add custom error response",
"// parsing.",
"r",
".",
"Handlers",
".",
"DecodeError",
".",
"Run",
"(",
"r",
")",
"\n",
"return",
"r",
".",
"Error",
"\n",
"}",
"\n\n",
"// Decode the response. Commonly will populate r.Data variable with a parsed response body.",
"r",
".",
"Handlers",
".",
"Decode",
".",
"Run",
"(",
"r",
")",
"\n",
"return",
"r",
".",
"Error",
"\n",
"}"
] | // Send sends a request. Send manages the execution of the Handlers.
// If an error occurs during any phase, request processing stops. | [
"Send",
"sends",
"a",
"request",
".",
"Send",
"manages",
"the",
"execution",
"of",
"the",
"Handlers",
".",
"If",
"an",
"error",
"occurs",
"during",
"any",
"phase",
"request",
"processing",
"stops",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/client/request/request.go#L42-L73 |
9,709 | remind101/pkg | client/request/request.go | Build | func (r *Request) Build() {
if !r.built {
r.Handlers.Build.Run(r)
r.built = true
if r.Error != nil {
return
}
r.Handlers.Sign.Run(r)
}
} | go | func (r *Request) Build() {
if !r.built {
r.Handlers.Build.Run(r)
r.built = true
if r.Error != nil {
return
}
r.Handlers.Sign.Run(r)
}
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"Build",
"(",
")",
"{",
"if",
"!",
"r",
".",
"built",
"{",
"r",
".",
"Handlers",
".",
"Build",
".",
"Run",
"(",
"r",
")",
"\n",
"r",
".",
"built",
"=",
"true",
"\n",
"if",
"r",
".",
"Error",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"r",
".",
"Handlers",
".",
"Sign",
".",
"Run",
"(",
"r",
")",
"\n",
"}",
"\n",
"}"
] | // Build runs build handlers and then runs sign handlers. | [
"Build",
"runs",
"build",
"handlers",
"and",
"then",
"runs",
"sign",
"handlers",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/client/request/request.go#L76-L85 |
9,710 | remind101/pkg | svc/handler.go | NewStandardHandler | func NewStandardHandler(opts HandlerOpts) http.Handler {
h := httpx.Handler(opts.Router)
if opts.HandlerTimeout != 0 {
// Timeout requests after the given Timeout duration.
h = middleware.TimeoutHandler(h, opts.HandlerTimeout)
}
// Recover from panics. A panic is converted to an error. This should be first,
// even though it means panics in middleware will not be recovered, because
// later middleware expects endpoint panics to be returned as an error.
h = middleware.BasicRecover(h)
// Handler errors returned by endpoint handler or recovery middleware.
// Errors will no longer be returned after this middeware.
errorHandler := opts.ErrorHandler
if errorHandler == nil {
errorHandler = middleware.ReportingErrorHandler
}
h = middleware.HandleError(h, errorHandler)
// Add request tracing. Must go after the HandleError middleware in order
// to capture the status code written to the response.
h = middleware.OpentracingTracing(h, opts.Router)
// Insert logger into context and log requests at INFO level.
h = middleware.LogTo(h, middleware.LoggerWithRequestID)
// Add reporter to context and request to reporter context.
h = middleware.WithReporter(h, opts.Reporter)
// Add the request id to the context.
h = middleware.ExtractRequestID(h)
// Add basic auth
if opts.BasicAuth != "" {
user := strings.Split(opts.BasicAuth, ":")[0]
pass := strings.Split(opts.BasicAuth, ":")[1]
h = middleware.BasicAuth(h, user, pass, "")
}
// Adds forwarding headers from request to the context. This allows http clients
// to get those headers from the context and add them to upstream requests.
if len(opts.ForwardingHeaders) > 0 {
for _, header := range opts.ForwardingHeaders {
h = middleware.ExtractHeader(h, header)
}
}
// Wrap the route in middleware to add a context.Context. This middleware must be
// last as it acts as the adaptor between http.Handler and httpx.Handler.
return middleware.BackgroundContext(h)
} | go | func NewStandardHandler(opts HandlerOpts) http.Handler {
h := httpx.Handler(opts.Router)
if opts.HandlerTimeout != 0 {
// Timeout requests after the given Timeout duration.
h = middleware.TimeoutHandler(h, opts.HandlerTimeout)
}
// Recover from panics. A panic is converted to an error. This should be first,
// even though it means panics in middleware will not be recovered, because
// later middleware expects endpoint panics to be returned as an error.
h = middleware.BasicRecover(h)
// Handler errors returned by endpoint handler or recovery middleware.
// Errors will no longer be returned after this middeware.
errorHandler := opts.ErrorHandler
if errorHandler == nil {
errorHandler = middleware.ReportingErrorHandler
}
h = middleware.HandleError(h, errorHandler)
// Add request tracing. Must go after the HandleError middleware in order
// to capture the status code written to the response.
h = middleware.OpentracingTracing(h, opts.Router)
// Insert logger into context and log requests at INFO level.
h = middleware.LogTo(h, middleware.LoggerWithRequestID)
// Add reporter to context and request to reporter context.
h = middleware.WithReporter(h, opts.Reporter)
// Add the request id to the context.
h = middleware.ExtractRequestID(h)
// Add basic auth
if opts.BasicAuth != "" {
user := strings.Split(opts.BasicAuth, ":")[0]
pass := strings.Split(opts.BasicAuth, ":")[1]
h = middleware.BasicAuth(h, user, pass, "")
}
// Adds forwarding headers from request to the context. This allows http clients
// to get those headers from the context and add them to upstream requests.
if len(opts.ForwardingHeaders) > 0 {
for _, header := range opts.ForwardingHeaders {
h = middleware.ExtractHeader(h, header)
}
}
// Wrap the route in middleware to add a context.Context. This middleware must be
// last as it acts as the adaptor between http.Handler and httpx.Handler.
return middleware.BackgroundContext(h)
} | [
"func",
"NewStandardHandler",
"(",
"opts",
"HandlerOpts",
")",
"http",
".",
"Handler",
"{",
"h",
":=",
"httpx",
".",
"Handler",
"(",
"opts",
".",
"Router",
")",
"\n\n",
"if",
"opts",
".",
"HandlerTimeout",
"!=",
"0",
"{",
"// Timeout requests after the given Timeout duration.",
"h",
"=",
"middleware",
".",
"TimeoutHandler",
"(",
"h",
",",
"opts",
".",
"HandlerTimeout",
")",
"\n",
"}",
"\n\n",
"// Recover from panics. A panic is converted to an error. This should be first,",
"// even though it means panics in middleware will not be recovered, because",
"// later middleware expects endpoint panics to be returned as an error.",
"h",
"=",
"middleware",
".",
"BasicRecover",
"(",
"h",
")",
"\n\n",
"// Handler errors returned by endpoint handler or recovery middleware.",
"// Errors will no longer be returned after this middeware.",
"errorHandler",
":=",
"opts",
".",
"ErrorHandler",
"\n",
"if",
"errorHandler",
"==",
"nil",
"{",
"errorHandler",
"=",
"middleware",
".",
"ReportingErrorHandler",
"\n",
"}",
"\n",
"h",
"=",
"middleware",
".",
"HandleError",
"(",
"h",
",",
"errorHandler",
")",
"\n\n",
"// Add request tracing. Must go after the HandleError middleware in order",
"// to capture the status code written to the response.",
"h",
"=",
"middleware",
".",
"OpentracingTracing",
"(",
"h",
",",
"opts",
".",
"Router",
")",
"\n\n",
"// Insert logger into context and log requests at INFO level.",
"h",
"=",
"middleware",
".",
"LogTo",
"(",
"h",
",",
"middleware",
".",
"LoggerWithRequestID",
")",
"\n\n",
"// Add reporter to context and request to reporter context.",
"h",
"=",
"middleware",
".",
"WithReporter",
"(",
"h",
",",
"opts",
".",
"Reporter",
")",
"\n\n",
"// Add the request id to the context.",
"h",
"=",
"middleware",
".",
"ExtractRequestID",
"(",
"h",
")",
"\n\n",
"// Add basic auth",
"if",
"opts",
".",
"BasicAuth",
"!=",
"\"",
"\"",
"{",
"user",
":=",
"strings",
".",
"Split",
"(",
"opts",
".",
"BasicAuth",
",",
"\"",
"\"",
")",
"[",
"0",
"]",
"\n",
"pass",
":=",
"strings",
".",
"Split",
"(",
"opts",
".",
"BasicAuth",
",",
"\"",
"\"",
")",
"[",
"1",
"]",
"\n",
"h",
"=",
"middleware",
".",
"BasicAuth",
"(",
"h",
",",
"user",
",",
"pass",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Adds forwarding headers from request to the context. This allows http clients",
"// to get those headers from the context and add them to upstream requests.",
"if",
"len",
"(",
"opts",
".",
"ForwardingHeaders",
")",
">",
"0",
"{",
"for",
"_",
",",
"header",
":=",
"range",
"opts",
".",
"ForwardingHeaders",
"{",
"h",
"=",
"middleware",
".",
"ExtractHeader",
"(",
"h",
",",
"header",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Wrap the route in middleware to add a context.Context. This middleware must be",
"// last as it acts as the adaptor between http.Handler and httpx.Handler.",
"return",
"middleware",
".",
"BackgroundContext",
"(",
"h",
")",
"\n",
"}"
] | // NewStandardHandler returns an http.Handler with a standard middleware stack.
// The last middleware added is the first middleware to handle the request.
// Order is pretty important as some middleware depends on others having run
// already. | [
"NewStandardHandler",
"returns",
"an",
"http",
".",
"Handler",
"with",
"a",
"standard",
"middleware",
"stack",
".",
"The",
"last",
"middleware",
"added",
"is",
"the",
"first",
"middleware",
"to",
"handle",
"the",
"request",
".",
"Order",
"is",
"pretty",
"important",
"as",
"some",
"middleware",
"depends",
"on",
"others",
"having",
"run",
"already",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/svc/handler.go#L46-L98 |
9,711 | remind101/pkg | metrics/runtime.go | ReportRuntimeMetrics | func ReportRuntimeMetrics() {
var memstats runtime.MemStats
runtime.ReadMemStats(&memstats)
numGoroutines := runtime.NumGoroutine()
r := map[string]float64{
"goroutine": float64(numGoroutines),
"runtime.MemStats.Alloc": float64(memstats.Alloc),
"runtime.MemStats.Frees": float64(memstats.Frees),
"runtime.MemStats.HeapAlloc": float64(memstats.HeapAlloc),
"runtime.MemStats.HeapIdle": float64(memstats.HeapIdle),
"runtime.MemStats.HeapObjects": float64(memstats.HeapObjects),
"runtime.MemStats.HeapReleased": float64(memstats.HeapReleased),
"runtime.MemStats.HeapSys": float64(memstats.HeapSys),
"runtime.MemStats.LastGC": float64(memstats.LastGC),
"runtime.MemStats.Lookups": float64(memstats.Lookups),
"runtime.MemStats.Mallocs": float64(memstats.Mallocs),
"runtime.MemStats.MCacheInuse": float64(memstats.MCacheInuse),
"runtime.MemStats.MCacheSys": float64(memstats.MCacheSys),
"runtime.MemStats.MSpanInuse": float64(memstats.MSpanInuse),
"runtime.MemStats.MSpanSys": float64(memstats.MSpanSys),
"runtime.MemStats.NextGC": float64(memstats.NextGC),
"runtime.MemStats.NumGC": float64(memstats.NumGC),
"runtime.MemStats.PauseTotalMs": float64(memstats.PauseTotalNs) / float64(time.Millisecond),
"runtime.MemStats.StackInuse": float64(memstats.StackInuse),
}
for name, value := range r {
Gauge(name, value, nil, 1.0)
}
} | go | func ReportRuntimeMetrics() {
var memstats runtime.MemStats
runtime.ReadMemStats(&memstats)
numGoroutines := runtime.NumGoroutine()
r := map[string]float64{
"goroutine": float64(numGoroutines),
"runtime.MemStats.Alloc": float64(memstats.Alloc),
"runtime.MemStats.Frees": float64(memstats.Frees),
"runtime.MemStats.HeapAlloc": float64(memstats.HeapAlloc),
"runtime.MemStats.HeapIdle": float64(memstats.HeapIdle),
"runtime.MemStats.HeapObjects": float64(memstats.HeapObjects),
"runtime.MemStats.HeapReleased": float64(memstats.HeapReleased),
"runtime.MemStats.HeapSys": float64(memstats.HeapSys),
"runtime.MemStats.LastGC": float64(memstats.LastGC),
"runtime.MemStats.Lookups": float64(memstats.Lookups),
"runtime.MemStats.Mallocs": float64(memstats.Mallocs),
"runtime.MemStats.MCacheInuse": float64(memstats.MCacheInuse),
"runtime.MemStats.MCacheSys": float64(memstats.MCacheSys),
"runtime.MemStats.MSpanInuse": float64(memstats.MSpanInuse),
"runtime.MemStats.MSpanSys": float64(memstats.MSpanSys),
"runtime.MemStats.NextGC": float64(memstats.NextGC),
"runtime.MemStats.NumGC": float64(memstats.NumGC),
"runtime.MemStats.PauseTotalMs": float64(memstats.PauseTotalNs) / float64(time.Millisecond),
"runtime.MemStats.StackInuse": float64(memstats.StackInuse),
}
for name, value := range r {
Gauge(name, value, nil, 1.0)
}
} | [
"func",
"ReportRuntimeMetrics",
"(",
")",
"{",
"var",
"memstats",
"runtime",
".",
"MemStats",
"\n",
"runtime",
".",
"ReadMemStats",
"(",
"&",
"memstats",
")",
"\n",
"numGoroutines",
":=",
"runtime",
".",
"NumGoroutine",
"(",
")",
"\n\n",
"r",
":=",
"map",
"[",
"string",
"]",
"float64",
"{",
"\"",
"\"",
":",
"float64",
"(",
"numGoroutines",
")",
",",
"\"",
"\"",
":",
"float64",
"(",
"memstats",
".",
"Alloc",
")",
",",
"\"",
"\"",
":",
"float64",
"(",
"memstats",
".",
"Frees",
")",
",",
"\"",
"\"",
":",
"float64",
"(",
"memstats",
".",
"HeapAlloc",
")",
",",
"\"",
"\"",
":",
"float64",
"(",
"memstats",
".",
"HeapIdle",
")",
",",
"\"",
"\"",
":",
"float64",
"(",
"memstats",
".",
"HeapObjects",
")",
",",
"\"",
"\"",
":",
"float64",
"(",
"memstats",
".",
"HeapReleased",
")",
",",
"\"",
"\"",
":",
"float64",
"(",
"memstats",
".",
"HeapSys",
")",
",",
"\"",
"\"",
":",
"float64",
"(",
"memstats",
".",
"LastGC",
")",
",",
"\"",
"\"",
":",
"float64",
"(",
"memstats",
".",
"Lookups",
")",
",",
"\"",
"\"",
":",
"float64",
"(",
"memstats",
".",
"Mallocs",
")",
",",
"\"",
"\"",
":",
"float64",
"(",
"memstats",
".",
"MCacheInuse",
")",
",",
"\"",
"\"",
":",
"float64",
"(",
"memstats",
".",
"MCacheSys",
")",
",",
"\"",
"\"",
":",
"float64",
"(",
"memstats",
".",
"MSpanInuse",
")",
",",
"\"",
"\"",
":",
"float64",
"(",
"memstats",
".",
"MSpanSys",
")",
",",
"\"",
"\"",
":",
"float64",
"(",
"memstats",
".",
"NextGC",
")",
",",
"\"",
"\"",
":",
"float64",
"(",
"memstats",
".",
"NumGC",
")",
",",
"\"",
"\"",
":",
"float64",
"(",
"memstats",
".",
"PauseTotalNs",
")",
"/",
"float64",
"(",
"time",
".",
"Millisecond",
")",
",",
"\"",
"\"",
":",
"float64",
"(",
"memstats",
".",
"StackInuse",
")",
",",
"}",
"\n\n",
"for",
"name",
",",
"value",
":=",
"range",
"r",
"{",
"Gauge",
"(",
"name",
",",
"value",
",",
"nil",
",",
"1.0",
")",
"\n",
"}",
"\n",
"}"
] | // Samples and reports current runtime status once. | [
"Samples",
"and",
"reports",
"current",
"runtime",
"status",
"once",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/metrics/runtime.go#L27-L57 |
9,712 | remind101/pkg | svc/server.go | WithPort | func WithPort(port string) NewServerOpt {
return func(srv *http.Server) {
srv.Addr = ":" + port
}
} | go | func WithPort(port string) NewServerOpt {
return func(srv *http.Server) {
srv.Addr = ":" + port
}
} | [
"func",
"WithPort",
"(",
"port",
"string",
")",
"NewServerOpt",
"{",
"return",
"func",
"(",
"srv",
"*",
"http",
".",
"Server",
")",
"{",
"srv",
".",
"Addr",
"=",
"\"",
"\"",
"+",
"port",
"\n",
"}",
"\n",
"}"
] | // WithPort sets the port for the server to run on. | [
"WithPort",
"sets",
"the",
"port",
"for",
"the",
"server",
"to",
"run",
"on",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/svc/server.go#L25-L29 |
9,713 | remind101/pkg | svc/server.go | NewServer | func NewServer(h http.Handler, opts ...NewServerOpt) *http.Server {
srv := &http.Server{Handler: h}
// Prepend defaults to server options.
opts = append([]NewServerOpt{ServerDefaults}, opts...)
for _, opt := range opts {
opt(srv)
}
return srv
} | go | func NewServer(h http.Handler, opts ...NewServerOpt) *http.Server {
srv := &http.Server{Handler: h}
// Prepend defaults to server options.
opts = append([]NewServerOpt{ServerDefaults}, opts...)
for _, opt := range opts {
opt(srv)
}
return srv
} | [
"func",
"NewServer",
"(",
"h",
"http",
".",
"Handler",
",",
"opts",
"...",
"NewServerOpt",
")",
"*",
"http",
".",
"Server",
"{",
"srv",
":=",
"&",
"http",
".",
"Server",
"{",
"Handler",
":",
"h",
"}",
"\n\n",
"// Prepend defaults to server options.",
"opts",
"=",
"append",
"(",
"[",
"]",
"NewServerOpt",
"{",
"ServerDefaults",
"}",
",",
"opts",
"...",
")",
"\n",
"for",
"_",
",",
"opt",
":=",
"range",
"opts",
"{",
"opt",
"(",
"srv",
")",
"\n",
"}",
"\n\n",
"return",
"srv",
"\n",
"}"
] | // NewServer offers some convenience and good defaults for creating an http.Server | [
"NewServer",
"offers",
"some",
"convenience",
"and",
"good",
"defaults",
"for",
"creating",
"an",
"http",
".",
"Server"
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/svc/server.go#L32-L42 |
9,714 | remind101/pkg | svc/server.go | RunServer | func RunServer(srv *http.Server, shutdownFuncs ...func()) {
done := make(chan struct{})
go func() {
// Handle SIGINT and SIGTERM.
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
sig := <-sigCh
fmt.Println("Received signal, stopping.", "signal", sig)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
// We received an interrupt signal, shut down.
if err := srv.Shutdown(ctx); err != nil {
// Error from closing listeners, or context timeout:
fmt.Printf("HTTP server Shutdown: %v\n", err)
}
// Run shutdown functions
for _, sf := range shutdownFuncs {
sf()
}
close(done)
}()
fmt.Printf("HTTP server listening on address: \"%s\"\n", srv.Addr)
if err := srv.ListenAndServe(); err != http.ErrServerClosed {
// Error starting or closing listener:
fmt.Printf("HTTP server ListenAndServe: %v\n", err)
os.Exit(1)
}
<-done
} | go | func RunServer(srv *http.Server, shutdownFuncs ...func()) {
done := make(chan struct{})
go func() {
// Handle SIGINT and SIGTERM.
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
sig := <-sigCh
fmt.Println("Received signal, stopping.", "signal", sig)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
// We received an interrupt signal, shut down.
if err := srv.Shutdown(ctx); err != nil {
// Error from closing listeners, or context timeout:
fmt.Printf("HTTP server Shutdown: %v\n", err)
}
// Run shutdown functions
for _, sf := range shutdownFuncs {
sf()
}
close(done)
}()
fmt.Printf("HTTP server listening on address: \"%s\"\n", srv.Addr)
if err := srv.ListenAndServe(); err != http.ErrServerClosed {
// Error starting or closing listener:
fmt.Printf("HTTP server ListenAndServe: %v\n", err)
os.Exit(1)
}
<-done
} | [
"func",
"RunServer",
"(",
"srv",
"*",
"http",
".",
"Server",
",",
"shutdownFuncs",
"...",
"func",
"(",
")",
")",
"{",
"done",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n\n",
"go",
"func",
"(",
")",
"{",
"// Handle SIGINT and SIGTERM.",
"sigCh",
":=",
"make",
"(",
"chan",
"os",
".",
"Signal",
",",
"1",
")",
"\n",
"signal",
".",
"Notify",
"(",
"sigCh",
",",
"syscall",
".",
"SIGINT",
",",
"syscall",
".",
"SIGTERM",
")",
"\n\n",
"sig",
":=",
"<-",
"sigCh",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"sig",
")",
"\n\n",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"context",
".",
"Background",
"(",
")",
",",
"5",
"*",
"time",
".",
"Second",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n\n",
"// We received an interrupt signal, shut down.",
"if",
"err",
":=",
"srv",
".",
"Shutdown",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"// Error from closing listeners, or context timeout:",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"// Run shutdown functions",
"for",
"_",
",",
"sf",
":=",
"range",
"shutdownFuncs",
"{",
"sf",
"(",
")",
"\n",
"}",
"\n\n",
"close",
"(",
"done",
")",
"\n",
"}",
"(",
")",
"\n\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\\"",
"\\\"",
"\\n",
"\"",
",",
"srv",
".",
"Addr",
")",
"\n",
"if",
"err",
":=",
"srv",
".",
"ListenAndServe",
"(",
")",
";",
"err",
"!=",
"http",
".",
"ErrServerClosed",
"{",
"// Error starting or closing listener:",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"err",
")",
"\n",
"os",
".",
"Exit",
"(",
"1",
")",
"\n",
"}",
"\n\n",
"<-",
"done",
"\n",
"}"
] | // RunServer handles the biolerplate of starting an http server and handling
// signals gracefully. | [
"RunServer",
"handles",
"the",
"biolerplate",
"of",
"starting",
"an",
"http",
"server",
"and",
"handling",
"signals",
"gracefully",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/svc/server.go#L46-L81 |
9,715 | remind101/pkg | metrics/metrics.go | SetEmpireDefaultTags | func SetEmpireDefaultTags() {
defaultTags["empire.app.name"] = os.Getenv("EMPIRE_APPNAME")
defaultTags["empire.app.process"] = os.Getenv("EMPIRE_PROCESS")
defaultTags["empire.app.release"] = os.Getenv("EMPIRE_RELEASE")
} | go | func SetEmpireDefaultTags() {
defaultTags["empire.app.name"] = os.Getenv("EMPIRE_APPNAME")
defaultTags["empire.app.process"] = os.Getenv("EMPIRE_PROCESS")
defaultTags["empire.app.release"] = os.Getenv("EMPIRE_RELEASE")
} | [
"func",
"SetEmpireDefaultTags",
"(",
")",
"{",
"defaultTags",
"[",
"\"",
"\"",
"]",
"=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
"\n",
"defaultTags",
"[",
"\"",
"\"",
"]",
"=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
"\n",
"defaultTags",
"[",
"\"",
"\"",
"]",
"=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // SetEmpireDefaultTags sets default tags reflecting the empire environment to each metric | [
"SetEmpireDefaultTags",
"sets",
"default",
"tags",
"reflecting",
"the",
"empire",
"environment",
"to",
"each",
"metric"
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/metrics/metrics.go#L30-L34 |
9,716 | remind101/pkg | httpx/router.go | Handle | func (r *Router) Handle(path string, h Handler) *Route {
return r.getOrCreateRoute(r.mux.Handle(path, r.handler(h)), path)
} | go | func (r *Router) Handle(path string, h Handler) *Route {
return r.getOrCreateRoute(r.mux.Handle(path, r.handler(h)), path)
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Handle",
"(",
"path",
"string",
",",
"h",
"Handler",
")",
"*",
"Route",
"{",
"return",
"r",
".",
"getOrCreateRoute",
"(",
"r",
".",
"mux",
".",
"Handle",
"(",
"path",
",",
"r",
".",
"handler",
"(",
"h",
")",
")",
",",
"path",
")",
"\n",
"}"
] | // Handle registers a new route with a matcher for the URL path | [
"Handle",
"registers",
"a",
"new",
"route",
"with",
"a",
"matcher",
"for",
"the",
"URL",
"path"
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/httpx/router.go#L35-L37 |
9,717 | remind101/pkg | httpx/router.go | HandleFunc | func (r *Router) HandleFunc(path string, f func(context.Context, http.ResponseWriter, *http.Request) error) *Route {
return r.Handle(path, HandlerFunc(f))
} | go | func (r *Router) HandleFunc(path string, f func(context.Context, http.ResponseWriter, *http.Request) error) *Route {
return r.Handle(path, HandlerFunc(f))
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"HandleFunc",
"(",
"path",
"string",
",",
"f",
"func",
"(",
"context",
".",
"Context",
",",
"http",
".",
"ResponseWriter",
",",
"*",
"http",
".",
"Request",
")",
"error",
")",
"*",
"Route",
"{",
"return",
"r",
".",
"Handle",
"(",
"path",
",",
"HandlerFunc",
"(",
"f",
")",
")",
"\n",
"}"
] | // HandleFunc registers a new route with a matcher for the URL path | [
"HandleFunc",
"registers",
"a",
"new",
"route",
"with",
"a",
"matcher",
"for",
"the",
"URL",
"path"
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/httpx/router.go#L40-L42 |
9,718 | remind101/pkg | httpx/router.go | Headers | func (r *Router) Headers(pairs ...string) *Route {
return r.getOrCreateRoute(r.mux.Headers(pairs...), "")
} | go | func (r *Router) Headers(pairs ...string) *Route {
return r.getOrCreateRoute(r.mux.Headers(pairs...), "")
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Headers",
"(",
"pairs",
"...",
"string",
")",
"*",
"Route",
"{",
"return",
"r",
".",
"getOrCreateRoute",
"(",
"r",
".",
"mux",
".",
"Headers",
"(",
"pairs",
"...",
")",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // Header adds a route that will be used if the header value matches. | [
"Header",
"adds",
"a",
"route",
"that",
"will",
"be",
"used",
"if",
"the",
"header",
"value",
"matches",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/httpx/router.go#L45-L47 |
9,719 | remind101/pkg | httpx/router.go | Match | func (r *Router) Match(f func(*http.Request) bool, h Handler) {
matcher := func(r *http.Request, rm *mux.RouteMatch) bool {
return f(r)
}
r.mux.MatcherFunc(matcher).Handler(r.handler(h))
} | go | func (r *Router) Match(f func(*http.Request) bool, h Handler) {
matcher := func(r *http.Request, rm *mux.RouteMatch) bool {
return f(r)
}
r.mux.MatcherFunc(matcher).Handler(r.handler(h))
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Match",
"(",
"f",
"func",
"(",
"*",
"http",
".",
"Request",
")",
"bool",
",",
"h",
"Handler",
")",
"{",
"matcher",
":=",
"func",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"rm",
"*",
"mux",
".",
"RouteMatch",
")",
"bool",
"{",
"return",
"f",
"(",
"r",
")",
"\n",
"}",
"\n\n",
"r",
".",
"mux",
".",
"MatcherFunc",
"(",
"matcher",
")",
".",
"Handler",
"(",
"r",
".",
"handler",
"(",
"h",
")",
")",
"\n",
"}"
] | // Match adds a route that will be matched if f returns true. | [
"Match",
"adds",
"a",
"route",
"that",
"will",
"be",
"matched",
"if",
"f",
"returns",
"true",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/httpx/router.go#L50-L56 |
9,720 | remind101/pkg | httpx/router.go | Path | func (r *Router) Path(path string) *Route {
return r.getOrCreateRoute(r.mux.Path(path), path)
} | go | func (r *Router) Path(path string) *Route {
return r.getOrCreateRoute(r.mux.Path(path), path)
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Path",
"(",
"path",
"string",
")",
"*",
"Route",
"{",
"return",
"r",
".",
"getOrCreateRoute",
"(",
"r",
".",
"mux",
".",
"Path",
"(",
"path",
")",
",",
"path",
")",
"\n",
"}"
] | // Path registers a new route with a matcher for the URL path. | [
"Path",
"registers",
"a",
"new",
"route",
"with",
"a",
"matcher",
"for",
"the",
"URL",
"path",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/httpx/router.go#L59-L61 |
9,721 | remind101/pkg | httpx/router.go | getOrCreateRoute | func (r *Router) getOrCreateRoute(muxRoute *mux.Route, pathTpl string) *Route {
if route, ok := r.routes[muxRoute]; !ok {
route = &Route{muxRoute, pathTpl}
r.routes[muxRoute] = route
} else if pathTpl != "" {
route.pathTpl = pathTpl
}
return r.routes[muxRoute]
} | go | func (r *Router) getOrCreateRoute(muxRoute *mux.Route, pathTpl string) *Route {
if route, ok := r.routes[muxRoute]; !ok {
route = &Route{muxRoute, pathTpl}
r.routes[muxRoute] = route
} else if pathTpl != "" {
route.pathTpl = pathTpl
}
return r.routes[muxRoute]
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"getOrCreateRoute",
"(",
"muxRoute",
"*",
"mux",
".",
"Route",
",",
"pathTpl",
"string",
")",
"*",
"Route",
"{",
"if",
"route",
",",
"ok",
":=",
"r",
".",
"routes",
"[",
"muxRoute",
"]",
";",
"!",
"ok",
"{",
"route",
"=",
"&",
"Route",
"{",
"muxRoute",
",",
"pathTpl",
"}",
"\n",
"r",
".",
"routes",
"[",
"muxRoute",
"]",
"=",
"route",
"\n",
"}",
"else",
"if",
"pathTpl",
"!=",
"\"",
"\"",
"{",
"route",
".",
"pathTpl",
"=",
"pathTpl",
"\n",
"}",
"\n",
"return",
"r",
".",
"routes",
"[",
"muxRoute",
"]",
"\n",
"}"
] | // Caches the routes so we have access to the original path template. | [
"Caches",
"the",
"routes",
"so",
"we",
"have",
"access",
"to",
"the",
"original",
"path",
"template",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/httpx/router.go#L64-L72 |
9,722 | remind101/pkg | httpx/router.go | Vars | func Vars(ctx context.Context) map[string]string {
vars, ok := ctx.Value(varsKey).(map[string]string)
if !ok {
return map[string]string{}
}
return vars
} | go | func Vars(ctx context.Context) map[string]string {
vars, ok := ctx.Value(varsKey).(map[string]string)
if !ok {
return map[string]string{}
}
return vars
} | [
"func",
"Vars",
"(",
"ctx",
"context",
".",
"Context",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"vars",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"varsKey",
")",
".",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
"\n",
"}",
"\n\n",
"return",
"vars",
"\n",
"}"
] | // Vars extracts the route vars from a context.Context. | [
"Vars",
"extracts",
"the",
"route",
"vars",
"from",
"a",
"context",
".",
"Context",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/httpx/router.go#L111-L118 |
9,723 | remind101/pkg | httpx/router.go | WithVars | func WithVars(ctx context.Context, vars map[string]string) context.Context {
return context.WithValue(ctx, varsKey, vars)
} | go | func WithVars(ctx context.Context, vars map[string]string) context.Context {
return context.WithValue(ctx, varsKey, vars)
} | [
"func",
"WithVars",
"(",
"ctx",
"context",
".",
"Context",
",",
"vars",
"map",
"[",
"string",
"]",
"string",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"varsKey",
",",
"vars",
")",
"\n",
"}"
] | // WithVars adds the vars to the context.Context. | [
"WithVars",
"adds",
"the",
"vars",
"to",
"the",
"context",
".",
"Context",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/httpx/router.go#L121-L123 |
9,724 | remind101/pkg | httpx/router.go | WithRoute | func WithRoute(ctx context.Context, r *Route) context.Context {
return context.WithValue(ctx, routeKey, r)
} | go | func WithRoute(ctx context.Context, r *Route) context.Context {
return context.WithValue(ctx, routeKey, r)
} | [
"func",
"WithRoute",
"(",
"ctx",
"context",
".",
"Context",
",",
"r",
"*",
"Route",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"routeKey",
",",
"r",
")",
"\n",
"}"
] | // WithVars adds the current Route to the context.Context. | [
"WithVars",
"adds",
"the",
"current",
"Route",
"to",
"the",
"context",
".",
"Context",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/httpx/router.go#L126-L128 |
9,725 | remind101/pkg | httpx/router.go | RouteFromContext | func RouteFromContext(ctx context.Context) *Route {
r, _ := ctx.Value(routeKey).(*Route)
return r
} | go | func RouteFromContext(ctx context.Context) *Route {
r, _ := ctx.Value(routeKey).(*Route)
return r
} | [
"func",
"RouteFromContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"*",
"Route",
"{",
"r",
",",
"_",
":=",
"ctx",
".",
"Value",
"(",
"routeKey",
")",
".",
"(",
"*",
"Route",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // RouteFromContext extracts the current Route from a context.Context. | [
"RouteFromContext",
"extracts",
"the",
"current",
"Route",
"from",
"a",
"context",
".",
"Context",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/httpx/router.go#L139-L142 |
9,726 | remind101/pkg | httpx/router.go | HandlerFunc | func (r *Route) HandlerFunc(f func(context.Context, http.ResponseWriter, *http.Request) error) *Route {
return r.Handler(HandlerFunc(f))
} | go | func (r *Route) HandlerFunc(f func(context.Context, http.ResponseWriter, *http.Request) error) *Route {
return r.Handler(HandlerFunc(f))
} | [
"func",
"(",
"r",
"*",
"Route",
")",
"HandlerFunc",
"(",
"f",
"func",
"(",
"context",
".",
"Context",
",",
"http",
".",
"ResponseWriter",
",",
"*",
"http",
".",
"Request",
")",
"error",
")",
"*",
"Route",
"{",
"return",
"r",
".",
"Handler",
"(",
"HandlerFunc",
"(",
"f",
")",
")",
"\n",
"}"
] | // HandlerFunc sets the httpx.Handler for this route. | [
"HandlerFunc",
"sets",
"the",
"httpx",
".",
"Handler",
"for",
"this",
"route",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/httpx/router.go#L153-L155 |
9,727 | remind101/pkg | httpx/router.go | Handler | func (r *Route) Handler(h Handler) *Route {
r.route.Handler(r.handler(h))
return r
} | go | func (r *Route) Handler(h Handler) *Route {
r.route.Handler(r.handler(h))
return r
} | [
"func",
"(",
"r",
"*",
"Route",
")",
"Handler",
"(",
"h",
"Handler",
")",
"*",
"Route",
"{",
"r",
".",
"route",
".",
"Handler",
"(",
"r",
".",
"handler",
"(",
"h",
")",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // Handler sets the httpx.Handler for this route. | [
"Handler",
"sets",
"the",
"httpx",
".",
"Handler",
"for",
"this",
"route",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/httpx/router.go#L158-L161 |
9,728 | remind101/pkg | httpx/router.go | Name | func (r *Route) Name(name string) *Route {
r.route.Name(name)
return r
} | go | func (r *Route) Name(name string) *Route {
r.route.Name(name)
return r
} | [
"func",
"(",
"r",
"*",
"Route",
")",
"Name",
"(",
"name",
"string",
")",
"*",
"Route",
"{",
"r",
".",
"route",
".",
"Name",
"(",
"name",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // Name sets the name for the route, used to build URLs.
// If the name was registered already it will be overwritten. | [
"Name",
"sets",
"the",
"name",
"for",
"the",
"route",
"used",
"to",
"build",
"URLs",
".",
"If",
"the",
"name",
"was",
"registered",
"already",
"it",
"will",
"be",
"overwritten",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/httpx/router.go#L165-L168 |
9,729 | remind101/pkg | httpx/router.go | URL | func (r *Route) URL(pairs ...string) (*url.URL, error) {
return r.route.URL(pairs...)
} | go | func (r *Route) URL(pairs ...string) (*url.URL, error) {
return r.route.URL(pairs...)
} | [
"func",
"(",
"r",
"*",
"Route",
")",
"URL",
"(",
"pairs",
"...",
"string",
")",
"(",
"*",
"url",
".",
"URL",
",",
"error",
")",
"{",
"return",
"r",
".",
"route",
".",
"URL",
"(",
"pairs",
"...",
")",
"\n",
"}"
] | // See mux.Route.URL. | [
"See",
"mux",
".",
"Route",
".",
"URL",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/httpx/router.go#L176-L178 |
9,730 | remind101/pkg | httpx/router.go | ServeHTTP | func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
panic(fmt.Sprintf("httpx: ServeHTTP called on %v", h))
} | go | func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
panic(fmt.Sprintf("httpx: ServeHTTP called on %v", h))
} | [
"func",
"(",
"h",
"*",
"handler",
")",
"ServeHTTP",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"h",
")",
")",
"\n",
"}"
] | // ServeHTTP implements the http.Handler interface. This method is never
// actually called by this package, it's only used as a means to pass a Handler
// in and out of mux. | [
"ServeHTTP",
"implements",
"the",
"http",
".",
"Handler",
"interface",
".",
"This",
"method",
"is",
"never",
"actually",
"called",
"by",
"this",
"package",
"it",
"s",
"only",
"used",
"as",
"a",
"means",
"to",
"pass",
"a",
"Handler",
"in",
"and",
"out",
"of",
"mux",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/httpx/router.go#L205-L207 |
9,731 | remind101/pkg | counting/probabilistic_counter.go | Add | func (pc *ProbabilisticCounter) Add(values ...string) {
for _, value := range values {
pc.bitset.Set(pc.bitIndex(value))
}
} | go | func (pc *ProbabilisticCounter) Add(values ...string) {
for _, value := range values {
pc.bitset.Set(pc.bitIndex(value))
}
} | [
"func",
"(",
"pc",
"*",
"ProbabilisticCounter",
")",
"Add",
"(",
"values",
"...",
"string",
")",
"{",
"for",
"_",
",",
"value",
":=",
"range",
"values",
"{",
"pc",
".",
"bitset",
".",
"Set",
"(",
"pc",
".",
"bitIndex",
"(",
"value",
")",
")",
"\n",
"}",
"\n",
"}"
] | // It adds one or more string values to this counter. | [
"It",
"adds",
"one",
"or",
"more",
"string",
"values",
"to",
"this",
"counter",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/counting/probabilistic_counter.go#L67-L71 |
9,732 | remind101/pkg | counting/probabilistic_counter.go | Bytes | func (pc *ProbabilisticCounter) Bytes() ([]byte, error) {
bytes, err := pc.bitset.MarshalBinary()
if err != nil {
return nil, errors.Wrap(err, "Unable to serialize ProbabilisticCounter into binary data")
}
return bytes, nil
} | go | func (pc *ProbabilisticCounter) Bytes() ([]byte, error) {
bytes, err := pc.bitset.MarshalBinary()
if err != nil {
return nil, errors.Wrap(err, "Unable to serialize ProbabilisticCounter into binary data")
}
return bytes, nil
} | [
"func",
"(",
"pc",
"*",
"ProbabilisticCounter",
")",
"Bytes",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"bytes",
",",
"err",
":=",
"pc",
".",
"bitset",
".",
"MarshalBinary",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"bytes",
",",
"nil",
"\n",
"}"
] | // It serializes this ProbabilisticCounter into a slice of bytes, which can be used to persist this data structure. | [
"It",
"serializes",
"this",
"ProbabilisticCounter",
"into",
"a",
"slice",
"of",
"bytes",
"which",
"can",
"be",
"used",
"to",
"persist",
"this",
"data",
"structure",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/counting/probabilistic_counter.go#L83-L89 |
9,733 | remind101/pkg | counting/probabilistic_counter.go | lengthForCardinality | func lengthForCardinality(cardinality int) uint {
length := closestBase2(cardinality) * loadFactor
var minLength = math.Exp2(16) // 8kb
var maxLength = math.Exp2(20) // 128kb
return uint(math.Max(minLength, math.Min(length, maxLength)))
} | go | func lengthForCardinality(cardinality int) uint {
length := closestBase2(cardinality) * loadFactor
var minLength = math.Exp2(16) // 8kb
var maxLength = math.Exp2(20) // 128kb
return uint(math.Max(minLength, math.Min(length, maxLength)))
} | [
"func",
"lengthForCardinality",
"(",
"cardinality",
"int",
")",
"uint",
"{",
"length",
":=",
"closestBase2",
"(",
"cardinality",
")",
"*",
"loadFactor",
"\n",
"var",
"minLength",
"=",
"math",
".",
"Exp2",
"(",
"16",
")",
"// 8kb",
"\n",
"var",
"maxLength",
"=",
"math",
".",
"Exp2",
"(",
"20",
")",
"// 128kb",
"\n",
"return",
"uint",
"(",
"math",
".",
"Max",
"(",
"minLength",
",",
"math",
".",
"Min",
"(",
"length",
",",
"maxLength",
")",
")",
")",
"\n",
"}"
] | // bit map length is proportinal to the estimated cardinality, it can be between 8 and 128kb,
// those numbers were chosen in order to achieve a relatively low error rate while keeping a low memory usage. | [
"bit",
"map",
"length",
"is",
"proportinal",
"to",
"the",
"estimated",
"cardinality",
"it",
"can",
"be",
"between",
"8",
"and",
"128kb",
"those",
"numbers",
"were",
"chosen",
"in",
"order",
"to",
"achieve",
"a",
"relatively",
"low",
"error",
"rate",
"while",
"keeping",
"a",
"low",
"memory",
"usage",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/counting/probabilistic_counter.go#L100-L105 |
9,734 | remind101/pkg | counting/probabilistic_counter.go | bitIndex | func (pc *ProbabilisticCounter) bitIndex(value string) uint {
h := fnv.New32a()
h.Write([]byte(value))
return uint(h.Sum32()) % pc.bitset.Len()
} | go | func (pc *ProbabilisticCounter) bitIndex(value string) uint {
h := fnv.New32a()
h.Write([]byte(value))
return uint(h.Sum32()) % pc.bitset.Len()
} | [
"func",
"(",
"pc",
"*",
"ProbabilisticCounter",
")",
"bitIndex",
"(",
"value",
"string",
")",
"uint",
"{",
"h",
":=",
"fnv",
".",
"New32a",
"(",
")",
"\n",
"h",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"value",
")",
")",
"\n",
"return",
"uint",
"(",
"h",
".",
"Sum32",
"(",
")",
")",
"%",
"pc",
".",
"bitset",
".",
"Len",
"(",
")",
"\n",
"}"
] | // It provides a bit map address given a string value using a non-crypto hashing function. | [
"It",
"provides",
"a",
"bit",
"map",
"address",
"given",
"a",
"string",
"value",
"using",
"a",
"non",
"-",
"crypto",
"hashing",
"function",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/counting/probabilistic_counter.go#L116-L120 |
9,735 | remind101/pkg | svc/env.go | InitAll | func InitAll() Env {
traceCloser := InitTracer()
metricsCloser := InitMetrics()
l := InitLogger()
logger.DefaultLogger = l
r := InitReporter()
ctx := reporter.WithReporter(context.Background(), r)
ctx = logger.WithLogger(ctx, l)
go func() {
defer reporter.Monitor(ctx)
metrics.Runtime()
}()
return Env{
Logger: l,
Reporter: r,
Context: ctx,
Close: func() {
traceCloser()
metricsCloser()
},
}
} | go | func InitAll() Env {
traceCloser := InitTracer()
metricsCloser := InitMetrics()
l := InitLogger()
logger.DefaultLogger = l
r := InitReporter()
ctx := reporter.WithReporter(context.Background(), r)
ctx = logger.WithLogger(ctx, l)
go func() {
defer reporter.Monitor(ctx)
metrics.Runtime()
}()
return Env{
Logger: l,
Reporter: r,
Context: ctx,
Close: func() {
traceCloser()
metricsCloser()
},
}
} | [
"func",
"InitAll",
"(",
")",
"Env",
"{",
"traceCloser",
":=",
"InitTracer",
"(",
")",
"\n",
"metricsCloser",
":=",
"InitMetrics",
"(",
")",
"\n\n",
"l",
":=",
"InitLogger",
"(",
")",
"\n",
"logger",
".",
"DefaultLogger",
"=",
"l",
"\n\n",
"r",
":=",
"InitReporter",
"(",
")",
"\n\n",
"ctx",
":=",
"reporter",
".",
"WithReporter",
"(",
"context",
".",
"Background",
"(",
")",
",",
"r",
")",
"\n",
"ctx",
"=",
"logger",
".",
"WithLogger",
"(",
"ctx",
",",
"l",
")",
"\n\n",
"go",
"func",
"(",
")",
"{",
"defer",
"reporter",
".",
"Monitor",
"(",
"ctx",
")",
"\n",
"metrics",
".",
"Runtime",
"(",
")",
"\n",
"}",
"(",
")",
"\n\n",
"return",
"Env",
"{",
"Logger",
":",
"l",
",",
"Reporter",
":",
"r",
",",
"Context",
":",
"ctx",
",",
"Close",
":",
"func",
"(",
")",
"{",
"traceCloser",
"(",
")",
"\n",
"metricsCloser",
"(",
")",
"\n",
"}",
",",
"}",
"\n",
"}"
] | // InitAll will initialize all the common dependencies such as metrics, reporting,
// tracing, and logging. | [
"InitAll",
"will",
"initialize",
"all",
"the",
"common",
"dependencies",
"such",
"as",
"metrics",
"reporting",
"tracing",
"and",
"logging",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/svc/env.go#L29-L55 |
9,736 | remind101/pkg | reporter/logger.go | ReportWithLevel | func (h *LogReporter) ReportWithLevel(ctx context.Context, level string, err error) error {
var file, line string
var stack errors.StackTrace
if errWithStack, ok := err.(stackTracer); ok {
stack = errWithStack.StackTrace()
}
if stack != nil && len(stack) > 0 {
file = fmt.Sprintf("%s", stack[0])
line = fmt.Sprintf("%d", stack[0])
} else {
file = "unknown"
line = "0"
}
if level == "debug" {
logger.Debug(ctx, "", "debug", fmt.Sprintf(`"%v"`, err), "line", line, "file", file)
} else if level == "info" {
logger.Info(ctx, "", "info", fmt.Sprintf(`"%v"`, err), "line", line, "file", file)
} else {
logger.Error(ctx, "", level, fmt.Sprintf(`"%v"`, err), "line", line, "file", file)
}
return nil
} | go | func (h *LogReporter) ReportWithLevel(ctx context.Context, level string, err error) error {
var file, line string
var stack errors.StackTrace
if errWithStack, ok := err.(stackTracer); ok {
stack = errWithStack.StackTrace()
}
if stack != nil && len(stack) > 0 {
file = fmt.Sprintf("%s", stack[0])
line = fmt.Sprintf("%d", stack[0])
} else {
file = "unknown"
line = "0"
}
if level == "debug" {
logger.Debug(ctx, "", "debug", fmt.Sprintf(`"%v"`, err), "line", line, "file", file)
} else if level == "info" {
logger.Info(ctx, "", "info", fmt.Sprintf(`"%v"`, err), "line", line, "file", file)
} else {
logger.Error(ctx, "", level, fmt.Sprintf(`"%v"`, err), "line", line, "file", file)
}
return nil
} | [
"func",
"(",
"h",
"*",
"LogReporter",
")",
"ReportWithLevel",
"(",
"ctx",
"context",
".",
"Context",
",",
"level",
"string",
",",
"err",
"error",
")",
"error",
"{",
"var",
"file",
",",
"line",
"string",
"\n",
"var",
"stack",
"errors",
".",
"StackTrace",
"\n\n",
"if",
"errWithStack",
",",
"ok",
":=",
"err",
".",
"(",
"stackTracer",
")",
";",
"ok",
"{",
"stack",
"=",
"errWithStack",
".",
"StackTrace",
"(",
")",
"\n",
"}",
"\n",
"if",
"stack",
"!=",
"nil",
"&&",
"len",
"(",
"stack",
")",
">",
"0",
"{",
"file",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"stack",
"[",
"0",
"]",
")",
"\n",
"line",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"stack",
"[",
"0",
"]",
")",
"\n",
"}",
"else",
"{",
"file",
"=",
"\"",
"\"",
"\n",
"line",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"if",
"level",
"==",
"\"",
"\"",
"{",
"logger",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"`\"%v\"`",
",",
"err",
")",
",",
"\"",
"\"",
",",
"line",
",",
"\"",
"\"",
",",
"file",
")",
"\n",
"}",
"else",
"if",
"level",
"==",
"\"",
"\"",
"{",
"logger",
".",
"Info",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"`\"%v\"`",
",",
"err",
")",
",",
"\"",
"\"",
",",
"line",
",",
"\"",
"\"",
",",
"file",
")",
"\n",
"}",
"else",
"{",
"logger",
".",
"Error",
"(",
"ctx",
",",
"\"",
"\"",
",",
"level",
",",
"fmt",
".",
"Sprintf",
"(",
"`\"%v\"`",
",",
"err",
")",
",",
"\"",
"\"",
",",
"line",
",",
"\"",
"\"",
",",
"file",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Report logs the error to the Logger. | [
"Report",
"logs",
"the",
"error",
"to",
"the",
"Logger",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/reporter/logger.go#L24-L47 |
9,737 | remind101/pkg | tracing/contrib/aws/request.go | New | func New(opts ...Option) *Tracer {
opts = append([]Option{defaultTags}, opts...)
return &Tracer{opts}
} | go | func New(opts ...Option) *Tracer {
opts = append([]Option{defaultTags}, opts...)
return &Tracer{opts}
} | [
"func",
"New",
"(",
"opts",
"...",
"Option",
")",
"*",
"Tracer",
"{",
"opts",
"=",
"append",
"(",
"[",
"]",
"Option",
"{",
"defaultTags",
"}",
",",
"opts",
"...",
")",
"\n",
"return",
"&",
"Tracer",
"{",
"opts",
"}",
"\n",
"}"
] | // New returns a new AWS request tracer with default tagging. | [
"New",
"returns",
"a",
"new",
"AWS",
"request",
"tracer",
"with",
"default",
"tagging",
"."
] | 6c8f1a7b080e58f5c69a857536d9989fc9356841 | https://github.com/remind101/pkg/blob/6c8f1a7b080e58f5c69a857536d9989fc9356841/tracing/contrib/aws/request.go#L19-L22 |
9,738 | fnproject/fdk-go | handler.go | encapHeaders | func encapHeaders(hdr http.Header) {
for k, vs := range hdr {
if k == "Content-Type" || strings.HasPrefix(k, "Fn-Http-H-") {
continue // we've passed this one
}
// remove them all to add them all back
hdr.Del(k)
// prepend this guy, add it back
k = "Fn-Http-H-" + k
hdr[k] = vs
}
} | go | func encapHeaders(hdr http.Header) {
for k, vs := range hdr {
if k == "Content-Type" || strings.HasPrefix(k, "Fn-Http-H-") {
continue // we've passed this one
}
// remove them all to add them all back
hdr.Del(k)
// prepend this guy, add it back
k = "Fn-Http-H-" + k
hdr[k] = vs
}
} | [
"func",
"encapHeaders",
"(",
"hdr",
"http",
".",
"Header",
")",
"{",
"for",
"k",
",",
"vs",
":=",
"range",
"hdr",
"{",
"if",
"k",
"==",
"\"",
"\"",
"||",
"strings",
".",
"HasPrefix",
"(",
"k",
",",
"\"",
"\"",
")",
"{",
"continue",
"// we've passed this one",
"\n",
"}",
"\n\n",
"// remove them all to add them all back",
"hdr",
".",
"Del",
"(",
"k",
")",
"\n\n",
"// prepend this guy, add it back",
"k",
"=",
"\"",
"\"",
"+",
"k",
"\n",
"hdr",
"[",
"k",
"]",
"=",
"vs",
"\n",
"}",
"\n",
"}"
] | // encapHeaders modifies headers in place per http gateway protocol | [
"encapHeaders",
"modifies",
"headers",
"in",
"place",
"per",
"http",
"gateway",
"protocol"
] | fe351e86c1f732195ca870595a259ce55fe9c7ed | https://github.com/fnproject/fdk-go/blob/fe351e86c1f732195ca870595a259ce55fe9c7ed/handler.go#L87-L100 |
9,739 | fnproject/fdk-go | handler.go | logFrameHeader | func logFrameHeader(r *http.Request) {
framer := os.Getenv("FN_LOGFRAME_NAME")
if framer == "" {
return
}
valueSrc := os.Getenv("FN_LOGFRAME_HDR")
if valueSrc == "" {
return
}
id := r.Header.Get(valueSrc)
if id != "" {
fmt.Fprintf(os.Stderr, "\n%s=%s\n", framer, id)
fmt.Fprintf(os.Stdout, "\n%s=%s\n", framer, id)
}
} | go | func logFrameHeader(r *http.Request) {
framer := os.Getenv("FN_LOGFRAME_NAME")
if framer == "" {
return
}
valueSrc := os.Getenv("FN_LOGFRAME_HDR")
if valueSrc == "" {
return
}
id := r.Header.Get(valueSrc)
if id != "" {
fmt.Fprintf(os.Stderr, "\n%s=%s\n", framer, id)
fmt.Fprintf(os.Stdout, "\n%s=%s\n", framer, id)
}
} | [
"func",
"logFrameHeader",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"framer",
":=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
"\n",
"if",
"framer",
"==",
"\"",
"\"",
"{",
"return",
"\n",
"}",
"\n",
"valueSrc",
":=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
"\n",
"if",
"valueSrc",
"==",
"\"",
"\"",
"{",
"return",
"\n",
"}",
"\n",
"id",
":=",
"r",
".",
"Header",
".",
"Get",
"(",
"valueSrc",
")",
"\n",
"if",
"id",
"!=",
"\"",
"\"",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\n",
"\\n",
"\"",
",",
"framer",
",",
"id",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stdout",
",",
"\"",
"\\n",
"\\n",
"\"",
",",
"framer",
",",
"id",
")",
"\n",
"}",
"\n",
"}"
] | // If enabled, print the log framing content. | [
"If",
"enabled",
"print",
"the",
"log",
"framing",
"content",
"."
] | fe351e86c1f732195ca870595a259ce55fe9c7ed | https://github.com/fnproject/fdk-go/blob/fe351e86c1f732195ca870595a259ce55fe9c7ed/handler.go#L225-L239 |
9,740 | fnproject/fdk-go | fdk.go | WithContext | func WithContext(ctx context.Context, fnctx Context) context.Context {
return context.WithValue(ctx, ctxKey, fnctx)
} | go | func WithContext(ctx context.Context, fnctx Context) context.Context {
return context.WithValue(ctx, ctxKey, fnctx)
} | [
"func",
"WithContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"fnctx",
"Context",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"ctxKey",
",",
"fnctx",
")",
"\n",
"}"
] | // WithContext adds an fn context to a context context. It is unclear why this is
// an exported method but hey here ya go don't hurt yourself. | [
"WithContext",
"adds",
"an",
"fn",
"context",
"to",
"a",
"context",
"context",
".",
"It",
"is",
"unclear",
"why",
"this",
"is",
"an",
"exported",
"method",
"but",
"hey",
"here",
"ya",
"go",
"don",
"t",
"hurt",
"yourself",
"."
] | fe351e86c1f732195ca870595a259ce55fe9c7ed | https://github.com/fnproject/fdk-go/blob/fe351e86c1f732195ca870595a259ce55fe9c7ed/fdk.go#L73-L75 |
9,741 | fnproject/fdk-go | fdk.go | AddHeader | func AddHeader(out io.Writer, key, value string) {
if resp, ok := out.(http.ResponseWriter); ok {
resp.Header().Add(key, value)
}
} | go | func AddHeader(out io.Writer, key, value string) {
if resp, ok := out.(http.ResponseWriter); ok {
resp.Header().Add(key, value)
}
} | [
"func",
"AddHeader",
"(",
"out",
"io",
".",
"Writer",
",",
"key",
",",
"value",
"string",
")",
"{",
"if",
"resp",
",",
"ok",
":=",
"out",
".",
"(",
"http",
".",
"ResponseWriter",
")",
";",
"ok",
"{",
"resp",
".",
"Header",
"(",
")",
".",
"Add",
"(",
"key",
",",
"value",
")",
"\n",
"}",
"\n",
"}"
] | // AddHeader will add a header onto the function response | [
"AddHeader",
"will",
"add",
"a",
"header",
"onto",
"the",
"function",
"response"
] | fe351e86c1f732195ca870595a259ce55fe9c7ed | https://github.com/fnproject/fdk-go/blob/fe351e86c1f732195ca870595a259ce55fe9c7ed/fdk.go#L149-L153 |
9,742 | fnproject/fdk-go | fdk.go | SetHeader | func SetHeader(out io.Writer, key, value string) {
if resp, ok := out.(http.ResponseWriter); ok {
resp.Header().Set(key, value)
}
} | go | func SetHeader(out io.Writer, key, value string) {
if resp, ok := out.(http.ResponseWriter); ok {
resp.Header().Set(key, value)
}
} | [
"func",
"SetHeader",
"(",
"out",
"io",
".",
"Writer",
",",
"key",
",",
"value",
"string",
")",
"{",
"if",
"resp",
",",
"ok",
":=",
"out",
".",
"(",
"http",
".",
"ResponseWriter",
")",
";",
"ok",
"{",
"resp",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"key",
",",
"value",
")",
"\n",
"}",
"\n",
"}"
] | // SetHeader will set a header on the function response | [
"SetHeader",
"will",
"set",
"a",
"header",
"on",
"the",
"function",
"response"
] | fe351e86c1f732195ca870595a259ce55fe9c7ed | https://github.com/fnproject/fdk-go/blob/fe351e86c1f732195ca870595a259ce55fe9c7ed/fdk.go#L156-L160 |
9,743 | fnproject/fdk-go | fdk.go | WriteStatus | func WriteStatus(out io.Writer, status int) {
if resp, ok := out.(http.ResponseWriter); ok {
resp.WriteHeader(status)
}
} | go | func WriteStatus(out io.Writer, status int) {
if resp, ok := out.(http.ResponseWriter); ok {
resp.WriteHeader(status)
}
} | [
"func",
"WriteStatus",
"(",
"out",
"io",
".",
"Writer",
",",
"status",
"int",
")",
"{",
"if",
"resp",
",",
"ok",
":=",
"out",
".",
"(",
"http",
".",
"ResponseWriter",
")",
";",
"ok",
"{",
"resp",
".",
"WriteHeader",
"(",
"status",
")",
"\n",
"}",
"\n",
"}"
] | // WriteStatus will set the status code to return in the function response | [
"WriteStatus",
"will",
"set",
"the",
"status",
"code",
"to",
"return",
"in",
"the",
"function",
"response"
] | fe351e86c1f732195ca870595a259ce55fe9c7ed | https://github.com/fnproject/fdk-go/blob/fe351e86c1f732195ca870595a259ce55fe9c7ed/fdk.go#L163-L167 |
9,744 | Fs02/grimoire | adapter/specs/transaction.go | Transaction | func Transaction(t *testing.T, repo grimoire.Repo) {
tests := []struct {
name string
block func(*testing.T) func(grimoire.Repo) error
err error
}{
{"QueryAll", queryAll, nil},
{"InsertWithAssoc", insertWithAssoc, nil},
{"InsertWithAssocError", insertWithAssocError, errors.New("let's rollback", "", errors.NotFound)},
{"InsertWithAssocPanic", insertWithAssocPanic, errors.New("let's rollback", "", errors.NotFound)},
{"ReplaceAssoc", replaceAssoc, nil},
{"NestedInsertWithAssoc", nestedInsertWithAssoc, nil},
{"NestedInsertWithAssocError", nestedInsertWithAssocError, errors.New("let's rollback", "", errors.NotFound)},
{"NestedInsertWithAssocPanic", nestedInsertWithAssocPanic, errors.New("let's rollback", "", errors.NotFound)},
{"NestedReplaceAssoc", nestedReplaceAssoc, nil},
}
for _, tt := range tests {
t.Run("Transaction|"+tt.name, func(t *testing.T) {
assert.Equal(t, tt.err, repo.Transaction(tt.block(t)))
})
}
} | go | func Transaction(t *testing.T, repo grimoire.Repo) {
tests := []struct {
name string
block func(*testing.T) func(grimoire.Repo) error
err error
}{
{"QueryAll", queryAll, nil},
{"InsertWithAssoc", insertWithAssoc, nil},
{"InsertWithAssocError", insertWithAssocError, errors.New("let's rollback", "", errors.NotFound)},
{"InsertWithAssocPanic", insertWithAssocPanic, errors.New("let's rollback", "", errors.NotFound)},
{"ReplaceAssoc", replaceAssoc, nil},
{"NestedInsertWithAssoc", nestedInsertWithAssoc, nil},
{"NestedInsertWithAssocError", nestedInsertWithAssocError, errors.New("let's rollback", "", errors.NotFound)},
{"NestedInsertWithAssocPanic", nestedInsertWithAssocPanic, errors.New("let's rollback", "", errors.NotFound)},
{"NestedReplaceAssoc", nestedReplaceAssoc, nil},
}
for _, tt := range tests {
t.Run("Transaction|"+tt.name, func(t *testing.T) {
assert.Equal(t, tt.err, repo.Transaction(tt.block(t)))
})
}
} | [
"func",
"Transaction",
"(",
"t",
"*",
"testing",
".",
"T",
",",
"repo",
"grimoire",
".",
"Repo",
")",
"{",
"tests",
":=",
"[",
"]",
"struct",
"{",
"name",
"string",
"\n",
"block",
"func",
"(",
"*",
"testing",
".",
"T",
")",
"func",
"(",
"grimoire",
".",
"Repo",
")",
"error",
"\n",
"err",
"error",
"\n",
"}",
"{",
"{",
"\"",
"\"",
",",
"queryAll",
",",
"nil",
"}",
",",
"{",
"\"",
"\"",
",",
"insertWithAssoc",
",",
"nil",
"}",
",",
"{",
"\"",
"\"",
",",
"insertWithAssocError",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"errors",
".",
"NotFound",
")",
"}",
",",
"{",
"\"",
"\"",
",",
"insertWithAssocPanic",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"errors",
".",
"NotFound",
")",
"}",
",",
"{",
"\"",
"\"",
",",
"replaceAssoc",
",",
"nil",
"}",
",",
"{",
"\"",
"\"",
",",
"nestedInsertWithAssoc",
",",
"nil",
"}",
",",
"{",
"\"",
"\"",
",",
"nestedInsertWithAssocError",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"errors",
".",
"NotFound",
")",
"}",
",",
"{",
"\"",
"\"",
",",
"nestedInsertWithAssocPanic",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"errors",
".",
"NotFound",
")",
"}",
",",
"{",
"\"",
"\"",
",",
"nestedReplaceAssoc",
",",
"nil",
"}",
",",
"}",
"\n\n",
"for",
"_",
",",
"tt",
":=",
"range",
"tests",
"{",
"t",
".",
"Run",
"(",
"\"",
"\"",
"+",
"tt",
".",
"name",
",",
"func",
"(",
"t",
"*",
"testing",
".",
"T",
")",
"{",
"assert",
".",
"Equal",
"(",
"t",
",",
"tt",
".",
"err",
",",
"repo",
".",
"Transaction",
"(",
"tt",
".",
"block",
"(",
"t",
")",
")",
")",
"\n",
"}",
")",
"\n",
"}",
"\n",
"}"
] | // Transaction tests insert specifications. | [
"Transaction",
"tests",
"insert",
"specifications",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/specs/transaction.go#L30-L52 |
9,745 | Fs02/grimoire | changeset/cast.go | Cast | func Cast(data interface{}, params params.Params, fields []string, opts ...Option) *Changeset {
options := Options{
message: CastErrorMessage,
emptyValues: []interface{}{""},
}
options.apply(opts)
var ch *Changeset
if existingCh, ok := data.(Changeset); ok {
ch = &existingCh
} else if existingCh, ok := data.(*Changeset); ok {
ch = existingCh
} else {
ch = &Changeset{}
ch.params = params
ch.changes = make(map[string]interface{})
ch.values, ch.types, ch.zero = mapSchema(data)
}
for _, field := range fields {
typ, texist := ch.types[field]
if !params.Exists(field) || !texist {
continue
}
// ignore if it's an empty value
if contains(options.emptyValues, params.Get(field)) {
continue
}
if change, valid := params.GetWithType(field, typ); valid {
value, vexist := ch.values[field]
if (typ.Kind() == reflect.Slice || typ.Kind() == reflect.Array) || (ch.zero && change != nil) || (!vexist && change != nil) || (vexist && value != change) {
ch.changes[field] = change
}
} else {
msg := strings.Replace(options.message, "{field}", field, 1)
AddError(ch, field, msg)
}
}
return ch
} | go | func Cast(data interface{}, params params.Params, fields []string, opts ...Option) *Changeset {
options := Options{
message: CastErrorMessage,
emptyValues: []interface{}{""},
}
options.apply(opts)
var ch *Changeset
if existingCh, ok := data.(Changeset); ok {
ch = &existingCh
} else if existingCh, ok := data.(*Changeset); ok {
ch = existingCh
} else {
ch = &Changeset{}
ch.params = params
ch.changes = make(map[string]interface{})
ch.values, ch.types, ch.zero = mapSchema(data)
}
for _, field := range fields {
typ, texist := ch.types[field]
if !params.Exists(field) || !texist {
continue
}
// ignore if it's an empty value
if contains(options.emptyValues, params.Get(field)) {
continue
}
if change, valid := params.GetWithType(field, typ); valid {
value, vexist := ch.values[field]
if (typ.Kind() == reflect.Slice || typ.Kind() == reflect.Array) || (ch.zero && change != nil) || (!vexist && change != nil) || (vexist && value != change) {
ch.changes[field] = change
}
} else {
msg := strings.Replace(options.message, "{field}", field, 1)
AddError(ch, field, msg)
}
}
return ch
} | [
"func",
"Cast",
"(",
"data",
"interface",
"{",
"}",
",",
"params",
"params",
".",
"Params",
",",
"fields",
"[",
"]",
"string",
",",
"opts",
"...",
"Option",
")",
"*",
"Changeset",
"{",
"options",
":=",
"Options",
"{",
"message",
":",
"CastErrorMessage",
",",
"emptyValues",
":",
"[",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
"}",
",",
"}",
"\n",
"options",
".",
"apply",
"(",
"opts",
")",
"\n\n",
"var",
"ch",
"*",
"Changeset",
"\n",
"if",
"existingCh",
",",
"ok",
":=",
"data",
".",
"(",
"Changeset",
")",
";",
"ok",
"{",
"ch",
"=",
"&",
"existingCh",
"\n",
"}",
"else",
"if",
"existingCh",
",",
"ok",
":=",
"data",
".",
"(",
"*",
"Changeset",
")",
";",
"ok",
"{",
"ch",
"=",
"existingCh",
"\n",
"}",
"else",
"{",
"ch",
"=",
"&",
"Changeset",
"{",
"}",
"\n",
"ch",
".",
"params",
"=",
"params",
"\n",
"ch",
".",
"changes",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"ch",
".",
"values",
",",
"ch",
".",
"types",
",",
"ch",
".",
"zero",
"=",
"mapSchema",
"(",
"data",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"field",
":=",
"range",
"fields",
"{",
"typ",
",",
"texist",
":=",
"ch",
".",
"types",
"[",
"field",
"]",
"\n\n",
"if",
"!",
"params",
".",
"Exists",
"(",
"field",
")",
"||",
"!",
"texist",
"{",
"continue",
"\n",
"}",
"\n\n",
"// ignore if it's an empty value",
"if",
"contains",
"(",
"options",
".",
"emptyValues",
",",
"params",
".",
"Get",
"(",
"field",
")",
")",
"{",
"continue",
"\n",
"}",
"\n\n",
"if",
"change",
",",
"valid",
":=",
"params",
".",
"GetWithType",
"(",
"field",
",",
"typ",
")",
";",
"valid",
"{",
"value",
",",
"vexist",
":=",
"ch",
".",
"values",
"[",
"field",
"]",
"\n\n",
"if",
"(",
"typ",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Slice",
"||",
"typ",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Array",
")",
"||",
"(",
"ch",
".",
"zero",
"&&",
"change",
"!=",
"nil",
")",
"||",
"(",
"!",
"vexist",
"&&",
"change",
"!=",
"nil",
")",
"||",
"(",
"vexist",
"&&",
"value",
"!=",
"change",
")",
"{",
"ch",
".",
"changes",
"[",
"field",
"]",
"=",
"change",
"\n",
"}",
"\n",
"}",
"else",
"{",
"msg",
":=",
"strings",
".",
"Replace",
"(",
"options",
".",
"message",
",",
"\"",
"\"",
",",
"field",
",",
"1",
")",
"\n",
"AddError",
"(",
"ch",
",",
"field",
",",
"msg",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"ch",
"\n",
"}"
] | // Cast params as changes for the given data according to the permitted fields. Returns a new changeset.
// params will only be added as changes if it does not have the same value as the field in the data. | [
"Cast",
"params",
"as",
"changes",
"for",
"the",
"given",
"data",
"according",
"to",
"the",
"permitted",
"fields",
".",
"Returns",
"a",
"new",
"changeset",
".",
"params",
"will",
"only",
"be",
"added",
"as",
"changes",
"if",
"it",
"does",
"not",
"have",
"the",
"same",
"value",
"as",
"the",
"field",
"in",
"the",
"data",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/changeset/cast.go#L16-L60 |
9,746 | Fs02/grimoire | changeset/cast.go | isZero | func isZero(rv reflect.Value) bool {
zero := true
switch rv.Kind() {
case reflect.Bool:
zero = !rv.Bool()
case reflect.Float32, reflect.Float64:
zero = rv.Float() == 0
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
zero = rv.Int() == 0
case reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
zero = rv.IsNil()
case reflect.String:
zero = rv.String() == ""
case reflect.Uint, reflect.Uintptr, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
zero = rv.Uint() == 0
}
return zero
} | go | func isZero(rv reflect.Value) bool {
zero := true
switch rv.Kind() {
case reflect.Bool:
zero = !rv.Bool()
case reflect.Float32, reflect.Float64:
zero = rv.Float() == 0
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
zero = rv.Int() == 0
case reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
zero = rv.IsNil()
case reflect.String:
zero = rv.String() == ""
case reflect.Uint, reflect.Uintptr, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
zero = rv.Uint() == 0
}
return zero
} | [
"func",
"isZero",
"(",
"rv",
"reflect",
".",
"Value",
")",
"bool",
"{",
"zero",
":=",
"true",
"\n",
"switch",
"rv",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Bool",
":",
"zero",
"=",
"!",
"rv",
".",
"Bool",
"(",
")",
"\n",
"case",
"reflect",
".",
"Float32",
",",
"reflect",
".",
"Float64",
":",
"zero",
"=",
"rv",
".",
"Float",
"(",
")",
"==",
"0",
"\n",
"case",
"reflect",
".",
"Int",
",",
"reflect",
".",
"Int8",
",",
"reflect",
".",
"Int16",
",",
"reflect",
".",
"Int32",
",",
"reflect",
".",
"Int64",
":",
"zero",
"=",
"rv",
".",
"Int",
"(",
")",
"==",
"0",
"\n",
"case",
"reflect",
".",
"Interface",
",",
"reflect",
".",
"Map",
",",
"reflect",
".",
"Ptr",
",",
"reflect",
".",
"Slice",
":",
"zero",
"=",
"rv",
".",
"IsNil",
"(",
")",
"\n",
"case",
"reflect",
".",
"String",
":",
"zero",
"=",
"rv",
".",
"String",
"(",
")",
"==",
"\"",
"\"",
"\n",
"case",
"reflect",
".",
"Uint",
",",
"reflect",
".",
"Uintptr",
",",
"reflect",
".",
"Uint8",
",",
"reflect",
".",
"Uint16",
",",
"reflect",
".",
"Uint32",
",",
"reflect",
".",
"Uint64",
":",
"zero",
"=",
"rv",
".",
"Uint",
"(",
")",
"==",
"0",
"\n",
"}",
"\n\n",
"return",
"zero",
"\n",
"}"
] | // isZero shallowly check wether a field in struct is zero or not | [
"isZero",
"shallowly",
"check",
"wether",
"a",
"field",
"in",
"struct",
"is",
"zero",
"or",
"not"
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/changeset/cast.go#L123-L141 |
9,747 | Fs02/grimoire | changeset/apply_string.go | ApplyString | func ApplyString(ch *Changeset, field string, fn func(string) string) {
if val, ok := ch.changes[field]; ok && val != nil && ch.types[field].Kind() == reflect.String {
ch.changes[field] = fn(val.(string))
}
} | go | func ApplyString(ch *Changeset, field string, fn func(string) string) {
if val, ok := ch.changes[field]; ok && val != nil && ch.types[field].Kind() == reflect.String {
ch.changes[field] = fn(val.(string))
}
} | [
"func",
"ApplyString",
"(",
"ch",
"*",
"Changeset",
",",
"field",
"string",
",",
"fn",
"func",
"(",
"string",
")",
"string",
")",
"{",
"if",
"val",
",",
"ok",
":=",
"ch",
".",
"changes",
"[",
"field",
"]",
";",
"ok",
"&&",
"val",
"!=",
"nil",
"&&",
"ch",
".",
"types",
"[",
"field",
"]",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"String",
"{",
"ch",
".",
"changes",
"[",
"field",
"]",
"=",
"fn",
"(",
"val",
".",
"(",
"string",
")",
")",
"\n",
"}",
"\n",
"}"
] | // ApplyString apply a function for string value. | [
"ApplyString",
"apply",
"a",
"function",
"for",
"string",
"value",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/changeset/apply_string.go#L8-L12 |
9,748 | Fs02/grimoire | adapter/postgres/postgres.go | InsertAll | func (adapter *Adapter) InsertAll(query grimoire.Query, fields []string, allchanges []map[string]interface{}, loggers ...grimoire.Logger) ([]interface{}, error) {
statement, args := sql.NewBuilder(adapter.Config).Returning("id").InsertAll(query.Collection, fields, allchanges)
var result []struct {
ID int64
}
_, err := adapter.Query(&result, statement, args, loggers...)
ids := make([]interface{}, 0, len(result))
for _, r := range result {
ids = append(ids, r.ID)
}
return ids, err
} | go | func (adapter *Adapter) InsertAll(query grimoire.Query, fields []string, allchanges []map[string]interface{}, loggers ...grimoire.Logger) ([]interface{}, error) {
statement, args := sql.NewBuilder(adapter.Config).Returning("id").InsertAll(query.Collection, fields, allchanges)
var result []struct {
ID int64
}
_, err := adapter.Query(&result, statement, args, loggers...)
ids := make([]interface{}, 0, len(result))
for _, r := range result {
ids = append(ids, r.ID)
}
return ids, err
} | [
"func",
"(",
"adapter",
"*",
"Adapter",
")",
"InsertAll",
"(",
"query",
"grimoire",
".",
"Query",
",",
"fields",
"[",
"]",
"string",
",",
"allchanges",
"[",
"]",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"loggers",
"...",
"grimoire",
".",
"Logger",
")",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"statement",
",",
"args",
":=",
"sql",
".",
"NewBuilder",
"(",
"adapter",
".",
"Config",
")",
".",
"Returning",
"(",
"\"",
"\"",
")",
".",
"InsertAll",
"(",
"query",
".",
"Collection",
",",
"fields",
",",
"allchanges",
")",
"\n\n",
"var",
"result",
"[",
"]",
"struct",
"{",
"ID",
"int64",
"\n",
"}",
"\n\n",
"_",
",",
"err",
":=",
"adapter",
".",
"Query",
"(",
"&",
"result",
",",
"statement",
",",
"args",
",",
"loggers",
"...",
")",
"\n\n",
"ids",
":=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"0",
",",
"len",
"(",
"result",
")",
")",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"result",
"{",
"ids",
"=",
"append",
"(",
"ids",
",",
"r",
".",
"ID",
")",
"\n",
"}",
"\n\n",
"return",
"ids",
",",
"err",
"\n",
"}"
] | // InsertAll inserts multiple records to database and returns its ids. | [
"InsertAll",
"inserts",
"multiple",
"records",
"to",
"database",
"and",
"returns",
"its",
"ids",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/postgres/postgres.go#L65-L80 |
9,749 | Fs02/grimoire | changeset/cast_assoc.go | CastAssoc | func CastAssoc(ch *Changeset, field string, fn ChangeFunc, opts ...Option) {
options := Options{
message: CastAssocErrorMessage,
}
options.apply(opts)
sourceField := options.sourceField
if sourceField == "" {
sourceField = field
}
typ, texist := ch.types[field]
valid := true
if texist && ch.params.Exists(sourceField) {
if typ.Kind() == reflect.Struct {
valid = castOne(ch, sourceField, field, fn)
} else if typ.Kind() == reflect.Slice && typ.Elem().Kind() == reflect.Struct {
valid = castMany(ch, sourceField, field, fn)
}
}
if !valid {
msg := strings.Replace(options.message, "{field}", field, 1)
AddError(ch, field, msg)
}
_, found := ch.changes[field]
if options.required && !found {
options.message = CastAssocRequiredMessage
msg := strings.Replace(options.message, "{field}", field, 1)
AddError(ch, field, msg)
}
} | go | func CastAssoc(ch *Changeset, field string, fn ChangeFunc, opts ...Option) {
options := Options{
message: CastAssocErrorMessage,
}
options.apply(opts)
sourceField := options.sourceField
if sourceField == "" {
sourceField = field
}
typ, texist := ch.types[field]
valid := true
if texist && ch.params.Exists(sourceField) {
if typ.Kind() == reflect.Struct {
valid = castOne(ch, sourceField, field, fn)
} else if typ.Kind() == reflect.Slice && typ.Elem().Kind() == reflect.Struct {
valid = castMany(ch, sourceField, field, fn)
}
}
if !valid {
msg := strings.Replace(options.message, "{field}", field, 1)
AddError(ch, field, msg)
}
_, found := ch.changes[field]
if options.required && !found {
options.message = CastAssocRequiredMessage
msg := strings.Replace(options.message, "{field}", field, 1)
AddError(ch, field, msg)
}
} | [
"func",
"CastAssoc",
"(",
"ch",
"*",
"Changeset",
",",
"field",
"string",
",",
"fn",
"ChangeFunc",
",",
"opts",
"...",
"Option",
")",
"{",
"options",
":=",
"Options",
"{",
"message",
":",
"CastAssocErrorMessage",
",",
"}",
"\n",
"options",
".",
"apply",
"(",
"opts",
")",
"\n\n",
"sourceField",
":=",
"options",
".",
"sourceField",
"\n",
"if",
"sourceField",
"==",
"\"",
"\"",
"{",
"sourceField",
"=",
"field",
"\n",
"}",
"\n\n",
"typ",
",",
"texist",
":=",
"ch",
".",
"types",
"[",
"field",
"]",
"\n",
"valid",
":=",
"true",
"\n",
"if",
"texist",
"&&",
"ch",
".",
"params",
".",
"Exists",
"(",
"sourceField",
")",
"{",
"if",
"typ",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Struct",
"{",
"valid",
"=",
"castOne",
"(",
"ch",
",",
"sourceField",
",",
"field",
",",
"fn",
")",
"\n",
"}",
"else",
"if",
"typ",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Slice",
"&&",
"typ",
".",
"Elem",
"(",
")",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Struct",
"{",
"valid",
"=",
"castMany",
"(",
"ch",
",",
"sourceField",
",",
"field",
",",
"fn",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"!",
"valid",
"{",
"msg",
":=",
"strings",
".",
"Replace",
"(",
"options",
".",
"message",
",",
"\"",
"\"",
",",
"field",
",",
"1",
")",
"\n",
"AddError",
"(",
"ch",
",",
"field",
",",
"msg",
")",
"\n",
"}",
"\n\n",
"_",
",",
"found",
":=",
"ch",
".",
"changes",
"[",
"field",
"]",
"\n",
"if",
"options",
".",
"required",
"&&",
"!",
"found",
"{",
"options",
".",
"message",
"=",
"CastAssocRequiredMessage",
"\n",
"msg",
":=",
"strings",
".",
"Replace",
"(",
"options",
".",
"message",
",",
"\"",
"\"",
",",
"field",
",",
"1",
")",
"\n",
"AddError",
"(",
"ch",
",",
"field",
",",
"msg",
")",
"\n",
"}",
"\n",
"}"
] | // CastAssoc casts association changes using changeset function.
// Repo insert or update won't persist any changes generated by CastAssoc. | [
"CastAssoc",
"casts",
"association",
"changes",
"using",
"changeset",
"function",
".",
"Repo",
"insert",
"or",
"update",
"won",
"t",
"persist",
"any",
"changes",
"generated",
"by",
"CastAssoc",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/changeset/cast_assoc.go#L21-L53 |
9,750 | Fs02/grimoire | c/condition.go | NewOperand | func NewOperand(o ...interface{}) Operand {
if len(o) == 1 {
if c, ok := o[0].(I); ok {
return Operand{Column: c}
}
}
return Operand{Values: o}
} | go | func NewOperand(o ...interface{}) Operand {
if len(o) == 1 {
if c, ok := o[0].(I); ok {
return Operand{Column: c}
}
}
return Operand{Values: o}
} | [
"func",
"NewOperand",
"(",
"o",
"...",
"interface",
"{",
"}",
")",
"Operand",
"{",
"if",
"len",
"(",
"o",
")",
"==",
"1",
"{",
"if",
"c",
",",
"ok",
":=",
"o",
"[",
"0",
"]",
".",
"(",
"I",
")",
";",
"ok",
"{",
"return",
"Operand",
"{",
"Column",
":",
"c",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"Operand",
"{",
"Values",
":",
"o",
"}",
"\n",
"}"
] | // NewOperand create new operand. | [
"NewOperand",
"create",
"new",
"operand",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/c/condition.go#L58-L66 |
9,751 | Fs02/grimoire | c/condition.go | None | func (c Condition) None() bool {
return (c.Type == ConditionAnd ||
c.Type == ConditionOr ||
c.Type == ConditionNot) &&
len(c.Inner) == 0
} | go | func (c Condition) None() bool {
return (c.Type == ConditionAnd ||
c.Type == ConditionOr ||
c.Type == ConditionNot) &&
len(c.Inner) == 0
} | [
"func",
"(",
"c",
"Condition",
")",
"None",
"(",
")",
"bool",
"{",
"return",
"(",
"c",
".",
"Type",
"==",
"ConditionAnd",
"||",
"c",
".",
"Type",
"==",
"ConditionOr",
"||",
"c",
".",
"Type",
"==",
"ConditionNot",
")",
"&&",
"len",
"(",
"c",
".",
"Inner",
")",
"==",
"0",
"\n",
"}"
] | // None returns true if no condition is specified. | [
"None",
"returns",
"true",
"if",
"no",
"condition",
"is",
"specified",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/c/condition.go#L77-L82 |
9,752 | Fs02/grimoire | c/condition.go | And | func (c Condition) And(condition ...Condition) Condition {
if c.None() && len(condition) == 1 {
return condition[0]
} else if c.Type == ConditionAnd {
c.Inner = append(c.Inner, condition...)
return c
}
inner := append([]Condition{c}, condition...)
return And(inner...)
} | go | func (c Condition) And(condition ...Condition) Condition {
if c.None() && len(condition) == 1 {
return condition[0]
} else if c.Type == ConditionAnd {
c.Inner = append(c.Inner, condition...)
return c
}
inner := append([]Condition{c}, condition...)
return And(inner...)
} | [
"func",
"(",
"c",
"Condition",
")",
"And",
"(",
"condition",
"...",
"Condition",
")",
"Condition",
"{",
"if",
"c",
".",
"None",
"(",
")",
"&&",
"len",
"(",
"condition",
")",
"==",
"1",
"{",
"return",
"condition",
"[",
"0",
"]",
"\n",
"}",
"else",
"if",
"c",
".",
"Type",
"==",
"ConditionAnd",
"{",
"c",
".",
"Inner",
"=",
"append",
"(",
"c",
".",
"Inner",
",",
"condition",
"...",
")",
"\n",
"return",
"c",
"\n",
"}",
"\n\n",
"inner",
":=",
"append",
"(",
"[",
"]",
"Condition",
"{",
"c",
"}",
",",
"condition",
"...",
")",
"\n",
"return",
"And",
"(",
"inner",
"...",
")",
"\n",
"}"
] | // And wraps conditions using and. | [
"And",
"wraps",
"conditions",
"using",
"and",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/c/condition.go#L85-L95 |
9,753 | Fs02/grimoire | c/condition.go | Or | func (c Condition) Or(condition ...Condition) Condition {
if c.None() && len(condition) == 1 {
return condition[0]
} else if c.Type == ConditionOr || c.None() {
c.Type = ConditionOr
c.Inner = append(c.Inner, condition...)
return c
}
inner := append([]Condition{c}, condition...)
return Or(inner...)
} | go | func (c Condition) Or(condition ...Condition) Condition {
if c.None() && len(condition) == 1 {
return condition[0]
} else if c.Type == ConditionOr || c.None() {
c.Type = ConditionOr
c.Inner = append(c.Inner, condition...)
return c
}
inner := append([]Condition{c}, condition...)
return Or(inner...)
} | [
"func",
"(",
"c",
"Condition",
")",
"Or",
"(",
"condition",
"...",
"Condition",
")",
"Condition",
"{",
"if",
"c",
".",
"None",
"(",
")",
"&&",
"len",
"(",
"condition",
")",
"==",
"1",
"{",
"return",
"condition",
"[",
"0",
"]",
"\n",
"}",
"else",
"if",
"c",
".",
"Type",
"==",
"ConditionOr",
"||",
"c",
".",
"None",
"(",
")",
"{",
"c",
".",
"Type",
"=",
"ConditionOr",
"\n",
"c",
".",
"Inner",
"=",
"append",
"(",
"c",
".",
"Inner",
",",
"condition",
"...",
")",
"\n",
"return",
"c",
"\n",
"}",
"\n\n",
"inner",
":=",
"append",
"(",
"[",
"]",
"Condition",
"{",
"c",
"}",
",",
"condition",
"...",
")",
"\n",
"return",
"Or",
"(",
"inner",
"...",
")",
"\n",
"}"
] | // Or wraps conditions using or. | [
"Or",
"wraps",
"conditions",
"using",
"or",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/c/condition.go#L98-L109 |
9,754 | Fs02/grimoire | c/condition.go | And | func And(inner ...Condition) Condition {
if len(inner) == 1 {
return inner[0]
}
return Condition{
Type: ConditionAnd,
Inner: inner,
}
} | go | func And(inner ...Condition) Condition {
if len(inner) == 1 {
return inner[0]
}
return Condition{
Type: ConditionAnd,
Inner: inner,
}
} | [
"func",
"And",
"(",
"inner",
"...",
"Condition",
")",
"Condition",
"{",
"if",
"len",
"(",
"inner",
")",
"==",
"1",
"{",
"return",
"inner",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"return",
"Condition",
"{",
"Type",
":",
"ConditionAnd",
",",
"Inner",
":",
"inner",
",",
"}",
"\n",
"}"
] | // And compares other conditions using and. | [
"And",
"compares",
"other",
"conditions",
"using",
"and",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/c/condition.go#L112-L121 |
9,755 | Fs02/grimoire | c/condition.go | Or | func Or(inner ...Condition) Condition {
if len(inner) == 1 {
return inner[0]
}
return Condition{
Type: ConditionOr,
Inner: inner,
}
} | go | func Or(inner ...Condition) Condition {
if len(inner) == 1 {
return inner[0]
}
return Condition{
Type: ConditionOr,
Inner: inner,
}
} | [
"func",
"Or",
"(",
"inner",
"...",
"Condition",
")",
"Condition",
"{",
"if",
"len",
"(",
"inner",
")",
"==",
"1",
"{",
"return",
"inner",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"return",
"Condition",
"{",
"Type",
":",
"ConditionOr",
",",
"Inner",
":",
"inner",
",",
"}",
"\n",
"}"
] | // Or compares other conditions using and. | [
"Or",
"compares",
"other",
"conditions",
"using",
"and",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/c/condition.go#L124-L133 |
9,756 | Fs02/grimoire | c/condition.go | Not | func Not(inner ...Condition) Condition {
if len(inner) == 1 {
c := inner[0]
switch c.Type {
case ConditionEq:
c.Type = ConditionNe
return c
case ConditionLt:
c.Type = ConditionGte
return c
case ConditionLte:
c.Type = ConditionGt
return c
case ConditionGt:
c.Type = ConditionLte
return c
case ConditionGte:
c.Type = ConditionLt
return c
case ConditionNil:
c.Type = ConditionNotNil
return c
case ConditionIn:
c.Type = ConditionNin
return c
case ConditionLike:
c.Type = ConditionNotLike
return c
}
}
return Condition{
Type: ConditionNot,
Inner: inner,
}
} | go | func Not(inner ...Condition) Condition {
if len(inner) == 1 {
c := inner[0]
switch c.Type {
case ConditionEq:
c.Type = ConditionNe
return c
case ConditionLt:
c.Type = ConditionGte
return c
case ConditionLte:
c.Type = ConditionGt
return c
case ConditionGt:
c.Type = ConditionLte
return c
case ConditionGte:
c.Type = ConditionLt
return c
case ConditionNil:
c.Type = ConditionNotNil
return c
case ConditionIn:
c.Type = ConditionNin
return c
case ConditionLike:
c.Type = ConditionNotLike
return c
}
}
return Condition{
Type: ConditionNot,
Inner: inner,
}
} | [
"func",
"Not",
"(",
"inner",
"...",
"Condition",
")",
"Condition",
"{",
"if",
"len",
"(",
"inner",
")",
"==",
"1",
"{",
"c",
":=",
"inner",
"[",
"0",
"]",
"\n",
"switch",
"c",
".",
"Type",
"{",
"case",
"ConditionEq",
":",
"c",
".",
"Type",
"=",
"ConditionNe",
"\n",
"return",
"c",
"\n",
"case",
"ConditionLt",
":",
"c",
".",
"Type",
"=",
"ConditionGte",
"\n",
"return",
"c",
"\n",
"case",
"ConditionLte",
":",
"c",
".",
"Type",
"=",
"ConditionGt",
"\n",
"return",
"c",
"\n",
"case",
"ConditionGt",
":",
"c",
".",
"Type",
"=",
"ConditionLte",
"\n",
"return",
"c",
"\n",
"case",
"ConditionGte",
":",
"c",
".",
"Type",
"=",
"ConditionLt",
"\n",
"return",
"c",
"\n",
"case",
"ConditionNil",
":",
"c",
".",
"Type",
"=",
"ConditionNotNil",
"\n",
"return",
"c",
"\n",
"case",
"ConditionIn",
":",
"c",
".",
"Type",
"=",
"ConditionNin",
"\n",
"return",
"c",
"\n",
"case",
"ConditionLike",
":",
"c",
".",
"Type",
"=",
"ConditionNotLike",
"\n",
"return",
"c",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"Condition",
"{",
"Type",
":",
"ConditionNot",
",",
"Inner",
":",
"inner",
",",
"}",
"\n",
"}"
] | // Not wraps conditions using not.
// It'll negate the condition type if possible. | [
"Not",
"wraps",
"conditions",
"using",
"not",
".",
"It",
"ll",
"negate",
"the",
"condition",
"type",
"if",
"possible",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/c/condition.go#L137-L172 |
9,757 | Fs02/grimoire | c/condition.go | Eq | func Eq(left, right interface{}) Condition {
return Condition{
Type: ConditionEq,
Left: NewOperand(left),
Right: NewOperand(right),
}
} | go | func Eq(left, right interface{}) Condition {
return Condition{
Type: ConditionEq,
Left: NewOperand(left),
Right: NewOperand(right),
}
} | [
"func",
"Eq",
"(",
"left",
",",
"right",
"interface",
"{",
"}",
")",
"Condition",
"{",
"return",
"Condition",
"{",
"Type",
":",
"ConditionEq",
",",
"Left",
":",
"NewOperand",
"(",
"left",
")",
",",
"Right",
":",
"NewOperand",
"(",
"right",
")",
",",
"}",
"\n",
"}"
] | // Eq compares that left value is equal to right value. | [
"Eq",
"compares",
"that",
"left",
"value",
"is",
"equal",
"to",
"right",
"value",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/c/condition.go#L175-L181 |
9,758 | Fs02/grimoire | c/condition.go | Ne | func Ne(left, right interface{}) Condition {
return Condition{
Type: ConditionNe,
Left: NewOperand(left),
Right: NewOperand(right),
}
} | go | func Ne(left, right interface{}) Condition {
return Condition{
Type: ConditionNe,
Left: NewOperand(left),
Right: NewOperand(right),
}
} | [
"func",
"Ne",
"(",
"left",
",",
"right",
"interface",
"{",
"}",
")",
"Condition",
"{",
"return",
"Condition",
"{",
"Type",
":",
"ConditionNe",
",",
"Left",
":",
"NewOperand",
"(",
"left",
")",
",",
"Right",
":",
"NewOperand",
"(",
"right",
")",
",",
"}",
"\n",
"}"
] | // Ne compares that left value is not equal to right value. | [
"Ne",
"compares",
"that",
"left",
"value",
"is",
"not",
"equal",
"to",
"right",
"value",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/c/condition.go#L184-L190 |
9,759 | Fs02/grimoire | c/condition.go | Lt | func Lt(left, right interface{}) Condition {
return Condition{
Type: ConditionLt,
Left: NewOperand(left),
Right: NewOperand(right),
}
} | go | func Lt(left, right interface{}) Condition {
return Condition{
Type: ConditionLt,
Left: NewOperand(left),
Right: NewOperand(right),
}
} | [
"func",
"Lt",
"(",
"left",
",",
"right",
"interface",
"{",
"}",
")",
"Condition",
"{",
"return",
"Condition",
"{",
"Type",
":",
"ConditionLt",
",",
"Left",
":",
"NewOperand",
"(",
"left",
")",
",",
"Right",
":",
"NewOperand",
"(",
"right",
")",
",",
"}",
"\n",
"}"
] | // Lt compares that left value is less than to right value. | [
"Lt",
"compares",
"that",
"left",
"value",
"is",
"less",
"than",
"to",
"right",
"value",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/c/condition.go#L193-L199 |
9,760 | Fs02/grimoire | c/condition.go | Lte | func Lte(left, right interface{}) Condition {
return Condition{
Type: ConditionLte,
Left: NewOperand(left),
Right: NewOperand(right),
}
} | go | func Lte(left, right interface{}) Condition {
return Condition{
Type: ConditionLte,
Left: NewOperand(left),
Right: NewOperand(right),
}
} | [
"func",
"Lte",
"(",
"left",
",",
"right",
"interface",
"{",
"}",
")",
"Condition",
"{",
"return",
"Condition",
"{",
"Type",
":",
"ConditionLte",
",",
"Left",
":",
"NewOperand",
"(",
"left",
")",
",",
"Right",
":",
"NewOperand",
"(",
"right",
")",
",",
"}",
"\n",
"}"
] | // Lte compares that left value is less than or equal to right value. | [
"Lte",
"compares",
"that",
"left",
"value",
"is",
"less",
"than",
"or",
"equal",
"to",
"right",
"value",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/c/condition.go#L202-L208 |
9,761 | Fs02/grimoire | c/condition.go | Gt | func Gt(left, right interface{}) Condition {
return Condition{
Type: ConditionGt,
Left: NewOperand(left),
Right: NewOperand(right),
}
} | go | func Gt(left, right interface{}) Condition {
return Condition{
Type: ConditionGt,
Left: NewOperand(left),
Right: NewOperand(right),
}
} | [
"func",
"Gt",
"(",
"left",
",",
"right",
"interface",
"{",
"}",
")",
"Condition",
"{",
"return",
"Condition",
"{",
"Type",
":",
"ConditionGt",
",",
"Left",
":",
"NewOperand",
"(",
"left",
")",
",",
"Right",
":",
"NewOperand",
"(",
"right",
")",
",",
"}",
"\n",
"}"
] | // Gt compares that left value is greater than to right value. | [
"Gt",
"compares",
"that",
"left",
"value",
"is",
"greater",
"than",
"to",
"right",
"value",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/c/condition.go#L211-L217 |
9,762 | Fs02/grimoire | c/condition.go | Gte | func Gte(left, right interface{}) Condition {
return Condition{
Type: ConditionGte,
Left: NewOperand(left),
Right: NewOperand(right),
}
} | go | func Gte(left, right interface{}) Condition {
return Condition{
Type: ConditionGte,
Left: NewOperand(left),
Right: NewOperand(right),
}
} | [
"func",
"Gte",
"(",
"left",
",",
"right",
"interface",
"{",
"}",
")",
"Condition",
"{",
"return",
"Condition",
"{",
"Type",
":",
"ConditionGte",
",",
"Left",
":",
"NewOperand",
"(",
"left",
")",
",",
"Right",
":",
"NewOperand",
"(",
"right",
")",
",",
"}",
"\n",
"}"
] | // Gte compares that left value is greater than or equal to right value. | [
"Gte",
"compares",
"that",
"left",
"value",
"is",
"greater",
"than",
"or",
"equal",
"to",
"right",
"value",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/c/condition.go#L220-L226 |
9,763 | Fs02/grimoire | c/condition.go | Nil | func Nil(col I) Condition {
return Condition{
Type: ConditionNil,
Left: NewOperand(col),
}
} | go | func Nil(col I) Condition {
return Condition{
Type: ConditionNil,
Left: NewOperand(col),
}
} | [
"func",
"Nil",
"(",
"col",
"I",
")",
"Condition",
"{",
"return",
"Condition",
"{",
"Type",
":",
"ConditionNil",
",",
"Left",
":",
"NewOperand",
"(",
"col",
")",
",",
"}",
"\n",
"}"
] | // Nil check whether column is nil. | [
"Nil",
"check",
"whether",
"column",
"is",
"nil",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/c/condition.go#L229-L234 |
9,764 | Fs02/grimoire | c/condition.go | NotNil | func NotNil(col I) Condition {
return Condition{
Type: ConditionNotNil,
Left: NewOperand(col),
}
} | go | func NotNil(col I) Condition {
return Condition{
Type: ConditionNotNil,
Left: NewOperand(col),
}
} | [
"func",
"NotNil",
"(",
"col",
"I",
")",
"Condition",
"{",
"return",
"Condition",
"{",
"Type",
":",
"ConditionNotNil",
",",
"Left",
":",
"NewOperand",
"(",
"col",
")",
",",
"}",
"\n",
"}"
] | // NotNil check whether column is not nil. | [
"NotNil",
"check",
"whether",
"column",
"is",
"not",
"nil",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/c/condition.go#L237-L242 |
9,765 | Fs02/grimoire | c/condition.go | In | func In(col I, values ...interface{}) Condition {
return Condition{
Type: ConditionIn,
Left: NewOperand(col),
Right: NewOperand(values...),
}
} | go | func In(col I, values ...interface{}) Condition {
return Condition{
Type: ConditionIn,
Left: NewOperand(col),
Right: NewOperand(values...),
}
} | [
"func",
"In",
"(",
"col",
"I",
",",
"values",
"...",
"interface",
"{",
"}",
")",
"Condition",
"{",
"return",
"Condition",
"{",
"Type",
":",
"ConditionIn",
",",
"Left",
":",
"NewOperand",
"(",
"col",
")",
",",
"Right",
":",
"NewOperand",
"(",
"values",
"...",
")",
",",
"}",
"\n",
"}"
] | // In check whethers value of the column is included in values. | [
"In",
"check",
"whethers",
"value",
"of",
"the",
"column",
"is",
"included",
"in",
"values",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/c/condition.go#L245-L251 |
9,766 | Fs02/grimoire | c/condition.go | Nin | func Nin(col I, values ...interface{}) Condition {
return Condition{
Type: ConditionNin,
Left: NewOperand(col),
Right: NewOperand(values...),
}
} | go | func Nin(col I, values ...interface{}) Condition {
return Condition{
Type: ConditionNin,
Left: NewOperand(col),
Right: NewOperand(values...),
}
} | [
"func",
"Nin",
"(",
"col",
"I",
",",
"values",
"...",
"interface",
"{",
"}",
")",
"Condition",
"{",
"return",
"Condition",
"{",
"Type",
":",
"ConditionNin",
",",
"Left",
":",
"NewOperand",
"(",
"col",
")",
",",
"Right",
":",
"NewOperand",
"(",
"values",
"...",
")",
",",
"}",
"\n",
"}"
] | // Nin check whethers value of the column is not included in values. | [
"Nin",
"check",
"whethers",
"value",
"of",
"the",
"column",
"is",
"not",
"included",
"in",
"values",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/c/condition.go#L254-L260 |
9,767 | Fs02/grimoire | c/condition.go | Like | func Like(col I, pattern string) Condition {
return Condition{
Type: ConditionLike,
Left: NewOperand(col),
Right: NewOperand(pattern),
}
} | go | func Like(col I, pattern string) Condition {
return Condition{
Type: ConditionLike,
Left: NewOperand(col),
Right: NewOperand(pattern),
}
} | [
"func",
"Like",
"(",
"col",
"I",
",",
"pattern",
"string",
")",
"Condition",
"{",
"return",
"Condition",
"{",
"Type",
":",
"ConditionLike",
",",
"Left",
":",
"NewOperand",
"(",
"col",
")",
",",
"Right",
":",
"NewOperand",
"(",
"pattern",
")",
",",
"}",
"\n",
"}"
] | // Like compares value of column to match string pattern. | [
"Like",
"compares",
"value",
"of",
"column",
"to",
"match",
"string",
"pattern",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/c/condition.go#L263-L269 |
9,768 | Fs02/grimoire | c/condition.go | NotLike | func NotLike(col I, pattern string) Condition {
return Condition{
Type: ConditionNotLike,
Left: NewOperand(col),
Right: NewOperand(pattern),
}
} | go | func NotLike(col I, pattern string) Condition {
return Condition{
Type: ConditionNotLike,
Left: NewOperand(col),
Right: NewOperand(pattern),
}
} | [
"func",
"NotLike",
"(",
"col",
"I",
",",
"pattern",
"string",
")",
"Condition",
"{",
"return",
"Condition",
"{",
"Type",
":",
"ConditionNotLike",
",",
"Left",
":",
"NewOperand",
"(",
"col",
")",
",",
"Right",
":",
"NewOperand",
"(",
"pattern",
")",
",",
"}",
"\n",
"}"
] | // NotLike compares value of column to not match string pattern. | [
"NotLike",
"compares",
"value",
"of",
"column",
"to",
"not",
"match",
"string",
"pattern",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/c/condition.go#L272-L278 |
9,769 | Fs02/grimoire | c/condition.go | Fragment | func Fragment(expr I, values ...interface{}) Condition {
return Condition{
Type: ConditionFragment,
Left: NewOperand(expr),
Right: NewOperand(values...),
}
} | go | func Fragment(expr I, values ...interface{}) Condition {
return Condition{
Type: ConditionFragment,
Left: NewOperand(expr),
Right: NewOperand(values...),
}
} | [
"func",
"Fragment",
"(",
"expr",
"I",
",",
"values",
"...",
"interface",
"{",
"}",
")",
"Condition",
"{",
"return",
"Condition",
"{",
"Type",
":",
"ConditionFragment",
",",
"Left",
":",
"NewOperand",
"(",
"expr",
")",
",",
"Right",
":",
"NewOperand",
"(",
"values",
"...",
")",
",",
"}",
"\n",
"}"
] | // Fragment add custom condition. | [
"Fragment",
"add",
"custom",
"condition",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/c/condition.go#L281-L287 |
9,770 | Fs02/grimoire | internal/scannable.go | Scannable | func Scannable(rt reflect.Type) bool {
if rt.Kind() == reflect.Ptr {
fzeroval := reflect.New(rt.Elem()).Interface()
kind := rt.Elem().Kind()
_, isScanner := fzeroval.(sql.Scanner)
_, isTime := fzeroval.(*time.Time)
if (kind == reflect.Struct || kind == reflect.Slice || kind == reflect.Array) && kind != reflect.Uint8 && !isScanner && !isTime {
return false
}
} else {
fzeroval := reflect.New(rt).Interface()
kind := rt.Kind()
_, isScanner := fzeroval.(sql.Scanner)
_, isTime := fzeroval.(*time.Time)
if (kind == reflect.Struct || kind == reflect.Slice || kind == reflect.Array) && kind != reflect.Uint8 && !isScanner && !isTime {
return false
}
}
return true
} | go | func Scannable(rt reflect.Type) bool {
if rt.Kind() == reflect.Ptr {
fzeroval := reflect.New(rt.Elem()).Interface()
kind := rt.Elem().Kind()
_, isScanner := fzeroval.(sql.Scanner)
_, isTime := fzeroval.(*time.Time)
if (kind == reflect.Struct || kind == reflect.Slice || kind == reflect.Array) && kind != reflect.Uint8 && !isScanner && !isTime {
return false
}
} else {
fzeroval := reflect.New(rt).Interface()
kind := rt.Kind()
_, isScanner := fzeroval.(sql.Scanner)
_, isTime := fzeroval.(*time.Time)
if (kind == reflect.Struct || kind == reflect.Slice || kind == reflect.Array) && kind != reflect.Uint8 && !isScanner && !isTime {
return false
}
}
return true
} | [
"func",
"Scannable",
"(",
"rt",
"reflect",
".",
"Type",
")",
"bool",
"{",
"if",
"rt",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Ptr",
"{",
"fzeroval",
":=",
"reflect",
".",
"New",
"(",
"rt",
".",
"Elem",
"(",
")",
")",
".",
"Interface",
"(",
")",
"\n",
"kind",
":=",
"rt",
".",
"Elem",
"(",
")",
".",
"Kind",
"(",
")",
"\n",
"_",
",",
"isScanner",
":=",
"fzeroval",
".",
"(",
"sql",
".",
"Scanner",
")",
"\n",
"_",
",",
"isTime",
":=",
"fzeroval",
".",
"(",
"*",
"time",
".",
"Time",
")",
"\n\n",
"if",
"(",
"kind",
"==",
"reflect",
".",
"Struct",
"||",
"kind",
"==",
"reflect",
".",
"Slice",
"||",
"kind",
"==",
"reflect",
".",
"Array",
")",
"&&",
"kind",
"!=",
"reflect",
".",
"Uint8",
"&&",
"!",
"isScanner",
"&&",
"!",
"isTime",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"else",
"{",
"fzeroval",
":=",
"reflect",
".",
"New",
"(",
"rt",
")",
".",
"Interface",
"(",
")",
"\n",
"kind",
":=",
"rt",
".",
"Kind",
"(",
")",
"\n",
"_",
",",
"isScanner",
":=",
"fzeroval",
".",
"(",
"sql",
".",
"Scanner",
")",
"\n",
"_",
",",
"isTime",
":=",
"fzeroval",
".",
"(",
"*",
"time",
".",
"Time",
")",
"\n\n",
"if",
"(",
"kind",
"==",
"reflect",
".",
"Struct",
"||",
"kind",
"==",
"reflect",
".",
"Slice",
"||",
"kind",
"==",
"reflect",
".",
"Array",
")",
"&&",
"kind",
"!=",
"reflect",
".",
"Uint8",
"&&",
"!",
"isScanner",
"&&",
"!",
"isTime",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // Scannable checks whether type is scannable. | [
"Scannable",
"checks",
"whether",
"type",
"is",
"scannable",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/internal/scannable.go#L10-L31 |
9,771 | Fs02/grimoire | changeset/convert.go | Convert | func Convert(data interface{}) *Changeset {
ch := &Changeset{}
ch.values = make(map[string]interface{})
ch.changes, ch.types, _ = mapSchema(data)
return ch
} | go | func Convert(data interface{}) *Changeset {
ch := &Changeset{}
ch.values = make(map[string]interface{})
ch.changes, ch.types, _ = mapSchema(data)
return ch
} | [
"func",
"Convert",
"(",
"data",
"interface",
"{",
"}",
")",
"*",
"Changeset",
"{",
"ch",
":=",
"&",
"Changeset",
"{",
"}",
"\n",
"ch",
".",
"values",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"ch",
".",
"changes",
",",
"ch",
".",
"types",
",",
"_",
"=",
"mapSchema",
"(",
"data",
")",
"\n\n",
"return",
"ch",
"\n",
"}"
] | // Convert a struct as changeset, every field's value will be treated as changes. Returns a new changeset. | [
"Convert",
"a",
"struct",
"as",
"changeset",
"every",
"field",
"s",
"value",
"will",
"be",
"treated",
"as",
"changes",
".",
"Returns",
"a",
"new",
"changeset",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/changeset/convert.go#L4-L10 |
9,772 | Fs02/grimoire | adapter/specs/query.go | QueryJoin | func QueryJoin(t *testing.T, repo grimoire.Repo) {
tests := []grimoire.Query{
repo.From(addresses).Join(users),
repo.From(addresses).Join(users, c.Eq(c.I("addresses.user_id"), c.I("users.id"))),
repo.From(addresses).Join(users).Find(1),
repo.From(addresses).Join(users).Where(c.Eq(address, "address1")),
repo.From(addresses).Join(users).Where(c.Eq(address, "address1")).Order(c.Asc(name)),
repo.From(addresses).JoinWith("LEFT JOIN", users),
repo.From(addresses).JoinWith("LEFT OUTER JOIN", users),
}
run(t, tests)
} | go | func QueryJoin(t *testing.T, repo grimoire.Repo) {
tests := []grimoire.Query{
repo.From(addresses).Join(users),
repo.From(addresses).Join(users, c.Eq(c.I("addresses.user_id"), c.I("users.id"))),
repo.From(addresses).Join(users).Find(1),
repo.From(addresses).Join(users).Where(c.Eq(address, "address1")),
repo.From(addresses).Join(users).Where(c.Eq(address, "address1")).Order(c.Asc(name)),
repo.From(addresses).JoinWith("LEFT JOIN", users),
repo.From(addresses).JoinWith("LEFT OUTER JOIN", users),
}
run(t, tests)
} | [
"func",
"QueryJoin",
"(",
"t",
"*",
"testing",
".",
"T",
",",
"repo",
"grimoire",
".",
"Repo",
")",
"{",
"tests",
":=",
"[",
"]",
"grimoire",
".",
"Query",
"{",
"repo",
".",
"From",
"(",
"addresses",
")",
".",
"Join",
"(",
"users",
")",
",",
"repo",
".",
"From",
"(",
"addresses",
")",
".",
"Join",
"(",
"users",
",",
"c",
".",
"Eq",
"(",
"c",
".",
"I",
"(",
"\"",
"\"",
")",
",",
"c",
".",
"I",
"(",
"\"",
"\"",
")",
")",
")",
",",
"repo",
".",
"From",
"(",
"addresses",
")",
".",
"Join",
"(",
"users",
")",
".",
"Find",
"(",
"1",
")",
",",
"repo",
".",
"From",
"(",
"addresses",
")",
".",
"Join",
"(",
"users",
")",
".",
"Where",
"(",
"c",
".",
"Eq",
"(",
"address",
",",
"\"",
"\"",
")",
")",
",",
"repo",
".",
"From",
"(",
"addresses",
")",
".",
"Join",
"(",
"users",
")",
".",
"Where",
"(",
"c",
".",
"Eq",
"(",
"address",
",",
"\"",
"\"",
")",
")",
".",
"Order",
"(",
"c",
".",
"Asc",
"(",
"name",
")",
")",
",",
"repo",
".",
"From",
"(",
"addresses",
")",
".",
"JoinWith",
"(",
"\"",
"\"",
",",
"users",
")",
",",
"repo",
".",
"From",
"(",
"addresses",
")",
".",
"JoinWith",
"(",
"\"",
"\"",
",",
"users",
")",
",",
"}",
"\n\n",
"run",
"(",
"t",
",",
"tests",
")",
"\n",
"}"
] | // QueryJoin tests query specifications with join. | [
"QueryJoin",
"tests",
"query",
"specifications",
"with",
"join",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/specs/query.go#L66-L78 |
9,773 | Fs02/grimoire | adapter/specs/query.go | QueryNotFound | func QueryNotFound(t *testing.T, repo grimoire.Repo) {
t.Run("NotFound", func(t *testing.T) {
user := User{}
// find user error not found
err := repo.From("users").Find(0).One(&user)
assert.NotNil(t, err)
assert.Equal(t, errors.NotFound, err.(errors.Error).Kind())
})
} | go | func QueryNotFound(t *testing.T, repo grimoire.Repo) {
t.Run("NotFound", func(t *testing.T) {
user := User{}
// find user error not found
err := repo.From("users").Find(0).One(&user)
assert.NotNil(t, err)
assert.Equal(t, errors.NotFound, err.(errors.Error).Kind())
})
} | [
"func",
"QueryNotFound",
"(",
"t",
"*",
"testing",
".",
"T",
",",
"repo",
"grimoire",
".",
"Repo",
")",
"{",
"t",
".",
"Run",
"(",
"\"",
"\"",
",",
"func",
"(",
"t",
"*",
"testing",
".",
"T",
")",
"{",
"user",
":=",
"User",
"{",
"}",
"\n\n",
"// find user error not found",
"err",
":=",
"repo",
".",
"From",
"(",
"\"",
"\"",
")",
".",
"Find",
"(",
"0",
")",
".",
"One",
"(",
"&",
"user",
")",
"\n",
"assert",
".",
"NotNil",
"(",
"t",
",",
"err",
")",
"\n",
"assert",
".",
"Equal",
"(",
"t",
",",
"errors",
".",
"NotFound",
",",
"err",
".",
"(",
"errors",
".",
"Error",
")",
".",
"Kind",
"(",
")",
")",
"\n",
"}",
")",
"\n",
"}"
] | // QueryNotFound tests query specifications when no result found. | [
"QueryNotFound",
"tests",
"query",
"specifications",
"when",
"no",
"result",
"found",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/specs/query.go#L81-L90 |
9,774 | Fs02/grimoire | changeset/validate_min.go | ValidateMin | func ValidateMin(ch *Changeset, field string, min int, opts ...Option) {
val, exist := ch.changes[field]
if !exist {
return
}
options := Options{
message: ValidateMinErrorMessage,
}
options.apply(opts)
invalid := false
switch v := val.(type) {
case string:
invalid = len(v) < min
case []interface{}:
invalid = len(v) < min
case []*Changeset:
invalid = len(v) < min
case int:
invalid = v < min
case int8:
invalid = v < int8(min)
case int16:
invalid = v < int16(min)
case int32:
invalid = v < int32(min)
case int64:
invalid = v < int64(min)
case uint:
invalid = v < uint(min)
case uint8:
invalid = v < uint8(min)
case uint16:
invalid = v < uint16(min)
case uint32:
invalid = v < uint32(min)
case uint64:
invalid = v < uint64(min)
case uintptr:
invalid = v < uintptr(min)
case float32:
invalid = v < float32(min)
case float64:
invalid = v < float64(min)
}
if invalid {
r := strings.NewReplacer("{field}", field, "{min}", strconv.Itoa(min))
AddError(ch, field, r.Replace(options.message))
}
} | go | func ValidateMin(ch *Changeset, field string, min int, opts ...Option) {
val, exist := ch.changes[field]
if !exist {
return
}
options := Options{
message: ValidateMinErrorMessage,
}
options.apply(opts)
invalid := false
switch v := val.(type) {
case string:
invalid = len(v) < min
case []interface{}:
invalid = len(v) < min
case []*Changeset:
invalid = len(v) < min
case int:
invalid = v < min
case int8:
invalid = v < int8(min)
case int16:
invalid = v < int16(min)
case int32:
invalid = v < int32(min)
case int64:
invalid = v < int64(min)
case uint:
invalid = v < uint(min)
case uint8:
invalid = v < uint8(min)
case uint16:
invalid = v < uint16(min)
case uint32:
invalid = v < uint32(min)
case uint64:
invalid = v < uint64(min)
case uintptr:
invalid = v < uintptr(min)
case float32:
invalid = v < float32(min)
case float64:
invalid = v < float64(min)
}
if invalid {
r := strings.NewReplacer("{field}", field, "{min}", strconv.Itoa(min))
AddError(ch, field, r.Replace(options.message))
}
} | [
"func",
"ValidateMin",
"(",
"ch",
"*",
"Changeset",
",",
"field",
"string",
",",
"min",
"int",
",",
"opts",
"...",
"Option",
")",
"{",
"val",
",",
"exist",
":=",
"ch",
".",
"changes",
"[",
"field",
"]",
"\n",
"if",
"!",
"exist",
"{",
"return",
"\n",
"}",
"\n\n",
"options",
":=",
"Options",
"{",
"message",
":",
"ValidateMinErrorMessage",
",",
"}",
"\n",
"options",
".",
"apply",
"(",
"opts",
")",
"\n\n",
"invalid",
":=",
"false",
"\n\n",
"switch",
"v",
":=",
"val",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"invalid",
"=",
"len",
"(",
"v",
")",
"<",
"min",
"\n",
"case",
"[",
"]",
"interface",
"{",
"}",
":",
"invalid",
"=",
"len",
"(",
"v",
")",
"<",
"min",
"\n",
"case",
"[",
"]",
"*",
"Changeset",
":",
"invalid",
"=",
"len",
"(",
"v",
")",
"<",
"min",
"\n",
"case",
"int",
":",
"invalid",
"=",
"v",
"<",
"min",
"\n",
"case",
"int8",
":",
"invalid",
"=",
"v",
"<",
"int8",
"(",
"min",
")",
"\n",
"case",
"int16",
":",
"invalid",
"=",
"v",
"<",
"int16",
"(",
"min",
")",
"\n",
"case",
"int32",
":",
"invalid",
"=",
"v",
"<",
"int32",
"(",
"min",
")",
"\n",
"case",
"int64",
":",
"invalid",
"=",
"v",
"<",
"int64",
"(",
"min",
")",
"\n",
"case",
"uint",
":",
"invalid",
"=",
"v",
"<",
"uint",
"(",
"min",
")",
"\n",
"case",
"uint8",
":",
"invalid",
"=",
"v",
"<",
"uint8",
"(",
"min",
")",
"\n",
"case",
"uint16",
":",
"invalid",
"=",
"v",
"<",
"uint16",
"(",
"min",
")",
"\n",
"case",
"uint32",
":",
"invalid",
"=",
"v",
"<",
"uint32",
"(",
"min",
")",
"\n",
"case",
"uint64",
":",
"invalid",
"=",
"v",
"<",
"uint64",
"(",
"min",
")",
"\n",
"case",
"uintptr",
":",
"invalid",
"=",
"v",
"<",
"uintptr",
"(",
"min",
")",
"\n",
"case",
"float32",
":",
"invalid",
"=",
"v",
"<",
"float32",
"(",
"min",
")",
"\n",
"case",
"float64",
":",
"invalid",
"=",
"v",
"<",
"float64",
"(",
"min",
")",
"\n",
"}",
"\n\n",
"if",
"invalid",
"{",
"r",
":=",
"strings",
".",
"NewReplacer",
"(",
"\"",
"\"",
",",
"field",
",",
"\"",
"\"",
",",
"strconv",
".",
"Itoa",
"(",
"min",
")",
")",
"\n",
"AddError",
"(",
"ch",
",",
"field",
",",
"r",
".",
"Replace",
"(",
"options",
".",
"message",
")",
")",
"\n",
"}",
"\n",
"}"
] | // ValidateMin validates the value of given field is not smaller than min.
// Validation can be performed against string, slice and numbers. | [
"ValidateMin",
"validates",
"the",
"value",
"of",
"given",
"field",
"is",
"not",
"smaller",
"than",
"min",
".",
"Validation",
"can",
"be",
"performed",
"against",
"string",
"slice",
"and",
"numbers",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/changeset/validate_min.go#L13-L65 |
9,775 | Fs02/grimoire | changeset/validate_inclusion.go | ValidateInclusion | func ValidateInclusion(ch *Changeset, field string, values []interface{}, opts ...Option) {
val, exist := ch.changes[field]
if !exist {
return
}
options := Options{
message: ValidateInclusionErrorMessage,
}
options.apply(opts)
invalid := true
for _, inval := range values {
if val == inval {
invalid = false
break
}
}
if invalid {
r := strings.NewReplacer("{field}", field, "{values}", fmt.Sprintf("%v", values))
AddError(ch, field, r.Replace(options.message))
}
} | go | func ValidateInclusion(ch *Changeset, field string, values []interface{}, opts ...Option) {
val, exist := ch.changes[field]
if !exist {
return
}
options := Options{
message: ValidateInclusionErrorMessage,
}
options.apply(opts)
invalid := true
for _, inval := range values {
if val == inval {
invalid = false
break
}
}
if invalid {
r := strings.NewReplacer("{field}", field, "{values}", fmt.Sprintf("%v", values))
AddError(ch, field, r.Replace(options.message))
}
} | [
"func",
"ValidateInclusion",
"(",
"ch",
"*",
"Changeset",
",",
"field",
"string",
",",
"values",
"[",
"]",
"interface",
"{",
"}",
",",
"opts",
"...",
"Option",
")",
"{",
"val",
",",
"exist",
":=",
"ch",
".",
"changes",
"[",
"field",
"]",
"\n",
"if",
"!",
"exist",
"{",
"return",
"\n",
"}",
"\n\n",
"options",
":=",
"Options",
"{",
"message",
":",
"ValidateInclusionErrorMessage",
",",
"}",
"\n",
"options",
".",
"apply",
"(",
"opts",
")",
"\n\n",
"invalid",
":=",
"true",
"\n",
"for",
"_",
",",
"inval",
":=",
"range",
"values",
"{",
"if",
"val",
"==",
"inval",
"{",
"invalid",
"=",
"false",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"invalid",
"{",
"r",
":=",
"strings",
".",
"NewReplacer",
"(",
"\"",
"\"",
",",
"field",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"values",
")",
")",
"\n",
"AddError",
"(",
"ch",
",",
"field",
",",
"r",
".",
"Replace",
"(",
"options",
".",
"message",
")",
")",
"\n",
"}",
"\n",
"}"
] | // ValidateInclusion validates a change is included in the given values. | [
"ValidateInclusion",
"validates",
"a",
"change",
"is",
"included",
"in",
"the",
"given",
"values",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/changeset/validate_inclusion.go#L12-L35 |
9,776 | Fs02/grimoire | changeset/put_change.go | PutChange | func PutChange(ch *Changeset, field string, value interface{}, opts ...Option) {
options := Options{
message: PutChangeErrorMessage,
}
options.apply(opts)
if typ, exist := ch.types[field]; exist {
if value != (interface{})(nil) {
valTyp := reflect.TypeOf(value)
if valTyp.Kind() == reflect.Ptr {
valTyp = valTyp.Elem()
}
if valTyp.ConvertibleTo(typ) {
ch.changes[field] = value
return
}
} else {
ch.changes[field] = reflect.Zero(reflect.PtrTo(typ)).Interface()
return
}
}
msg := strings.Replace(options.message, "{field}", field, 1)
AddError(ch, field, msg)
} | go | func PutChange(ch *Changeset, field string, value interface{}, opts ...Option) {
options := Options{
message: PutChangeErrorMessage,
}
options.apply(opts)
if typ, exist := ch.types[field]; exist {
if value != (interface{})(nil) {
valTyp := reflect.TypeOf(value)
if valTyp.Kind() == reflect.Ptr {
valTyp = valTyp.Elem()
}
if valTyp.ConvertibleTo(typ) {
ch.changes[field] = value
return
}
} else {
ch.changes[field] = reflect.Zero(reflect.PtrTo(typ)).Interface()
return
}
}
msg := strings.Replace(options.message, "{field}", field, 1)
AddError(ch, field, msg)
} | [
"func",
"PutChange",
"(",
"ch",
"*",
"Changeset",
",",
"field",
"string",
",",
"value",
"interface",
"{",
"}",
",",
"opts",
"...",
"Option",
")",
"{",
"options",
":=",
"Options",
"{",
"message",
":",
"PutChangeErrorMessage",
",",
"}",
"\n",
"options",
".",
"apply",
"(",
"opts",
")",
"\n\n",
"if",
"typ",
",",
"exist",
":=",
"ch",
".",
"types",
"[",
"field",
"]",
";",
"exist",
"{",
"if",
"value",
"!=",
"(",
"interface",
"{",
"}",
")",
"(",
"nil",
")",
"{",
"valTyp",
":=",
"reflect",
".",
"TypeOf",
"(",
"value",
")",
"\n",
"if",
"valTyp",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Ptr",
"{",
"valTyp",
"=",
"valTyp",
".",
"Elem",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"valTyp",
".",
"ConvertibleTo",
"(",
"typ",
")",
"{",
"ch",
".",
"changes",
"[",
"field",
"]",
"=",
"value",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"else",
"{",
"ch",
".",
"changes",
"[",
"field",
"]",
"=",
"reflect",
".",
"Zero",
"(",
"reflect",
".",
"PtrTo",
"(",
"typ",
")",
")",
".",
"Interface",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"msg",
":=",
"strings",
".",
"Replace",
"(",
"options",
".",
"message",
",",
"\"",
"\"",
",",
"field",
",",
"1",
")",
"\n",
"AddError",
"(",
"ch",
",",
"field",
",",
"msg",
")",
"\n",
"}"
] | // PutChange to changeset. | [
"PutChange",
"to",
"changeset",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/changeset/put_change.go#L12-L37 |
9,777 | Fs02/grimoire | changeset/validate_required.go | ValidateRequired | func ValidateRequired(ch *Changeset, fields []string, opts ...Option) {
options := Options{
message: ValidateRequiredErrorMessage,
}
options.apply(opts)
for _, f := range fields {
val, exist := ch.changes[f]
// check values if it's not exist in changeset when changeOnly is false and changeset values are all zero value
if !exist && !options.changeOnly && !ch.zero {
val, exist = ch.values[f]
}
str, isStr := val.(string)
if exist && (isStr && strings.TrimSpace(str) != "") || (!isStr && val != nil) {
continue
}
msg := strings.Replace(options.message, "{field}", f, 1)
AddError(ch, f, msg)
}
} | go | func ValidateRequired(ch *Changeset, fields []string, opts ...Option) {
options := Options{
message: ValidateRequiredErrorMessage,
}
options.apply(opts)
for _, f := range fields {
val, exist := ch.changes[f]
// check values if it's not exist in changeset when changeOnly is false and changeset values are all zero value
if !exist && !options.changeOnly && !ch.zero {
val, exist = ch.values[f]
}
str, isStr := val.(string)
if exist && (isStr && strings.TrimSpace(str) != "") || (!isStr && val != nil) {
continue
}
msg := strings.Replace(options.message, "{field}", f, 1)
AddError(ch, f, msg)
}
} | [
"func",
"ValidateRequired",
"(",
"ch",
"*",
"Changeset",
",",
"fields",
"[",
"]",
"string",
",",
"opts",
"...",
"Option",
")",
"{",
"options",
":=",
"Options",
"{",
"message",
":",
"ValidateRequiredErrorMessage",
",",
"}",
"\n",
"options",
".",
"apply",
"(",
"opts",
")",
"\n\n",
"for",
"_",
",",
"f",
":=",
"range",
"fields",
"{",
"val",
",",
"exist",
":=",
"ch",
".",
"changes",
"[",
"f",
"]",
"\n\n",
"// check values if it's not exist in changeset when changeOnly is false and changeset values are all zero value",
"if",
"!",
"exist",
"&&",
"!",
"options",
".",
"changeOnly",
"&&",
"!",
"ch",
".",
"zero",
"{",
"val",
",",
"exist",
"=",
"ch",
".",
"values",
"[",
"f",
"]",
"\n",
"}",
"\n\n",
"str",
",",
"isStr",
":=",
"val",
".",
"(",
"string",
")",
"\n",
"if",
"exist",
"&&",
"(",
"isStr",
"&&",
"strings",
".",
"TrimSpace",
"(",
"str",
")",
"!=",
"\"",
"\"",
")",
"||",
"(",
"!",
"isStr",
"&&",
"val",
"!=",
"nil",
")",
"{",
"continue",
"\n",
"}",
"\n\n",
"msg",
":=",
"strings",
".",
"Replace",
"(",
"options",
".",
"message",
",",
"\"",
"\"",
",",
"f",
",",
"1",
")",
"\n",
"AddError",
"(",
"ch",
",",
"f",
",",
"msg",
")",
"\n",
"}",
"\n",
"}"
] | // ValidateRequired validates that one or more fields are present in the changeset.
// It'll add error to changeset if field in the changes is nil or string made only of whitespace, | [
"ValidateRequired",
"validates",
"that",
"one",
"or",
"more",
"fields",
"are",
"present",
"in",
"the",
"changeset",
".",
"It",
"ll",
"add",
"error",
"to",
"changeset",
"if",
"field",
"in",
"the",
"changes",
"is",
"nil",
"or",
"string",
"made",
"only",
"of",
"whitespace"
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/changeset/validate_required.go#L12-L34 |
9,778 | Fs02/grimoire | changeset/validate_range.go | ValidateRange | func ValidateRange(ch *Changeset, field string, min int, max int, opts ...Option) {
val, exist := ch.changes[field]
if !exist {
return
}
options := Options{
message: ValidateRangeErrorMessage,
}
options.apply(opts)
invalid := false
switch v := val.(type) {
case string:
invalid = len(v) < min || len(v) > max
case []interface{}:
invalid = len(v) < min || len(v) > max
case int:
invalid = v < min || v > max
case int8:
invalid = v < int8(min) || v > int8(max)
case int16:
invalid = v < int16(min) || v > int16(max)
case int32:
invalid = v < int32(min) || v > int32(max)
case int64:
invalid = v < int64(min) || v > int64(max)
case uint:
invalid = v < uint(min) || v > uint(max)
case uint8:
invalid = v < uint8(min) || v > uint8(max)
case uint16:
invalid = v < uint16(min) || v > uint16(max)
case uint32:
invalid = v < uint32(min) || v > uint32(max)
case uint64:
invalid = v < uint64(min) || v > uint64(max)
case uintptr:
invalid = v < uintptr(min) || v > uintptr(max)
case float32:
invalid = v < float32(min) || v > float32(max)
case float64:
invalid = v < float64(min) || v > float64(max)
}
if invalid {
r := strings.NewReplacer("{field}", field, "{min}", strconv.Itoa(min), "{max}", strconv.Itoa(max))
AddError(ch, field, r.Replace(options.message))
}
} | go | func ValidateRange(ch *Changeset, field string, min int, max int, opts ...Option) {
val, exist := ch.changes[field]
if !exist {
return
}
options := Options{
message: ValidateRangeErrorMessage,
}
options.apply(opts)
invalid := false
switch v := val.(type) {
case string:
invalid = len(v) < min || len(v) > max
case []interface{}:
invalid = len(v) < min || len(v) > max
case int:
invalid = v < min || v > max
case int8:
invalid = v < int8(min) || v > int8(max)
case int16:
invalid = v < int16(min) || v > int16(max)
case int32:
invalid = v < int32(min) || v > int32(max)
case int64:
invalid = v < int64(min) || v > int64(max)
case uint:
invalid = v < uint(min) || v > uint(max)
case uint8:
invalid = v < uint8(min) || v > uint8(max)
case uint16:
invalid = v < uint16(min) || v > uint16(max)
case uint32:
invalid = v < uint32(min) || v > uint32(max)
case uint64:
invalid = v < uint64(min) || v > uint64(max)
case uintptr:
invalid = v < uintptr(min) || v > uintptr(max)
case float32:
invalid = v < float32(min) || v > float32(max)
case float64:
invalid = v < float64(min) || v > float64(max)
}
if invalid {
r := strings.NewReplacer("{field}", field, "{min}", strconv.Itoa(min), "{max}", strconv.Itoa(max))
AddError(ch, field, r.Replace(options.message))
}
} | [
"func",
"ValidateRange",
"(",
"ch",
"*",
"Changeset",
",",
"field",
"string",
",",
"min",
"int",
",",
"max",
"int",
",",
"opts",
"...",
"Option",
")",
"{",
"val",
",",
"exist",
":=",
"ch",
".",
"changes",
"[",
"field",
"]",
"\n",
"if",
"!",
"exist",
"{",
"return",
"\n",
"}",
"\n\n",
"options",
":=",
"Options",
"{",
"message",
":",
"ValidateRangeErrorMessage",
",",
"}",
"\n",
"options",
".",
"apply",
"(",
"opts",
")",
"\n\n",
"invalid",
":=",
"false",
"\n\n",
"switch",
"v",
":=",
"val",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"invalid",
"=",
"len",
"(",
"v",
")",
"<",
"min",
"||",
"len",
"(",
"v",
")",
">",
"max",
"\n",
"case",
"[",
"]",
"interface",
"{",
"}",
":",
"invalid",
"=",
"len",
"(",
"v",
")",
"<",
"min",
"||",
"len",
"(",
"v",
")",
">",
"max",
"\n",
"case",
"int",
":",
"invalid",
"=",
"v",
"<",
"min",
"||",
"v",
">",
"max",
"\n",
"case",
"int8",
":",
"invalid",
"=",
"v",
"<",
"int8",
"(",
"min",
")",
"||",
"v",
">",
"int8",
"(",
"max",
")",
"\n",
"case",
"int16",
":",
"invalid",
"=",
"v",
"<",
"int16",
"(",
"min",
")",
"||",
"v",
">",
"int16",
"(",
"max",
")",
"\n",
"case",
"int32",
":",
"invalid",
"=",
"v",
"<",
"int32",
"(",
"min",
")",
"||",
"v",
">",
"int32",
"(",
"max",
")",
"\n",
"case",
"int64",
":",
"invalid",
"=",
"v",
"<",
"int64",
"(",
"min",
")",
"||",
"v",
">",
"int64",
"(",
"max",
")",
"\n",
"case",
"uint",
":",
"invalid",
"=",
"v",
"<",
"uint",
"(",
"min",
")",
"||",
"v",
">",
"uint",
"(",
"max",
")",
"\n",
"case",
"uint8",
":",
"invalid",
"=",
"v",
"<",
"uint8",
"(",
"min",
")",
"||",
"v",
">",
"uint8",
"(",
"max",
")",
"\n",
"case",
"uint16",
":",
"invalid",
"=",
"v",
"<",
"uint16",
"(",
"min",
")",
"||",
"v",
">",
"uint16",
"(",
"max",
")",
"\n",
"case",
"uint32",
":",
"invalid",
"=",
"v",
"<",
"uint32",
"(",
"min",
")",
"||",
"v",
">",
"uint32",
"(",
"max",
")",
"\n",
"case",
"uint64",
":",
"invalid",
"=",
"v",
"<",
"uint64",
"(",
"min",
")",
"||",
"v",
">",
"uint64",
"(",
"max",
")",
"\n",
"case",
"uintptr",
":",
"invalid",
"=",
"v",
"<",
"uintptr",
"(",
"min",
")",
"||",
"v",
">",
"uintptr",
"(",
"max",
")",
"\n",
"case",
"float32",
":",
"invalid",
"=",
"v",
"<",
"float32",
"(",
"min",
")",
"||",
"v",
">",
"float32",
"(",
"max",
")",
"\n",
"case",
"float64",
":",
"invalid",
"=",
"v",
"<",
"float64",
"(",
"min",
")",
"||",
"v",
">",
"float64",
"(",
"max",
")",
"\n",
"}",
"\n\n",
"if",
"invalid",
"{",
"r",
":=",
"strings",
".",
"NewReplacer",
"(",
"\"",
"\"",
",",
"field",
",",
"\"",
"\"",
",",
"strconv",
".",
"Itoa",
"(",
"min",
")",
",",
"\"",
"\"",
",",
"strconv",
".",
"Itoa",
"(",
"max",
")",
")",
"\n",
"AddError",
"(",
"ch",
",",
"field",
",",
"r",
".",
"Replace",
"(",
"options",
".",
"message",
")",
")",
"\n",
"}",
"\n",
"}"
] | // ValidateRange validates the value of given field is not larger than max and not smaller than min.
// Validation can be performed against string, slice and numbers. | [
"ValidateRange",
"validates",
"the",
"value",
"of",
"given",
"field",
"is",
"not",
"larger",
"than",
"max",
"and",
"not",
"smaller",
"than",
"min",
".",
"Validation",
"can",
"be",
"performed",
"against",
"string",
"slice",
"and",
"numbers",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/changeset/validate_range.go#L13-L63 |
9,779 | Fs02/grimoire | repo.go | New | func New(adapter Adapter) Repo {
return Repo{
adapter: adapter,
logger: []Logger{DefaultLogger},
}
} | go | func New(adapter Adapter) Repo {
return Repo{
adapter: adapter,
logger: []Logger{DefaultLogger},
}
} | [
"func",
"New",
"(",
"adapter",
"Adapter",
")",
"Repo",
"{",
"return",
"Repo",
"{",
"adapter",
":",
"adapter",
",",
"logger",
":",
"[",
"]",
"Logger",
"{",
"DefaultLogger",
"}",
",",
"}",
"\n",
"}"
] | // New create new repo using adapter. | [
"New",
"create",
"new",
"repo",
"using",
"adapter",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/repo.go#L15-L20 |
9,780 | Fs02/grimoire | repo.go | From | func (repo Repo) From(collection string) Query {
return Query{
repo: &repo,
Collection: collection,
Fields: []string{collection + ".*"},
}
} | go | func (repo Repo) From(collection string) Query {
return Query{
repo: &repo,
Collection: collection,
Fields: []string{collection + ".*"},
}
} | [
"func",
"(",
"repo",
"Repo",
")",
"From",
"(",
"collection",
"string",
")",
"Query",
"{",
"return",
"Query",
"{",
"repo",
":",
"&",
"repo",
",",
"Collection",
":",
"collection",
",",
"Fields",
":",
"[",
"]",
"string",
"{",
"collection",
"+",
"\"",
"\"",
"}",
",",
"}",
"\n",
"}"
] | // From initiates a query for a collection. | [
"From",
"initiates",
"a",
"query",
"for",
"a",
"collection",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/repo.go#L33-L39 |
9,781 | Fs02/grimoire | repo.go | Transaction | func (repo Repo) Transaction(fn func(Repo) error) error {
adp, err := repo.adapter.Begin()
if err != nil {
return err
}
txRepo := New(adp)
txRepo.inTransaction = true
func() {
defer func() {
if p := recover(); p != nil {
txRepo.adapter.Rollback()
if e, ok := p.(errors.Error); ok && e.Kind() != errors.Unexpected {
err = e
} else {
panic(p) // re-throw panic after Rollback
}
} else if err != nil {
txRepo.adapter.Rollback()
} else {
err = txRepo.adapter.Commit()
}
}()
err = fn(txRepo)
}()
return err
} | go | func (repo Repo) Transaction(fn func(Repo) error) error {
adp, err := repo.adapter.Begin()
if err != nil {
return err
}
txRepo := New(adp)
txRepo.inTransaction = true
func() {
defer func() {
if p := recover(); p != nil {
txRepo.adapter.Rollback()
if e, ok := p.(errors.Error); ok && e.Kind() != errors.Unexpected {
err = e
} else {
panic(p) // re-throw panic after Rollback
}
} else if err != nil {
txRepo.adapter.Rollback()
} else {
err = txRepo.adapter.Commit()
}
}()
err = fn(txRepo)
}()
return err
} | [
"func",
"(",
"repo",
"Repo",
")",
"Transaction",
"(",
"fn",
"func",
"(",
"Repo",
")",
"error",
")",
"error",
"{",
"adp",
",",
"err",
":=",
"repo",
".",
"adapter",
".",
"Begin",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"txRepo",
":=",
"New",
"(",
"adp",
")",
"\n",
"txRepo",
".",
"inTransaction",
"=",
"true",
"\n\n",
"func",
"(",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"if",
"p",
":=",
"recover",
"(",
")",
";",
"p",
"!=",
"nil",
"{",
"txRepo",
".",
"adapter",
".",
"Rollback",
"(",
")",
"\n\n",
"if",
"e",
",",
"ok",
":=",
"p",
".",
"(",
"errors",
".",
"Error",
")",
";",
"ok",
"&&",
"e",
".",
"Kind",
"(",
")",
"!=",
"errors",
".",
"Unexpected",
"{",
"err",
"=",
"e",
"\n",
"}",
"else",
"{",
"panic",
"(",
"p",
")",
"// re-throw panic after Rollback",
"\n",
"}",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"txRepo",
".",
"adapter",
".",
"Rollback",
"(",
")",
"\n",
"}",
"else",
"{",
"err",
"=",
"txRepo",
".",
"adapter",
".",
"Commit",
"(",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"err",
"=",
"fn",
"(",
"txRepo",
")",
"\n",
"}",
"(",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] | // Transaction performs transaction with given function argument. | [
"Transaction",
"performs",
"transaction",
"with",
"given",
"function",
"argument",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/repo.go#L42-L72 |
9,782 | Fs02/grimoire | changeset/changeset.go | Error | func (changeset *Changeset) Error() error {
if changeset.errors != nil {
return changeset.errors[0]
}
return nil
} | go | func (changeset *Changeset) Error() error {
if changeset.errors != nil {
return changeset.errors[0]
}
return nil
} | [
"func",
"(",
"changeset",
"*",
"Changeset",
")",
"Error",
"(",
")",
"error",
"{",
"if",
"changeset",
".",
"errors",
"!=",
"nil",
"{",
"return",
"changeset",
".",
"errors",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Error of changeset, returns the first error if any. | [
"Error",
"of",
"changeset",
"returns",
"the",
"first",
"error",
"if",
"any",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/changeset/changeset.go#L27-L32 |
9,783 | Fs02/grimoire | changeset/changeset.go | Fetch | func (changeset *Changeset) Fetch(field string) interface{} {
if change, ok := changeset.changes[field]; ok {
return change
}
return changeset.values[field]
} | go | func (changeset *Changeset) Fetch(field string) interface{} {
if change, ok := changeset.changes[field]; ok {
return change
}
return changeset.values[field]
} | [
"func",
"(",
"changeset",
"*",
"Changeset",
")",
"Fetch",
"(",
"field",
"string",
")",
"interface",
"{",
"}",
"{",
"if",
"change",
",",
"ok",
":=",
"changeset",
".",
"changes",
"[",
"field",
"]",
";",
"ok",
"{",
"return",
"change",
"\n",
"}",
"\n\n",
"return",
"changeset",
".",
"values",
"[",
"field",
"]",
"\n",
"}"
] | // Fetch a change or value from changeset. | [
"Fetch",
"a",
"change",
"or",
"value",
"from",
"changeset",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/changeset/changeset.go#L40-L46 |
9,784 | Fs02/grimoire | query.go | Select | func (query Query) Select(fields ...string) Query {
query.Fields = fields
return query
} | go | func (query Query) Select(fields ...string) Query {
query.Fields = fields
return query
} | [
"func",
"(",
"query",
"Query",
")",
"Select",
"(",
"fields",
"...",
"string",
")",
"Query",
"{",
"query",
".",
"Fields",
"=",
"fields",
"\n",
"return",
"query",
"\n",
"}"
] | // Select filter fields to be selected from database. | [
"Select",
"filter",
"fields",
"to",
"be",
"selected",
"from",
"database",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L35-L38 |
9,785 | Fs02/grimoire | query.go | Join | func (query Query) Join(collection string, condition ...c.Condition) Query {
return query.JoinWith("JOIN", collection, condition...)
} | go | func (query Query) Join(collection string, condition ...c.Condition) Query {
return query.JoinWith("JOIN", collection, condition...)
} | [
"func",
"(",
"query",
"Query",
")",
"Join",
"(",
"collection",
"string",
",",
"condition",
"...",
"c",
".",
"Condition",
")",
"Query",
"{",
"return",
"query",
".",
"JoinWith",
"(",
"\"",
"\"",
",",
"collection",
",",
"condition",
"...",
")",
"\n",
"}"
] | // Join current collection with other collection. | [
"Join",
"current",
"collection",
"with",
"other",
"collection",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L47-L49 |
9,786 | Fs02/grimoire | query.go | JoinWith | func (query Query) JoinWith(mode string, collection string, condition ...c.Condition) Query {
if len(condition) == 0 {
query.JoinClause = append(query.JoinClause, c.Join{
Mode: mode,
Collection: collection,
Condition: c.And(c.Eq(
c.I(query.Collection+"."+strings.TrimSuffix(collection, "s")+"_id"),
c.I(collection+".id"),
)),
})
} else {
query.JoinClause = append(query.JoinClause, c.Join{
Mode: mode,
Collection: collection,
Condition: c.And(condition...),
})
}
return query
} | go | func (query Query) JoinWith(mode string, collection string, condition ...c.Condition) Query {
if len(condition) == 0 {
query.JoinClause = append(query.JoinClause, c.Join{
Mode: mode,
Collection: collection,
Condition: c.And(c.Eq(
c.I(query.Collection+"."+strings.TrimSuffix(collection, "s")+"_id"),
c.I(collection+".id"),
)),
})
} else {
query.JoinClause = append(query.JoinClause, c.Join{
Mode: mode,
Collection: collection,
Condition: c.And(condition...),
})
}
return query
} | [
"func",
"(",
"query",
"Query",
")",
"JoinWith",
"(",
"mode",
"string",
",",
"collection",
"string",
",",
"condition",
"...",
"c",
".",
"Condition",
")",
"Query",
"{",
"if",
"len",
"(",
"condition",
")",
"==",
"0",
"{",
"query",
".",
"JoinClause",
"=",
"append",
"(",
"query",
".",
"JoinClause",
",",
"c",
".",
"Join",
"{",
"Mode",
":",
"mode",
",",
"Collection",
":",
"collection",
",",
"Condition",
":",
"c",
".",
"And",
"(",
"c",
".",
"Eq",
"(",
"c",
".",
"I",
"(",
"query",
".",
"Collection",
"+",
"\"",
"\"",
"+",
"strings",
".",
"TrimSuffix",
"(",
"collection",
",",
"\"",
"\"",
")",
"+",
"\"",
"\"",
")",
",",
"c",
".",
"I",
"(",
"collection",
"+",
"\"",
"\"",
")",
",",
")",
")",
",",
"}",
")",
"\n",
"}",
"else",
"{",
"query",
".",
"JoinClause",
"=",
"append",
"(",
"query",
".",
"JoinClause",
",",
"c",
".",
"Join",
"{",
"Mode",
":",
"mode",
",",
"Collection",
":",
"collection",
",",
"Condition",
":",
"c",
".",
"And",
"(",
"condition",
"...",
")",
",",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"query",
"\n",
"}"
] | // JoinWith current collection with other collection with custom join mode. | [
"JoinWith",
"current",
"collection",
"with",
"other",
"collection",
"with",
"custom",
"join",
"mode",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L52-L71 |
9,787 | Fs02/grimoire | query.go | Where | func (query Query) Where(condition ...c.Condition) Query {
query.Condition = query.Condition.And(condition...)
return query
} | go | func (query Query) Where(condition ...c.Condition) Query {
query.Condition = query.Condition.And(condition...)
return query
} | [
"func",
"(",
"query",
"Query",
")",
"Where",
"(",
"condition",
"...",
"c",
".",
"Condition",
")",
"Query",
"{",
"query",
".",
"Condition",
"=",
"query",
".",
"Condition",
".",
"And",
"(",
"condition",
"...",
")",
"\n",
"return",
"query",
"\n",
"}"
] | // Where expressions are used to filter the result set. If there is more than one where expression, they are combined with an and operator. | [
"Where",
"expressions",
"are",
"used",
"to",
"filter",
"the",
"result",
"set",
".",
"If",
"there",
"is",
"more",
"than",
"one",
"where",
"expression",
"they",
"are",
"combined",
"with",
"an",
"and",
"operator",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L74-L77 |
9,788 | Fs02/grimoire | query.go | OrWhere | func (query Query) OrWhere(condition ...c.Condition) Query {
query.Condition = query.Condition.Or(c.And(condition...))
return query
} | go | func (query Query) OrWhere(condition ...c.Condition) Query {
query.Condition = query.Condition.Or(c.And(condition...))
return query
} | [
"func",
"(",
"query",
"Query",
")",
"OrWhere",
"(",
"condition",
"...",
"c",
".",
"Condition",
")",
"Query",
"{",
"query",
".",
"Condition",
"=",
"query",
".",
"Condition",
".",
"Or",
"(",
"c",
".",
"And",
"(",
"condition",
"...",
")",
")",
"\n",
"return",
"query",
"\n",
"}"
] | // OrWhere behaves exactly the same as where except it combines with any previous expression by using an OR. | [
"OrWhere",
"behaves",
"exactly",
"the",
"same",
"as",
"where",
"except",
"it",
"combines",
"with",
"any",
"previous",
"expression",
"by",
"using",
"an",
"OR",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L80-L83 |
9,789 | Fs02/grimoire | query.go | Group | func (query Query) Group(fields ...string) Query {
query.GroupFields = fields
return query
} | go | func (query Query) Group(fields ...string) Query {
query.GroupFields = fields
return query
} | [
"func",
"(",
"query",
"Query",
")",
"Group",
"(",
"fields",
"...",
"string",
")",
"Query",
"{",
"query",
".",
"GroupFields",
"=",
"fields",
"\n",
"return",
"query",
"\n",
"}"
] | // Group query using fields. | [
"Group",
"query",
"using",
"fields",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L86-L89 |
9,790 | Fs02/grimoire | query.go | Having | func (query Query) Having(condition ...c.Condition) Query {
query.HavingCondition = query.HavingCondition.And(condition...)
return query
} | go | func (query Query) Having(condition ...c.Condition) Query {
query.HavingCondition = query.HavingCondition.And(condition...)
return query
} | [
"func",
"(",
"query",
"Query",
")",
"Having",
"(",
"condition",
"...",
"c",
".",
"Condition",
")",
"Query",
"{",
"query",
".",
"HavingCondition",
"=",
"query",
".",
"HavingCondition",
".",
"And",
"(",
"condition",
"...",
")",
"\n",
"return",
"query",
"\n",
"}"
] | // Having adds condition for group query. | [
"Having",
"adds",
"condition",
"for",
"group",
"query",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L92-L95 |
9,791 | Fs02/grimoire | query.go | OrHaving | func (query Query) OrHaving(condition ...c.Condition) Query {
query.HavingCondition = query.HavingCondition.Or(c.And(condition...))
return query
} | go | func (query Query) OrHaving(condition ...c.Condition) Query {
query.HavingCondition = query.HavingCondition.Or(c.And(condition...))
return query
} | [
"func",
"(",
"query",
"Query",
")",
"OrHaving",
"(",
"condition",
"...",
"c",
".",
"Condition",
")",
"Query",
"{",
"query",
".",
"HavingCondition",
"=",
"query",
".",
"HavingCondition",
".",
"Or",
"(",
"c",
".",
"And",
"(",
"condition",
"...",
")",
")",
"\n",
"return",
"query",
"\n",
"}"
] | // OrHaving behaves exactly the same as having except it combines with any previous expression by using an OR. | [
"OrHaving",
"behaves",
"exactly",
"the",
"same",
"as",
"having",
"except",
"it",
"combines",
"with",
"any",
"previous",
"expression",
"by",
"using",
"an",
"OR",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L98-L101 |
9,792 | Fs02/grimoire | query.go | Order | func (query Query) Order(order ...c.Order) Query {
query.OrderClause = append(query.OrderClause, order...)
return query
} | go | func (query Query) Order(order ...c.Order) Query {
query.OrderClause = append(query.OrderClause, order...)
return query
} | [
"func",
"(",
"query",
"Query",
")",
"Order",
"(",
"order",
"...",
"c",
".",
"Order",
")",
"Query",
"{",
"query",
".",
"OrderClause",
"=",
"append",
"(",
"query",
".",
"OrderClause",
",",
"order",
"...",
")",
"\n",
"return",
"query",
"\n",
"}"
] | // Order the result returned by database. | [
"Order",
"the",
"result",
"returned",
"by",
"database",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L104-L107 |
9,793 | Fs02/grimoire | query.go | Offset | func (query Query) Offset(offset int) Query {
query.OffsetResult = offset
return query
} | go | func (query Query) Offset(offset int) Query {
query.OffsetResult = offset
return query
} | [
"func",
"(",
"query",
"Query",
")",
"Offset",
"(",
"offset",
"int",
")",
"Query",
"{",
"query",
".",
"OffsetResult",
"=",
"offset",
"\n",
"return",
"query",
"\n",
"}"
] | // Offset the result returned by database. | [
"Offset",
"the",
"result",
"returned",
"by",
"database",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L110-L113 |
9,794 | Fs02/grimoire | query.go | Limit | func (query Query) Limit(limit int) Query {
query.LimitResult = limit
return query
} | go | func (query Query) Limit(limit int) Query {
query.LimitResult = limit
return query
} | [
"func",
"(",
"query",
"Query",
")",
"Limit",
"(",
"limit",
"int",
")",
"Query",
"{",
"query",
".",
"LimitResult",
"=",
"limit",
"\n",
"return",
"query",
"\n",
"}"
] | // Limit result returned by database. | [
"Limit",
"result",
"returned",
"by",
"database",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L116-L119 |
9,795 | Fs02/grimoire | query.go | Lock | func (query Query) Lock(lock ...string) Query {
if !query.repo.inTransaction {
return query
}
if len(lock) > 0 {
query.LockClause = lock[0]
} else {
query.LockClause = "FOR UPDATE"
}
return query
} | go | func (query Query) Lock(lock ...string) Query {
if !query.repo.inTransaction {
return query
}
if len(lock) > 0 {
query.LockClause = lock[0]
} else {
query.LockClause = "FOR UPDATE"
}
return query
} | [
"func",
"(",
"query",
"Query",
")",
"Lock",
"(",
"lock",
"...",
"string",
")",
"Query",
"{",
"if",
"!",
"query",
".",
"repo",
".",
"inTransaction",
"{",
"return",
"query",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"lock",
")",
">",
"0",
"{",
"query",
".",
"LockClause",
"=",
"lock",
"[",
"0",
"]",
"\n",
"}",
"else",
"{",
"query",
".",
"LockClause",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"query",
"\n",
"}"
] | // Lock query using pessimistic locking.
// Lock expression can be specified as first parameter, default to FOR UPDATE. | [
"Lock",
"query",
"using",
"pessimistic",
"locking",
".",
"Lock",
"expression",
"can",
"be",
"specified",
"as",
"first",
"parameter",
"default",
"to",
"FOR",
"UPDATE",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L123-L135 |
9,796 | Fs02/grimoire | query.go | FindBy | func (query Query) FindBy(col string, val interface{}) Query {
return query.Where(c.Eq(c.I(query.Collection+"."+col), val))
} | go | func (query Query) FindBy(col string, val interface{}) Query {
return query.Where(c.Eq(c.I(query.Collection+"."+col), val))
} | [
"func",
"(",
"query",
"Query",
")",
"FindBy",
"(",
"col",
"string",
",",
"val",
"interface",
"{",
"}",
")",
"Query",
"{",
"return",
"query",
".",
"Where",
"(",
"c",
".",
"Eq",
"(",
"c",
".",
"I",
"(",
"query",
".",
"Collection",
"+",
"\"",
"\"",
"+",
"col",
")",
",",
"val",
")",
")",
"\n",
"}"
] | // FindBy adds where col=? into query. | [
"FindBy",
"adds",
"where",
"col",
"=",
"?",
"into",
"query",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L144-L146 |
9,797 | Fs02/grimoire | query.go | Set | func (query Query) Set(field string, value interface{}) Query {
if query.Changes == nil {
query.Changes = make(map[string]interface{})
}
query.Changes[field] = value
return query
} | go | func (query Query) Set(field string, value interface{}) Query {
if query.Changes == nil {
query.Changes = make(map[string]interface{})
}
query.Changes[field] = value
return query
} | [
"func",
"(",
"query",
"Query",
")",
"Set",
"(",
"field",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"Query",
"{",
"if",
"query",
".",
"Changes",
"==",
"nil",
"{",
"query",
".",
"Changes",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"}",
"\n\n",
"query",
".",
"Changes",
"[",
"field",
"]",
"=",
"value",
"\n",
"return",
"query",
"\n",
"}"
] | // Set value for insert or update operation that will replace changeset value. | [
"Set",
"value",
"for",
"insert",
"or",
"update",
"operation",
"that",
"will",
"replace",
"changeset",
"value",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L149-L156 |
9,798 | Fs02/grimoire | query.go | One | func (query Query) One(record interface{}) error {
query.LimitResult = 1
count, err := query.repo.adapter.All(query, record, query.repo.logger...)
if err != nil {
return transformError(err)
} else if count == 0 {
return errors.New("no result found", "", errors.NotFound)
} else {
return nil
}
} | go | func (query Query) One(record interface{}) error {
query.LimitResult = 1
count, err := query.repo.adapter.All(query, record, query.repo.logger...)
if err != nil {
return transformError(err)
} else if count == 0 {
return errors.New("no result found", "", errors.NotFound)
} else {
return nil
}
} | [
"func",
"(",
"query",
"Query",
")",
"One",
"(",
"record",
"interface",
"{",
"}",
")",
"error",
"{",
"query",
".",
"LimitResult",
"=",
"1",
"\n",
"count",
",",
"err",
":=",
"query",
".",
"repo",
".",
"adapter",
".",
"All",
"(",
"query",
",",
"record",
",",
"query",
".",
"repo",
".",
"logger",
"...",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"transformError",
"(",
"err",
")",
"\n",
"}",
"else",
"if",
"count",
"==",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"errors",
".",
"NotFound",
")",
"\n",
"}",
"else",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // One retrieves one result that match the query.
// If no result found, it'll return not found error. | [
"One",
"retrieves",
"one",
"result",
"that",
"match",
"the",
"query",
".",
"If",
"no",
"result",
"found",
"it",
"ll",
"return",
"not",
"found",
"error",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L160-L171 |
9,799 | Fs02/grimoire | query.go | All | func (query Query) All(record interface{}) error {
_, err := query.repo.adapter.All(query, record, query.repo.logger...)
return err
} | go | func (query Query) All(record interface{}) error {
_, err := query.repo.adapter.All(query, record, query.repo.logger...)
return err
} | [
"func",
"(",
"query",
"Query",
")",
"All",
"(",
"record",
"interface",
"{",
"}",
")",
"error",
"{",
"_",
",",
"err",
":=",
"query",
".",
"repo",
".",
"adapter",
".",
"All",
"(",
"query",
",",
"record",
",",
"query",
".",
"repo",
".",
"logger",
"...",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // All retrieves all results that match the query. | [
"All",
"retrieves",
"all",
"results",
"that",
"match",
"the",
"query",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L180-L183 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.