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
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
153,300
alexkappa/mustache
mustache.go
Parse
func Parse(r io.Reader) (*Template, error) { t := New() err := t.Parse(r) return t, err }
go
func Parse(r io.Reader) (*Template, error) { t := New() err := t.Parse(r) return t, err }
[ "func", "Parse", "(", "r", "io", ".", "Reader", ")", "(", "*", "Template", ",", "error", ")", "{", "t", ":=", "New", "(", ")", "\n", "err", ":=", "t", ".", "Parse", "(", "r", ")", "\n", "return", "t", ",", "err", "\n", "}" ]
// Parse wraps the creation of a new template and parsing from r in one go.
[ "Parse", "wraps", "the", "creation", "of", "a", "new", "template", "and", "parsing", "from", "r", "in", "one", "go", "." ]
d29845f60a879542625ba65812ddfb99fd9b12b9
https://github.com/alexkappa/mustache/blob/d29845f60a879542625ba65812ddfb99fd9b12b9/mustache.go#L330-L334
153,301
alexkappa/mustache
mustache.go
Render
func Render(r io.Reader, w io.Writer, context ...interface{}) error { t, err := Parse(r) if err != nil { return err } return t.Render(w, context...) }
go
func Render(r io.Reader, w io.Writer, context ...interface{}) error { t, err := Parse(r) if err != nil { return err } return t.Render(w, context...) }
[ "func", "Render", "(", "r", "io", ".", "Reader", ",", "w", "io", ".", "Writer", ",", "context", "...", "interface", "{", "}", ")", "error", "{", "t", ",", "err", ":=", "Parse", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err"...
// Render wraps the parsing and rendering into a single function.
[ "Render", "wraps", "the", "parsing", "and", "rendering", "into", "a", "single", "function", "." ]
d29845f60a879542625ba65812ddfb99fd9b12b9
https://github.com/alexkappa/mustache/blob/d29845f60a879542625ba65812ddfb99fd9b12b9/mustache.go#L337-L343
153,302
tmc/dot
dot.go
SameRank
func (g *Graph) SameRank(nodes []string) { g.sameRank = append(g.sameRank, nodes) }
go
func (g *Graph) SameRank(nodes []string) { g.sameRank = append(g.sameRank, nodes) }
[ "func", "(", "g", "*", "Graph", ")", "SameRank", "(", "nodes", "[", "]", "string", ")", "{", "g", ".", "sameRank", "=", "append", "(", "g", ".", "sameRank", ",", "nodes", ")", "\n", "}" ]
// SameRank enforces alignment of the given nodes
[ "SameRank", "enforces", "alignment", "of", "the", "given", "nodes" ]
6d252d5ff882ba9963502860f30ab3673c6c7322
https://github.com/tmc/dot/blob/6d252d5ff882ba9963502860f30ab3673c6c7322/dot.go#L288-L290
153,303
ONSdigital/go-ns
s3/url.go
NewURL
func NewURL(rawURL string) (*URL, error) { url, err := url.Parse(rawURL) if err != nil { return nil, err } return &URL{ URL: url, }, nil }
go
func NewURL(rawURL string) (*URL, error) { url, err := url.Parse(rawURL) if err != nil { return nil, err } return &URL{ URL: url, }, nil }
[ "func", "NewURL", "(", "rawURL", "string", ")", "(", "*", "URL", ",", "error", ")", "{", "url", ",", "err", ":=", "url", ".", "Parse", "(", "rawURL", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "ret...
// NewURL create a new instance of URL.
[ "NewURL", "create", "a", "new", "instance", "of", "URL", "." ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/s3/url.go#L9-L19
153,304
ONSdigital/go-ns
handlers/requestID/handler.go
Handler
func Handler(size int) func(http.Handler) http.Handler { return func(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { requestID := req.Header.Get(common.RequestHeaderKey) if len(requestID) == 0 { requestID = common.NewRequestID(size) common.AddRequestIdHeader(req, requestID) } h.ServeHTTP(w, req.WithContext(common.WithRequestId(req.Context(), requestID))) }) } }
go
func Handler(size int) func(http.Handler) http.Handler { return func(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { requestID := req.Header.Get(common.RequestHeaderKey) if len(requestID) == 0 { requestID = common.NewRequestID(size) common.AddRequestIdHeader(req, requestID) } h.ServeHTTP(w, req.WithContext(common.WithRequestId(req.Context(), requestID))) }) } }
[ "func", "Handler", "(", "size", "int", ")", "func", "(", "http", ".", "Handler", ")", "http", ".", "Handler", "{", "return", "func", "(", "h", "http", ".", "Handler", ")", "http", ".", "Handler", "{", "return", "http", ".", "HandlerFunc", "(", "func"...
// Handler is a wrapper which adds an X-Request-Id header if one does not yet exist
[ "Handler", "is", "a", "wrapper", "which", "adds", "an", "X", "-", "Request", "-", "Id", "header", "if", "one", "does", "not", "yet", "exist" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/handlers/requestID/handler.go#L10-L24
153,305
ONSdigital/go-ns
rchttp/client.go
ClientWithTimeout
func ClientWithTimeout(c common.RCHTTPClienter, timeout time.Duration) common.RCHTTPClienter { if c == nil { c = NewClient() } c.SetTimeout(timeout) return c }
go
func ClientWithTimeout(c common.RCHTTPClienter, timeout time.Duration) common.RCHTTPClienter { if c == nil { c = NewClient() } c.SetTimeout(timeout) return c }
[ "func", "ClientWithTimeout", "(", "c", "common", ".", "RCHTTPClienter", ",", "timeout", "time", ".", "Duration", ")", "common", ".", "RCHTTPClienter", "{", "if", "c", "==", "nil", "{", "c", "=", "NewClient", "(", ")", "\n", "}", "\n", "c", ".", "SetTim...
// ClientWithTimeout facilitates creating a client and setting request timeout
[ "ClientWithTimeout", "facilitates", "creating", "a", "client", "and", "setting", "request", "timeout" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/rchttp/client.go#L57-L63
153,306
ONSdigital/go-ns
rchttp/client.go
ClientWithServiceToken
func ClientWithServiceToken(c common.RCHTTPClienter, authToken string) common.RCHTTPClienter { if c == nil { c = NewClient() } c.SetAuthToken(authToken) return c }
go
func ClientWithServiceToken(c common.RCHTTPClienter, authToken string) common.RCHTTPClienter { if c == nil { c = NewClient() } c.SetAuthToken(authToken) return c }
[ "func", "ClientWithServiceToken", "(", "c", "common", ".", "RCHTTPClienter", ",", "authToken", "string", ")", "common", ".", "RCHTTPClienter", "{", "if", "c", "==", "nil", "{", "c", "=", "NewClient", "(", ")", "\n", "}", "\n", "c", ".", "SetAuthToken", "...
// ClientWithServiceToken facilitates creating a client and setting service auth
[ "ClientWithServiceToken", "facilitates", "creating", "a", "client", "and", "setting", "service", "auth" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/rchttp/client.go#L70-L76
153,307
ONSdigital/go-ns
rchttp/client.go
ClientWithDownloadServiceToken
func ClientWithDownloadServiceToken(c common.RCHTTPClienter, token string) common.RCHTTPClienter { if c == nil { c = NewClient() } c.SetDownloadServiceToken(token) return c }
go
func ClientWithDownloadServiceToken(c common.RCHTTPClienter, token string) common.RCHTTPClienter { if c == nil { c = NewClient() } c.SetDownloadServiceToken(token) return c }
[ "func", "ClientWithDownloadServiceToken", "(", "c", "common", ".", "RCHTTPClienter", ",", "token", "string", ")", "common", ".", "RCHTTPClienter", "{", "if", "c", "==", "nil", "{", "c", "=", "NewClient", "(", ")", "\n", "}", "\n", "c", ".", "SetDownloadSer...
// ClientWithDownloadServiceToken facilitates creating a client and setting service auth
[ "ClientWithDownloadServiceToken", "facilitates", "creating", "a", "client", "and", "setting", "service", "auth" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/rchttp/client.go#L82-L88
153,308
ONSdigital/go-ns
rchttp/client.go
Do
func (c *Client) Do(ctx context.Context, req *http.Request) (*http.Response, error) { if len(c.AuthToken) > 0 { // only add this header if not already set (e.g. for authClient) if len(req.Header.Get(common.AuthHeaderKey)) == 0 { common.AddServiceTokenHeader(req, c.AuthToken) } } if len(c.DownloadServiceToken) > 0 { // only add this header if not already set if len(req.Header.Get(common.DownloadServiceHeaderKey)) == 0 { common.AddDownloadServiceTokenHeader(req, c.DownloadServiceToken) } } if common.IsUserPresent(ctx) { // only add this header if not already set if len(req.Header.Get(common.UserHeaderKey)) == 0 { common.AddUserHeader(req, common.User(ctx)) } } if common.IsFlorenceIdentityPresent(ctx) { common.SetFlorenceHeader(ctx, req) } // get any existing correlation-id (might be "id1,id2"), append a new one, add to headers upstreamCorrelationIds := common.GetRequestId(ctx) addedIdLen := 20 if upstreamCorrelationIds != "" { // get length of (first of) IDs (e.g. "id1" is 3), new ID will be half that size addedIdLen = len(upstreamCorrelationIds) / 2 if commaPosition := strings.Index(upstreamCorrelationIds, ","); commaPosition > 1 { addedIdLen = commaPosition / 2 } upstreamCorrelationIds += "," } common.AddRequestIdHeader(req, upstreamCorrelationIds+common.NewRequestID(addedIdLen)) doer := func(args ...interface{}) (*http.Response, error) { req := args[2].(*http.Request) if req.ContentLength > 0 { var err error req.Body, err = req.GetBody() if err != nil { return nil, err } } return ctxhttp.Do(args[0].(context.Context), args[1].(*http.Client), req) } resp, err := doer(ctx, c.HTTPClient, req) if err != nil { if c.ExponentialBackoff { return c.backoff(doer, err, ctx, c.HTTPClient, req) } return nil, err } if c.ExponentialBackoff { if resp.StatusCode >= http.StatusInternalServerError { return c.backoff(doer, err, ctx, c.HTTPClient, req, errors.New("Bad server status")) } if resp.StatusCode == http.StatusConflict { return c.backoff(doer, err, ctx, c.HTTPClient, req, errors.New("Conflict - request could not be completed due to a conflict with the current state of the target resource")) } } return resp, err }
go
func (c *Client) Do(ctx context.Context, req *http.Request) (*http.Response, error) { if len(c.AuthToken) > 0 { // only add this header if not already set (e.g. for authClient) if len(req.Header.Get(common.AuthHeaderKey)) == 0 { common.AddServiceTokenHeader(req, c.AuthToken) } } if len(c.DownloadServiceToken) > 0 { // only add this header if not already set if len(req.Header.Get(common.DownloadServiceHeaderKey)) == 0 { common.AddDownloadServiceTokenHeader(req, c.DownloadServiceToken) } } if common.IsUserPresent(ctx) { // only add this header if not already set if len(req.Header.Get(common.UserHeaderKey)) == 0 { common.AddUserHeader(req, common.User(ctx)) } } if common.IsFlorenceIdentityPresent(ctx) { common.SetFlorenceHeader(ctx, req) } // get any existing correlation-id (might be "id1,id2"), append a new one, add to headers upstreamCorrelationIds := common.GetRequestId(ctx) addedIdLen := 20 if upstreamCorrelationIds != "" { // get length of (first of) IDs (e.g. "id1" is 3), new ID will be half that size addedIdLen = len(upstreamCorrelationIds) / 2 if commaPosition := strings.Index(upstreamCorrelationIds, ","); commaPosition > 1 { addedIdLen = commaPosition / 2 } upstreamCorrelationIds += "," } common.AddRequestIdHeader(req, upstreamCorrelationIds+common.NewRequestID(addedIdLen)) doer := func(args ...interface{}) (*http.Response, error) { req := args[2].(*http.Request) if req.ContentLength > 0 { var err error req.Body, err = req.GetBody() if err != nil { return nil, err } } return ctxhttp.Do(args[0].(context.Context), args[1].(*http.Client), req) } resp, err := doer(ctx, c.HTTPClient, req) if err != nil { if c.ExponentialBackoff { return c.backoff(doer, err, ctx, c.HTTPClient, req) } return nil, err } if c.ExponentialBackoff { if resp.StatusCode >= http.StatusInternalServerError { return c.backoff(doer, err, ctx, c.HTTPClient, req, errors.New("Bad server status")) } if resp.StatusCode == http.StatusConflict { return c.backoff(doer, err, ctx, c.HTTPClient, req, errors.New("Conflict - request could not be completed due to a conflict with the current state of the target resource")) } } return resp, err }
[ "func", "(", "c", "*", "Client", ")", "Do", "(", "ctx", "context", ".", "Context", ",", "req", "*", "http", ".", "Request", ")", "(", "*", "http", ".", "Response", ",", "error", ")", "{", "if", "len", "(", "c", ".", "AuthToken", ")", ">", "0", ...
// Do calls ctxhttp.Do with the addition of exponential backoff
[ "Do", "calls", "ctxhttp", ".", "Do", "with", "the", "addition", "of", "exponential", "backoff" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/rchttp/client.go#L101-L169
153,309
ONSdigital/go-ns
rchttp/client.go
Get
func (c *Client) Get(ctx context.Context, url string) (*http.Response, error) { req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, err } return c.Do(ctx, req) }
go
func (c *Client) Get(ctx context.Context, url string) (*http.Response, error) { req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, err } return c.Do(ctx, req) }
[ "func", "(", "c", "*", "Client", ")", "Get", "(", "ctx", "context", ".", "Context", ",", "url", "string", ")", "(", "*", "http", ".", "Response", ",", "error", ")", "{", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", ...
// Get calls Do with a GET
[ "Get", "calls", "Do", "with", "a", "GET" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/rchttp/client.go#L172-L179
153,310
ONSdigital/go-ns
rchttp/client.go
Post
func (c *Client) Post(ctx context.Context, url string, contentType string, body io.Reader) (*http.Response, error) { req, err := http.NewRequest("POST", url, body) if err != nil { return nil, err } req.Header.Set("Content-Type", contentType) return c.Do(ctx, req) }
go
func (c *Client) Post(ctx context.Context, url string, contentType string, body io.Reader) (*http.Response, error) { req, err := http.NewRequest("POST", url, body) if err != nil { return nil, err } req.Header.Set("Content-Type", contentType) return c.Do(ctx, req) }
[ "func", "(", "c", "*", "Client", ")", "Post", "(", "ctx", "context", ".", "Context", ",", "url", "string", ",", "contentType", "string", ",", "body", "io", ".", "Reader", ")", "(", "*", "http", ".", "Response", ",", "error", ")", "{", "req", ",", ...
// Post calls Do with a POST and the appropriate content-type and body
[ "Post", "calls", "Do", "with", "a", "POST", "and", "the", "appropriate", "content", "-", "type", "and", "body" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/rchttp/client.go#L192-L200
153,311
ONSdigital/go-ns
rchttp/client.go
PostForm
func (c *Client) PostForm(ctx context.Context, uri string, data url.Values) (*http.Response, error) { return c.Post(ctx, uri, "application/x-www-form-urlencoded", strings.NewReader(data.Encode())) }
go
func (c *Client) PostForm(ctx context.Context, uri string, data url.Values) (*http.Response, error) { return c.Post(ctx, uri, "application/x-www-form-urlencoded", strings.NewReader(data.Encode())) }
[ "func", "(", "c", "*", "Client", ")", "PostForm", "(", "ctx", "context", ".", "Context", ",", "uri", "string", ",", "data", "url", ".", "Values", ")", "(", "*", "http", ".", "Response", ",", "error", ")", "{", "return", "c", ".", "Post", "(", "ct...
// PostForm calls Post with the appropriate form content-type
[ "PostForm", "calls", "Post", "with", "the", "appropriate", "form", "content", "-", "type" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/rchttp/client.go#L214-L216
153,312
ONSdigital/go-ns
audit/helper.go
GetParameters
func GetParameters(ctx context.Context, path string, vars map[string]string) common.Params { auditParams := common.Params{} callerIdentity := common.Caller(ctx) if callerIdentity != "" { auditParams["caller_identity"] = callerIdentity } pathSegments := strings.Split(path, "/") // Remove initial segment if empty if pathSegments[0] == "" { pathSegments = pathSegments[1:] } numberOfSegments := len(pathSegments) if pathSegments[0] == "hierarchies" { if numberOfSegments > 1 { auditParams["instance_id"] = pathSegments[1] if numberOfSegments > 2 { auditParams["dimension"] = pathSegments[2] if numberOfSegments > 3 { auditParams["code"] = pathSegments[3] } } } return auditParams } if pathSegments[0] == "search" { pathSegments = pathSegments[1:] } for key, value := range vars { if key == "id" { auditParams[pathIDs[pathSegments[0]]] = value } else { auditParams[key] = value } } return auditParams }
go
func GetParameters(ctx context.Context, path string, vars map[string]string) common.Params { auditParams := common.Params{} callerIdentity := common.Caller(ctx) if callerIdentity != "" { auditParams["caller_identity"] = callerIdentity } pathSegments := strings.Split(path, "/") // Remove initial segment if empty if pathSegments[0] == "" { pathSegments = pathSegments[1:] } numberOfSegments := len(pathSegments) if pathSegments[0] == "hierarchies" { if numberOfSegments > 1 { auditParams["instance_id"] = pathSegments[1] if numberOfSegments > 2 { auditParams["dimension"] = pathSegments[2] if numberOfSegments > 3 { auditParams["code"] = pathSegments[3] } } } return auditParams } if pathSegments[0] == "search" { pathSegments = pathSegments[1:] } for key, value := range vars { if key == "id" { auditParams[pathIDs[pathSegments[0]]] = value } else { auditParams[key] = value } } return auditParams }
[ "func", "GetParameters", "(", "ctx", "context", ".", "Context", ",", "path", "string", ",", "vars", "map", "[", "string", "]", "string", ")", "common", ".", "Params", "{", "auditParams", ":=", "common", ".", "Params", "{", "}", "\n\n", "callerIdentity", ...
// GetParameters populates audit parameters with path variable values
[ "GetParameters", "populates", "audit", "parameters", "with", "path", "variable", "values" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/audit/helper.go#L19-L63
153,313
peter-edge/pkg-go
http/pkghttp.go
GetHandlerEnv
func GetHandlerEnv() (HandlerEnv, error) { handlerEnv := HandlerEnv{} if err := env.Populate(&handlerEnv); err != nil { return HandlerEnv{}, err } return handlerEnv, nil }
go
func GetHandlerEnv() (HandlerEnv, error) { handlerEnv := HandlerEnv{} if err := env.Populate(&handlerEnv); err != nil { return HandlerEnv{}, err } return handlerEnv, nil }
[ "func", "GetHandlerEnv", "(", ")", "(", "HandlerEnv", ",", "error", ")", "{", "handlerEnv", ":=", "HandlerEnv", "{", "}", "\n", "if", "err", ":=", "env", ".", "Populate", "(", "&", "handlerEnv", ")", ";", "err", "!=", "nil", "{", "return", "HandlerEnv"...
// GetHandlerEnv gets the HandlerEnv from the environment.
[ "GetHandlerEnv", "gets", "the", "HandlerEnv", "from", "the", "environment", "." ]
318cf31141c87eaa4348bd8a54886ba3aaf2a427
https://github.com/peter-edge/pkg-go/blob/318cf31141c87eaa4348bd8a54886ba3aaf2a427/http/pkghttp.go#L44-L50
153,314
peter-edge/pkg-go
http/pkghttp.go
NewWrapperHandler
func NewWrapperHandler(delegate http.Handler, handlerEnv HandlerEnv) http.Handler { return newWrapperHandler(delegate, handlerEnv) }
go
func NewWrapperHandler(delegate http.Handler, handlerEnv HandlerEnv) http.Handler { return newWrapperHandler(delegate, handlerEnv) }
[ "func", "NewWrapperHandler", "(", "delegate", "http", ".", "Handler", ",", "handlerEnv", "HandlerEnv", ")", "http", ".", "Handler", "{", "return", "newWrapperHandler", "(", "delegate", ",", "handlerEnv", ")", "\n", "}" ]
// NewWrapperHandler returns a new wrapper handler.
[ "NewWrapperHandler", "returns", "a", "new", "wrapper", "handler", "." ]
318cf31141c87eaa4348bd8a54886ba3aaf2a427
https://github.com/peter-edge/pkg-go/blob/318cf31141c87eaa4348bd8a54886ba3aaf2a427/http/pkghttp.go#L53-L55
153,315
peter-edge/pkg-go
http/pkghttp.go
ListenAndServe
func ListenAndServe(handler http.Handler, handlerEnv HandlerEnv) error { if handler == nil { return handleErrorBeforeStart(ErrRequireHandler) } if handlerEnv.Port == 0 { handlerEnv.Port = 8080 } if handlerEnv.HealthCheckPath == "" { handlerEnv.HealthCheckPath = "/health" } if handlerEnv.ShutdownTimeoutSec == 0 { handlerEnv.ShutdownTimeoutSec = 10 } server := &graceful.Server{ Timeout: time.Duration(handlerEnv.ShutdownTimeoutSec) * time.Second, Server: &http.Server{ Addr: fmt.Sprintf(":%d", handlerEnv.Port), Handler: NewWrapperHandler( handler, handlerEnv, ), }, } protolion.Info( &ServerStarting{ Port: uint32(handlerEnv.Port), }, ) start := time.Now() err := server.ListenAndServe() serverFinished := &ServerFinished{ Duration: prototime.DurationToProto(time.Since(start)), } if err != nil { serverFinished.Error = err.Error() protolion.Error(serverFinished) return err } protolion.Info(serverFinished) return nil }
go
func ListenAndServe(handler http.Handler, handlerEnv HandlerEnv) error { if handler == nil { return handleErrorBeforeStart(ErrRequireHandler) } if handlerEnv.Port == 0 { handlerEnv.Port = 8080 } if handlerEnv.HealthCheckPath == "" { handlerEnv.HealthCheckPath = "/health" } if handlerEnv.ShutdownTimeoutSec == 0 { handlerEnv.ShutdownTimeoutSec = 10 } server := &graceful.Server{ Timeout: time.Duration(handlerEnv.ShutdownTimeoutSec) * time.Second, Server: &http.Server{ Addr: fmt.Sprintf(":%d", handlerEnv.Port), Handler: NewWrapperHandler( handler, handlerEnv, ), }, } protolion.Info( &ServerStarting{ Port: uint32(handlerEnv.Port), }, ) start := time.Now() err := server.ListenAndServe() serverFinished := &ServerFinished{ Duration: prototime.DurationToProto(time.Since(start)), } if err != nil { serverFinished.Error = err.Error() protolion.Error(serverFinished) return err } protolion.Info(serverFinished) return nil }
[ "func", "ListenAndServe", "(", "handler", "http", ".", "Handler", ",", "handlerEnv", "HandlerEnv", ")", "error", "{", "if", "handler", "==", "nil", "{", "return", "handleErrorBeforeStart", "(", "ErrRequireHandler", ")", "\n", "}", "\n", "if", "handlerEnv", "."...
// ListenAndServe is the equivalent to http's method. // // Intercepts requests and responses, handles SIGINT and SIGTERM. // When this returns, any errors will have been logged. // If the server starts, this will block until the server stops. // // Uses a wrapper handler.
[ "ListenAndServe", "is", "the", "equivalent", "to", "http", "s", "method", ".", "Intercepts", "requests", "and", "responses", "handles", "SIGINT", "and", "SIGTERM", ".", "When", "this", "returns", "any", "errors", "will", "have", "been", "logged", ".", "If", ...
318cf31141c87eaa4348bd8a54886ba3aaf2a427
https://github.com/peter-edge/pkg-go/blob/318cf31141c87eaa4348bd8a54886ba3aaf2a427/http/pkghttp.go#L64-L104
153,316
peter-edge/pkg-go
http/pkghttp.go
GetAndListenAndServe
func GetAndListenAndServe(handler http.Handler) error { handlerEnv, err := GetHandlerEnv() if err != nil { return err } return ListenAndServe(handler, handlerEnv) }
go
func GetAndListenAndServe(handler http.Handler) error { handlerEnv, err := GetHandlerEnv() if err != nil { return err } return ListenAndServe(handler, handlerEnv) }
[ "func", "GetAndListenAndServe", "(", "handler", "http", ".", "Handler", ")", "error", "{", "handlerEnv", ",", "err", ":=", "GetHandlerEnv", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "ListenAndServe", "(", ...
// GetAndListenAndServe is GetHandlerEnv then ListenAndServe.
[ "GetAndListenAndServe", "is", "GetHandlerEnv", "then", "ListenAndServe", "." ]
318cf31141c87eaa4348bd8a54886ba3aaf2a427
https://github.com/peter-edge/pkg-go/blob/318cf31141c87eaa4348bd8a54886ba3aaf2a427/http/pkghttp.go#L107-L113
153,317
peter-edge/pkg-go
http/pkghttp.go
Error
func Error(responseWriter http.ResponseWriter, statusCode int, err error) bool { if err != nil { http.Error(responseWriter, err.Error(), statusCode) return true } return false }
go
func Error(responseWriter http.ResponseWriter, statusCode int, err error) bool { if err != nil { http.Error(responseWriter, err.Error(), statusCode) return true } return false }
[ "func", "Error", "(", "responseWriter", "http", ".", "ResponseWriter", ",", "statusCode", "int", ",", "err", "error", ")", "bool", "{", "if", "err", "!=", "nil", "{", "http", ".", "Error", "(", "responseWriter", ",", "err", ".", "Error", "(", ")", ",",...
// Error does http.Error on the error if not nil, and returns true if not nil.
[ "Error", "does", "http", ".", "Error", "on", "the", "error", "if", "not", "nil", "and", "returns", "true", "if", "not", "nil", "." ]
318cf31141c87eaa4348bd8a54886ba3aaf2a427
https://github.com/peter-edge/pkg-go/blob/318cf31141c87eaa4348bd8a54886ba3aaf2a427/http/pkghttp.go#L127-L133
153,318
peter-edge/pkg-go
http/pkghttp.go
ErrorInternal
func ErrorInternal(responseWriter http.ResponseWriter, err error) bool { return Error(responseWriter, http.StatusInternalServerError, err) }
go
func ErrorInternal(responseWriter http.ResponseWriter, err error) bool { return Error(responseWriter, http.StatusInternalServerError, err) }
[ "func", "ErrorInternal", "(", "responseWriter", "http", ".", "ResponseWriter", ",", "err", "error", ")", "bool", "{", "return", "Error", "(", "responseWriter", ",", "http", ".", "StatusInternalServerError", ",", "err", ")", "\n", "}" ]
// ErrorInternal does Error 500.
[ "ErrorInternal", "does", "Error", "500", "." ]
318cf31141c87eaa4348bd8a54886ba3aaf2a427
https://github.com/peter-edge/pkg-go/blob/318cf31141c87eaa4348bd8a54886ba3aaf2a427/http/pkghttp.go#L136-L138
153,319
peter-edge/pkg-go
http/pkghttp.go
FileHandlerFunc
func FileHandlerFunc(filePath string) func(http.ResponseWriter, *http.Request) { return func(responseWriter http.ResponseWriter, request *http.Request) { http.ServeFile(responseWriter, request, filePath) } }
go
func FileHandlerFunc(filePath string) func(http.ResponseWriter, *http.Request) { return func(responseWriter http.ResponseWriter, request *http.Request) { http.ServeFile(responseWriter, request, filePath) } }
[ "func", "FileHandlerFunc", "(", "filePath", "string", ")", "func", "(", "http", ".", "ResponseWriter", ",", "*", "http", ".", "Request", ")", "{", "return", "func", "(", "responseWriter", "http", ".", "ResponseWriter", ",", "request", "*", "http", ".", "Re...
// FileHandlerFunc returns a handler function for a file path.
[ "FileHandlerFunc", "returns", "a", "handler", "function", "for", "a", "file", "path", "." ]
318cf31141c87eaa4348bd8a54886ba3aaf2a427
https://github.com/peter-edge/pkg-go/blob/318cf31141c87eaa4348bd8a54886ba3aaf2a427/http/pkghttp.go#L141-L145
153,320
peter-edge/pkg-go
http/pkghttp.go
QueryGet
func QueryGet(request *http.Request, key string) string { return request.URL.Query().Get(key) }
go
func QueryGet(request *http.Request, key string) string { return request.URL.Query().Get(key) }
[ "func", "QueryGet", "(", "request", "*", "http", ".", "Request", ",", "key", "string", ")", "string", "{", "return", "request", ".", "URL", ".", "Query", "(", ")", ".", "Get", "(", "key", ")", "\n", "}" ]
// QueryGet gets the string by key from the request query, if it exists. // Otherwise, returns "".
[ "QueryGet", "gets", "the", "string", "by", "key", "from", "the", "request", "query", "if", "it", "exists", ".", "Otherwise", "returns", "." ]
318cf31141c87eaa4348bd8a54886ba3aaf2a427
https://github.com/peter-edge/pkg-go/blob/318cf31141c87eaa4348bd8a54886ba3aaf2a427/http/pkghttp.go#L149-L151
153,321
peter-edge/pkg-go
http/pkghttp.go
QueryGetUint32
func QueryGetUint32(request *http.Request, key string) (uint32, error) { return ParseUint32(QueryGet(request, key)) }
go
func QueryGetUint32(request *http.Request, key string) (uint32, error) { return ParseUint32(QueryGet(request, key)) }
[ "func", "QueryGetUint32", "(", "request", "*", "http", ".", "Request", ",", "key", "string", ")", "(", "uint32", ",", "error", ")", "{", "return", "ParseUint32", "(", "QueryGet", "(", "request", ",", "key", ")", ")", "\n", "}" ]
// QueryGetUint32 gets the uint32 by key from the request query, if it exists. // Otherwise, returns 0. // error returned if there is a parsing error.
[ "QueryGetUint32", "gets", "the", "uint32", "by", "key", "from", "the", "request", "query", "if", "it", "exists", ".", "Otherwise", "returns", "0", ".", "error", "returned", "if", "there", "is", "a", "parsing", "error", "." ]
318cf31141c87eaa4348bd8a54886ba3aaf2a427
https://github.com/peter-edge/pkg-go/blob/318cf31141c87eaa4348bd8a54886ba3aaf2a427/http/pkghttp.go#L156-L158
153,322
peter-edge/pkg-go
http/pkghttp.go
ParseUint32
func ParseUint32(valueString string) (uint32, error) { if valueString == "" { return 0, nil } valueString = strings.Replace(valueString, ",", "", -1) value, err := strconv.ParseUint(valueString, 10, 32) if err != nil { return 0, err } return uint32(value), nil }
go
func ParseUint32(valueString string) (uint32, error) { if valueString == "" { return 0, nil } valueString = strings.Replace(valueString, ",", "", -1) value, err := strconv.ParseUint(valueString, 10, 32) if err != nil { return 0, err } return uint32(value), nil }
[ "func", "ParseUint32", "(", "valueString", "string", ")", "(", "uint32", ",", "error", ")", "{", "if", "valueString", "==", "\"", "\"", "{", "return", "0", ",", "nil", "\n", "}", "\n", "valueString", "=", "strings", ".", "Replace", "(", "valueString", ...
// ParseUint32 parses the uint32 from the valueString, if it exists. // Otherwise, returns 0. // error returned if there is a parsing error.
[ "ParseUint32", "parses", "the", "uint32", "from", "the", "valueString", "if", "it", "exists", ".", "Otherwise", "returns", "0", ".", "error", "returned", "if", "there", "is", "a", "parsing", "error", "." ]
318cf31141c87eaa4348bd8a54886ba3aaf2a427
https://github.com/peter-edge/pkg-go/blob/318cf31141c87eaa4348bd8a54886ba3aaf2a427/http/pkghttp.go#L163-L173
153,323
peter-edge/pkg-go
http/pkghttp.go
QueryGetFloat64
func QueryGetFloat64(request *http.Request, key string) (float64, error) { return ParseFloat64(QueryGet(request, key)) }
go
func QueryGetFloat64(request *http.Request, key string) (float64, error) { return ParseFloat64(QueryGet(request, key)) }
[ "func", "QueryGetFloat64", "(", "request", "*", "http", ".", "Request", ",", "key", "string", ")", "(", "float64", ",", "error", ")", "{", "return", "ParseFloat64", "(", "QueryGet", "(", "request", ",", "key", ")", ")", "\n", "}" ]
// QueryGetFloat64 gets the float64 by key from the request query, if it exists. // Otherwise, returns 0.0. // error returned if there is a parsing error.
[ "QueryGetFloat64", "gets", "the", "float64", "by", "key", "from", "the", "request", "query", "if", "it", "exists", ".", "Otherwise", "returns", "0", ".", "0", ".", "error", "returned", "if", "there", "is", "a", "parsing", "error", "." ]
318cf31141c87eaa4348bd8a54886ba3aaf2a427
https://github.com/peter-edge/pkg-go/blob/318cf31141c87eaa4348bd8a54886ba3aaf2a427/http/pkghttp.go#L178-L180
153,324
peter-edge/pkg-go
http/pkghttp.go
ParseFloat64
func ParseFloat64(valueString string) (float64, error) { if valueString == "" { return 0.0, nil } valueString = strings.Replace(valueString, ",", "", -1) return strconv.ParseFloat(valueString, 64) }
go
func ParseFloat64(valueString string) (float64, error) { if valueString == "" { return 0.0, nil } valueString = strings.Replace(valueString, ",", "", -1) return strconv.ParseFloat(valueString, 64) }
[ "func", "ParseFloat64", "(", "valueString", "string", ")", "(", "float64", ",", "error", ")", "{", "if", "valueString", "==", "\"", "\"", "{", "return", "0.0", ",", "nil", "\n", "}", "\n", "valueString", "=", "strings", ".", "Replace", "(", "valueString"...
// ParseFloat64 parses the float64 from the valueString, if it exists. // Otherwise, returns 0.0. // error returned if there is a parsing error.
[ "ParseFloat64", "parses", "the", "float64", "from", "the", "valueString", "if", "it", "exists", ".", "Otherwise", "returns", "0", ".", "0", ".", "error", "returned", "if", "there", "is", "a", "parsing", "error", "." ]
318cf31141c87eaa4348bd8a54886ba3aaf2a427
https://github.com/peter-edge/pkg-go/blob/318cf31141c87eaa4348bd8a54886ba3aaf2a427/http/pkghttp.go#L185-L191
153,325
peter-edge/pkg-go
http/pkghttp.go
QueryGetDate
func QueryGetDate(request *http.Request, key string, timeFormat string) (*google_type.Date, error) { return ParseDate(QueryGet(request, key), timeFormat) }
go
func QueryGetDate(request *http.Request, key string, timeFormat string) (*google_type.Date, error) { return ParseDate(QueryGet(request, key), timeFormat) }
[ "func", "QueryGetDate", "(", "request", "*", "http", ".", "Request", ",", "key", "string", ",", "timeFormat", "string", ")", "(", "*", "google_type", ".", "Date", ",", "error", ")", "{", "return", "ParseDate", "(", "QueryGet", "(", "request", ",", "key",...
// QueryGetDate gets the Date by key from the request query, if it exists. // Otherwise, returns nil. // The time format given will be used to parse the request value into a time.Time object.
[ "QueryGetDate", "gets", "the", "Date", "by", "key", "from", "the", "request", "query", "if", "it", "exists", ".", "Otherwise", "returns", "nil", ".", "The", "time", "format", "given", "will", "be", "used", "to", "parse", "the", "request", "value", "into", ...
318cf31141c87eaa4348bd8a54886ba3aaf2a427
https://github.com/peter-edge/pkg-go/blob/318cf31141c87eaa4348bd8a54886ba3aaf2a427/http/pkghttp.go#L219-L221
153,326
peter-edge/pkg-go
http/pkghttp.go
ParseDate
func ParseDate(valueString string, timeFormat string) (*google_type.Date, error) { if valueString == "" { return nil, nil } t, err := time.Parse(timeFormat, valueString) if err != nil { return nil, err } return google_type.TimeToDate(t), nil }
go
func ParseDate(valueString string, timeFormat string) (*google_type.Date, error) { if valueString == "" { return nil, nil } t, err := time.Parse(timeFormat, valueString) if err != nil { return nil, err } return google_type.TimeToDate(t), nil }
[ "func", "ParseDate", "(", "valueString", "string", ",", "timeFormat", "string", ")", "(", "*", "google_type", ".", "Date", ",", "error", ")", "{", "if", "valueString", "==", "\"", "\"", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "t", ",", "er...
// ParseDate parses the Date from the valueString, if it exists. // Otherwise, returns nil. // The time format given will be used to parse the request value into a time.Time object.
[ "ParseDate", "parses", "the", "Date", "from", "the", "valueString", "if", "it", "exists", ".", "Otherwise", "returns", "nil", ".", "The", "time", "format", "given", "will", "be", "used", "to", "parse", "the", "request", "value", "into", "a", "time", ".", ...
318cf31141c87eaa4348bd8a54886ba3aaf2a427
https://github.com/peter-edge/pkg-go/blob/318cf31141c87eaa4348bd8a54886ba3aaf2a427/http/pkghttp.go#L226-L235
153,327
ONSdigital/go-ns
clients/hierarchy/hierarchy.go
GetRoot
func (c *Client) GetRoot(instanceID, name string) (m Model, err error) { path := fmt.Sprintf("/hierarchies/%s/%s", instanceID, name) clientlog.Do(context.Background(), "retrieving hierarchy", service, path, log.Data{ "method": "GET", "instance_id": instanceID, "dimension": name, }) return c.getHierarchy(path) }
go
func (c *Client) GetRoot(instanceID, name string) (m Model, err error) { path := fmt.Sprintf("/hierarchies/%s/%s", instanceID, name) clientlog.Do(context.Background(), "retrieving hierarchy", service, path, log.Data{ "method": "GET", "instance_id": instanceID, "dimension": name, }) return c.getHierarchy(path) }
[ "func", "(", "c", "*", "Client", ")", "GetRoot", "(", "instanceID", ",", "name", "string", ")", "(", "m", "Model", ",", "err", "error", ")", "{", "path", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "instanceID", ",", "name", ")", "\n\n", "...
// GetRoot returns the root hierarchy response from the hierarchy API
[ "GetRoot", "returns", "the", "root", "hierarchy", "response", "from", "the", "hierarchy", "API" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/clients/hierarchy/hierarchy.go#L70-L80
153,328
peter-edge/pkg-go
map/pkgmap.go
GetString
func (s StringStringMap) GetString(key string) (string, error) { value, ok := s[key] if !ok { return "", nil } return value, nil }
go
func (s StringStringMap) GetString(key string) (string, error) { value, ok := s[key] if !ok { return "", nil } return value, nil }
[ "func", "(", "s", "StringStringMap", ")", "GetString", "(", "key", "string", ")", "(", "string", ",", "error", ")", "{", "value", ",", "ok", ":=", "s", "[", "key", "]", "\n", "if", "!", "ok", "{", "return", "\"", "\"", ",", "nil", "\n", "}", "\...
// GetString gets the string if it is present, or "" otherwise.
[ "GetString", "gets", "the", "string", "if", "it", "is", "present", "or", "otherwise", "." ]
318cf31141c87eaa4348bd8a54886ba3aaf2a427
https://github.com/peter-edge/pkg-go/blob/318cf31141c87eaa4348bd8a54886ba3aaf2a427/map/pkgmap.go#L12-L18
153,329
peter-edge/pkg-go
map/pkgmap.go
GetRequiredString
func (s StringStringMap) GetRequiredString(key string) (string, error) { value, ok := s[key] if !ok { return "", newRequiredError(key) } return value, nil }
go
func (s StringStringMap) GetRequiredString(key string) (string, error) { value, ok := s[key] if !ok { return "", newRequiredError(key) } return value, nil }
[ "func", "(", "s", "StringStringMap", ")", "GetRequiredString", "(", "key", "string", ")", "(", "string", ",", "error", ")", "{", "value", ",", "ok", ":=", "s", "[", "key", "]", "\n", "if", "!", "ok", "{", "return", "\"", "\"", ",", "newRequiredError"...
// GetRequiredString gets the string if it is present, or returns error otherwise.
[ "GetRequiredString", "gets", "the", "string", "if", "it", "is", "present", "or", "returns", "error", "otherwise", "." ]
318cf31141c87eaa4348bd8a54886ba3aaf2a427
https://github.com/peter-edge/pkg-go/blob/318cf31141c87eaa4348bd8a54886ba3aaf2a427/map/pkgmap.go#L21-L27
153,330
peter-edge/pkg-go
map/pkgmap.go
GetInt32
func (s StringStringMap) GetInt32(key string) (int32, error) { return s.getInt32(key, false) }
go
func (s StringStringMap) GetInt32(key string) (int32, error) { return s.getInt32(key, false) }
[ "func", "(", "s", "StringStringMap", ")", "GetInt32", "(", "key", "string", ")", "(", "int32", ",", "error", ")", "{", "return", "s", ".", "getInt32", "(", "key", ",", "false", ")", "\n", "}" ]
// GetInt32 gets the int32 if it is present, or 0 otherwise.
[ "GetInt32", "gets", "the", "int32", "if", "it", "is", "present", "or", "0", "otherwise", "." ]
318cf31141c87eaa4348bd8a54886ba3aaf2a427
https://github.com/peter-edge/pkg-go/blob/318cf31141c87eaa4348bd8a54886ba3aaf2a427/map/pkgmap.go#L30-L32
153,331
peter-edge/pkg-go
map/pkgmap.go
GetRequiredInt32
func (s StringStringMap) GetRequiredInt32(key string) (int32, error) { return s.getInt32(key, true) }
go
func (s StringStringMap) GetRequiredInt32(key string) (int32, error) { return s.getInt32(key, true) }
[ "func", "(", "s", "StringStringMap", ")", "GetRequiredInt32", "(", "key", "string", ")", "(", "int32", ",", "error", ")", "{", "return", "s", ".", "getInt32", "(", "key", ",", "true", ")", "\n", "}" ]
// GetRequiredInt32 gets the int32 if it is present, or returns error otherwise.
[ "GetRequiredInt32", "gets", "the", "int32", "if", "it", "is", "present", "or", "returns", "error", "otherwise", "." ]
318cf31141c87eaa4348bd8a54886ba3aaf2a427
https://github.com/peter-edge/pkg-go/blob/318cf31141c87eaa4348bd8a54886ba3aaf2a427/map/pkgmap.go#L35-L37
153,332
peter-edge/pkg-go
map/pkgmap.go
GetInt64
func (s StringStringMap) GetInt64(key string) (int64, error) { return s.getInt64(key, false) }
go
func (s StringStringMap) GetInt64(key string) (int64, error) { return s.getInt64(key, false) }
[ "func", "(", "s", "StringStringMap", ")", "GetInt64", "(", "key", "string", ")", "(", "int64", ",", "error", ")", "{", "return", "s", ".", "getInt64", "(", "key", ",", "false", ")", "\n", "}" ]
// GetInt64 gets the int64 if it is present, or 0 otherwise.
[ "GetInt64", "gets", "the", "int64", "if", "it", "is", "present", "or", "0", "otherwise", "." ]
318cf31141c87eaa4348bd8a54886ba3aaf2a427
https://github.com/peter-edge/pkg-go/blob/318cf31141c87eaa4348bd8a54886ba3aaf2a427/map/pkgmap.go#L55-L57
153,333
peter-edge/pkg-go
map/pkgmap.go
GetRequiredInt64
func (s StringStringMap) GetRequiredInt64(key string) (int64, error) { return s.getInt64(key, true) }
go
func (s StringStringMap) GetRequiredInt64(key string) (int64, error) { return s.getInt64(key, true) }
[ "func", "(", "s", "StringStringMap", ")", "GetRequiredInt64", "(", "key", "string", ")", "(", "int64", ",", "error", ")", "{", "return", "s", ".", "getInt64", "(", "key", ",", "true", ")", "\n", "}" ]
// GetRequiredInt64 gets the int64 if it is present, or returns error otherwise.
[ "GetRequiredInt64", "gets", "the", "int64", "if", "it", "is", "present", "or", "returns", "error", "otherwise", "." ]
318cf31141c87eaa4348bd8a54886ba3aaf2a427
https://github.com/peter-edge/pkg-go/blob/318cf31141c87eaa4348bd8a54886ba3aaf2a427/map/pkgmap.go#L60-L62
153,334
peter-edge/pkg-go
map/pkgmap.go
GetUint32
func (s StringStringMap) GetUint32(key string) (uint32, error) { return s.getUint32(key, false) }
go
func (s StringStringMap) GetUint32(key string) (uint32, error) { return s.getUint32(key, false) }
[ "func", "(", "s", "StringStringMap", ")", "GetUint32", "(", "key", "string", ")", "(", "uint32", ",", "error", ")", "{", "return", "s", ".", "getUint32", "(", "key", ",", "false", ")", "\n", "}" ]
// GetUint32 gets the uint32 if it is present, or 0 otherwise.
[ "GetUint32", "gets", "the", "uint32", "if", "it", "is", "present", "or", "0", "otherwise", "." ]
318cf31141c87eaa4348bd8a54886ba3aaf2a427
https://github.com/peter-edge/pkg-go/blob/318cf31141c87eaa4348bd8a54886ba3aaf2a427/map/pkgmap.go#L80-L82
153,335
peter-edge/pkg-go
map/pkgmap.go
GetRequiredUint32
func (s StringStringMap) GetRequiredUint32(key string) (uint32, error) { return s.getUint32(key, true) }
go
func (s StringStringMap) GetRequiredUint32(key string) (uint32, error) { return s.getUint32(key, true) }
[ "func", "(", "s", "StringStringMap", ")", "GetRequiredUint32", "(", "key", "string", ")", "(", "uint32", ",", "error", ")", "{", "return", "s", ".", "getUint32", "(", "key", ",", "true", ")", "\n", "}" ]
// GetRequiredUint32 gets the uint32 if it is present, or returns error otherwise.
[ "GetRequiredUint32", "gets", "the", "uint32", "if", "it", "is", "present", "or", "returns", "error", "otherwise", "." ]
318cf31141c87eaa4348bd8a54886ba3aaf2a427
https://github.com/peter-edge/pkg-go/blob/318cf31141c87eaa4348bd8a54886ba3aaf2a427/map/pkgmap.go#L85-L87
153,336
peter-edge/pkg-go
map/pkgmap.go
GetUint64
func (s StringStringMap) GetUint64(key string) (uint64, error) { return s.getUint64(key, false) }
go
func (s StringStringMap) GetUint64(key string) (uint64, error) { return s.getUint64(key, false) }
[ "func", "(", "s", "StringStringMap", ")", "GetUint64", "(", "key", "string", ")", "(", "uint64", ",", "error", ")", "{", "return", "s", ".", "getUint64", "(", "key", ",", "false", ")", "\n", "}" ]
// GetUint64 gets the uint64 if it is present, or 0 otherwise.
[ "GetUint64", "gets", "the", "uint64", "if", "it", "is", "present", "or", "0", "otherwise", "." ]
318cf31141c87eaa4348bd8a54886ba3aaf2a427
https://github.com/peter-edge/pkg-go/blob/318cf31141c87eaa4348bd8a54886ba3aaf2a427/map/pkgmap.go#L105-L107
153,337
peter-edge/pkg-go
map/pkgmap.go
GetRequiredUint64
func (s StringStringMap) GetRequiredUint64(key string) (uint64, error) { return s.getUint64(key, true) }
go
func (s StringStringMap) GetRequiredUint64(key string) (uint64, error) { return s.getUint64(key, true) }
[ "func", "(", "s", "StringStringMap", ")", "GetRequiredUint64", "(", "key", "string", ")", "(", "uint64", ",", "error", ")", "{", "return", "s", ".", "getUint64", "(", "key", ",", "true", ")", "\n", "}" ]
// GetRequiredUint64 gets the uint64 if it is present, or returns error otherwise.
[ "GetRequiredUint64", "gets", "the", "uint64", "if", "it", "is", "present", "or", "returns", "error", "otherwise", "." ]
318cf31141c87eaa4348bd8a54886ba3aaf2a427
https://github.com/peter-edge/pkg-go/blob/318cf31141c87eaa4348bd8a54886ba3aaf2a427/map/pkgmap.go#L110-L112
153,338
peter-edge/pkg-go
map/pkgmap.go
GetBool
func (s StringStringMap) GetBool(key string) (bool, error) { value, ok := s[key] if !ok { return false, nil } return strconv.ParseBool(value) }
go
func (s StringStringMap) GetBool(key string) (bool, error) { value, ok := s[key] if !ok { return false, nil } return strconv.ParseBool(value) }
[ "func", "(", "s", "StringStringMap", ")", "GetBool", "(", "key", "string", ")", "(", "bool", ",", "error", ")", "{", "value", ",", "ok", ":=", "s", "[", "key", "]", "\n", "if", "!", "ok", "{", "return", "false", ",", "nil", "\n", "}", "\n", "re...
// GetBool gets the bool if it is present, or 0 otherwise.
[ "GetBool", "gets", "the", "bool", "if", "it", "is", "present", "or", "0", "otherwise", "." ]
318cf31141c87eaa4348bd8a54886ba3aaf2a427
https://github.com/peter-edge/pkg-go/blob/318cf31141c87eaa4348bd8a54886ba3aaf2a427/map/pkgmap.go#L130-L136
153,339
peter-edge/pkg-go
map/pkgmap.go
GetRequiredBool
func (s StringStringMap) GetRequiredBool(key string) (bool, error) { value, ok := s[key] if !ok { return false, newRequiredError(key) } return strconv.ParseBool(value) }
go
func (s StringStringMap) GetRequiredBool(key string) (bool, error) { value, ok := s[key] if !ok { return false, newRequiredError(key) } return strconv.ParseBool(value) }
[ "func", "(", "s", "StringStringMap", ")", "GetRequiredBool", "(", "key", "string", ")", "(", "bool", ",", "error", ")", "{", "value", ",", "ok", ":=", "s", "[", "key", "]", "\n", "if", "!", "ok", "{", "return", "false", ",", "newRequiredError", "(", ...
// GetRequiredBool gets the bool if it is present, or returns error otherwise.
[ "GetRequiredBool", "gets", "the", "bool", "if", "it", "is", "present", "or", "returns", "error", "otherwise", "." ]
318cf31141c87eaa4348bd8a54886ba3aaf2a427
https://github.com/peter-edge/pkg-go/blob/318cf31141c87eaa4348bd8a54886ba3aaf2a427/map/pkgmap.go#L139-L145
153,340
peter-edge/pkg-go
map/pkgmap.go
Copy
func (s StringStringMap) Copy() StringStringMap { m := make(StringStringMap) for key, value := range s { m[key] = value } return m }
go
func (s StringStringMap) Copy() StringStringMap { m := make(StringStringMap) for key, value := range s { m[key] = value } return m }
[ "func", "(", "s", "StringStringMap", ")", "Copy", "(", ")", "StringStringMap", "{", "m", ":=", "make", "(", "StringStringMap", ")", "\n", "for", "key", ",", "value", ":=", "range", "s", "{", "m", "[", "key", "]", "=", "value", "\n", "}", "\n", "ret...
// Copy gets a copy of the StringStringMap.
[ "Copy", "gets", "a", "copy", "of", "the", "StringStringMap", "." ]
318cf31141c87eaa4348bd8a54886ba3aaf2a427
https://github.com/peter-edge/pkg-go/blob/318cf31141c87eaa4348bd8a54886ba3aaf2a427/map/pkgmap.go#L148-L154
153,341
ONSdigital/go-ns
audit/audit.go
Record
func (a *NopAuditor) Record(ctx context.Context, attemptedAction string, actionResult string, params common.Params) error { return nil }
go
func (a *NopAuditor) Record(ctx context.Context, attemptedAction string, actionResult string, params common.Params) error { return nil }
[ "func", "(", "a", "*", "NopAuditor", ")", "Record", "(", "ctx", "context", ".", "Context", ",", "attemptedAction", "string", ",", "actionResult", "string", ",", "params", "common", ".", "Params", ")", "error", "{", "return", "nil", "\n", "}" ]
//Record is a no op implementation of Auditor.Record
[ "Record", "is", "a", "no", "op", "implementation", "of", "Auditor", ".", "Record" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/audit/audit.go#L66-L68
153,342
ONSdigital/go-ns
audit/audit.go
New
func New(producer OutboundProducer, namespace string) *Auditor { log.Debug("auditing enabled for service", log.Data{"service": namespace}) return &Auditor{ producer: producer, service: namespace, marshalToAvro: EventSchema.Marshal, } }
go
func New(producer OutboundProducer, namespace string) *Auditor { log.Debug("auditing enabled for service", log.Data{"service": namespace}) return &Auditor{ producer: producer, service: namespace, marshalToAvro: EventSchema.Marshal, } }
[ "func", "New", "(", "producer", "OutboundProducer", ",", "namespace", "string", ")", "*", "Auditor", "{", "log", ".", "Debug", "(", "\"", "\"", ",", "log", ".", "Data", "{", "\"", "\"", ":", "namespace", "}", ")", "\n", "return", "&", "Auditor", "{",...
//New creates a new Auditor with the namespace, producer and token provided.
[ "New", "creates", "a", "new", "Auditor", "with", "the", "namespace", "producer", "and", "token", "provided", "." ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/audit/audit.go#L71-L78
153,343
ONSdigital/go-ns
audit/audit.go
NewAuditError
func NewAuditError(cause string, attemptedAction string, actionResult string, params common.Params) Error { return Error{ Cause: cause, Action: attemptedAction, Result: actionResult, Params: params, } }
go
func NewAuditError(cause string, attemptedAction string, actionResult string, params common.Params) Error { return Error{ Cause: cause, Action: attemptedAction, Result: actionResult, Params: params, } }
[ "func", "NewAuditError", "(", "cause", "string", ",", "attemptedAction", "string", ",", "actionResult", "string", ",", "params", "common", ".", "Params", ")", "Error", "{", "return", "Error", "{", "Cause", ":", "cause", ",", "Action", ":", "attemptedAction", ...
//NewAuditError creates new audit.Error with default field values where necessary and orders the params alphabetically.
[ "NewAuditError", "creates", "new", "audit", ".", "Error", "with", "default", "field", "values", "where", "necessary", "and", "orders", "the", "params", "alphabetically", "." ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/audit/audit.go#L140-L147
153,344
ONSdigital/go-ns
audit/audit.go
Error
func (e Error) Error() string { return fmt.Sprintf("unable to audit event, attempted action: %s, action result: %s, cause: %s, params: %s", e.Action, e.Result, e.Cause, e.formatParams()) }
go
func (e Error) Error() string { return fmt.Sprintf("unable to audit event, attempted action: %s, action result: %s, cause: %s, params: %s", e.Action, e.Result, e.Cause, e.formatParams()) }
[ "func", "(", "e", "Error", ")", "Error", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "e", ".", "Action", ",", "e", ".", "Result", ",", "e", ".", "Cause", ",", "e", ".", "formatParams", "(", ")", ")", "\n", ...
// fulfill the error interface contract
[ "fulfill", "the", "error", "interface", "contract" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/audit/audit.go#L150-L153
153,345
ONSdigital/go-ns
audit/audit.go
ToLogData
func ToLogData(p common.Params) log.Data { if len(p) == 0 { return nil } data := log.Data{} for k, v := range p { data[k] = v } return data }
go
func ToLogData(p common.Params) log.Data { if len(p) == 0 { return nil } data := log.Data{} for k, v := range p { data[k] = v } return data }
[ "func", "ToLogData", "(", "p", "common", ".", "Params", ")", "log", ".", "Data", "{", "if", "len", "(", "p", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "data", ":=", "log", ".", "Data", "{", "}", "\n", "for", "k", ",", "v", ":="...
//ToLogData convert common.Params to log.Data
[ "ToLogData", "convert", "common", ".", "Params", "to", "log", ".", "Data" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/audit/audit.go#L192-L202
153,346
ONSdigital/go-ns
audit/mock.go
Record
func (mock *AuditorServiceMock) Record(ctx context.Context, action, result string, params common.Params) error { newParams := params.Copy() if mock.RecordFunc == nil { panic("MockAuditor.RecordFunc is nil but MockAuditor.Record was just called") } callInfo := struct { Ctx context.Context Action string Result string Params common.Params }{ Ctx: ctx, Action: action, Result: result, Params: newParams, } lockMockAuditorRecord.Lock() mock.calls.Record = append(mock.calls.Record, callInfo) lockMockAuditorRecord.Unlock() return mock.RecordFunc(ctx, action, result, newParams) }
go
func (mock *AuditorServiceMock) Record(ctx context.Context, action, result string, params common.Params) error { newParams := params.Copy() if mock.RecordFunc == nil { panic("MockAuditor.RecordFunc is nil but MockAuditor.Record was just called") } callInfo := struct { Ctx context.Context Action string Result string Params common.Params }{ Ctx: ctx, Action: action, Result: result, Params: newParams, } lockMockAuditorRecord.Lock() mock.calls.Record = append(mock.calls.Record, callInfo) lockMockAuditorRecord.Unlock() return mock.RecordFunc(ctx, action, result, newParams) }
[ "func", "(", "mock", "*", "AuditorServiceMock", ")", "Record", "(", "ctx", "context", ".", "Context", ",", "action", ",", "result", "string", ",", "params", "common", ".", "Params", ")", "error", "{", "newParams", ":=", "params", ".", "Copy", "(", ")", ...
// Record calls Copy on params and RecordFunc
[ "Record", "calls", "Copy", "on", "params", "and", "RecordFunc" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/audit/mock.go#L38-L61
153,347
ONSdigital/go-ns
audit/mock.go
RecordCalls
func (mock *AuditorServiceMock) RecordCalls() []struct { Ctx context.Context Action string Result string Params common.Params } { var calls []struct { Ctx context.Context Action string Result string Params common.Params } lockMockAuditorRecord.RLock() calls = mock.calls.Record lockMockAuditorRecord.RUnlock() return calls }
go
func (mock *AuditorServiceMock) RecordCalls() []struct { Ctx context.Context Action string Result string Params common.Params } { var calls []struct { Ctx context.Context Action string Result string Params common.Params } lockMockAuditorRecord.RLock() calls = mock.calls.Record lockMockAuditorRecord.RUnlock() return calls }
[ "func", "(", "mock", "*", "AuditorServiceMock", ")", "RecordCalls", "(", ")", "[", "]", "struct", "{", "Ctx", "context", ".", "Context", "\n", "Action", "string", "\n", "Result", "string", "\n", "Params", "common", ".", "Params", "\n", "}", "{", "var", ...
// RecordCalls retrieves all the calls that were made to Record
[ "RecordCalls", "retrieves", "all", "the", "calls", "that", "were", "made", "to", "Record" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/audit/mock.go#L64-L80
153,348
ONSdigital/go-ns
audit/mock.go
Output
func (mock *OutboundProducerMock) Output() chan []byte { if mock.OutputFunc == nil { panic("moq: OutboundProducerMock.OutputFunc is nil but OutboundProducer.Output was just called") } callInfo := struct { }{} lockOutboundProducerMockOutput.Lock() mock.calls.Output = append(mock.calls.Output, callInfo) lockOutboundProducerMockOutput.Unlock() return mock.OutputFunc() }
go
func (mock *OutboundProducerMock) Output() chan []byte { if mock.OutputFunc == nil { panic("moq: OutboundProducerMock.OutputFunc is nil but OutboundProducer.Output was just called") } callInfo := struct { }{} lockOutboundProducerMockOutput.Lock() mock.calls.Output = append(mock.calls.Output, callInfo) lockOutboundProducerMockOutput.Unlock() return mock.OutputFunc() }
[ "func", "(", "mock", "*", "OutboundProducerMock", ")", "Output", "(", ")", "chan", "[", "]", "byte", "{", "if", "mock", ".", "OutputFunc", "==", "nil", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "callInfo", ":=", "struct", "{", "}", "{", ...
// Output calls OutputFunc.
[ "Output", "calls", "OutputFunc", "." ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/audit/mock.go#L100-L110
153,349
ONSdigital/go-ns
kafka/consumer-group.go
StopListeningToConsumer
func (cg *ConsumerGroup) StopListeningToConsumer(ctx context.Context) (err error) { if ctx == nil { ctx = context.Background() } close(cg.closer) logData := log.Data{"topic": cg.topic, "group": cg.group} select { case <-cg.closed: log.Info("StopListeningToConsumer got confirmation of closed kafka consumer listener", logData) case <-ctx.Done(): err = ctx.Err() log.ErrorC("StopListeningToConsumer abandoned: context done", err, logData) } return }
go
func (cg *ConsumerGroup) StopListeningToConsumer(ctx context.Context) (err error) { if ctx == nil { ctx = context.Background() } close(cg.closer) logData := log.Data{"topic": cg.topic, "group": cg.group} select { case <-cg.closed: log.Info("StopListeningToConsumer got confirmation of closed kafka consumer listener", logData) case <-ctx.Done(): err = ctx.Err() log.ErrorC("StopListeningToConsumer abandoned: context done", err, logData) } return }
[ "func", "(", "cg", "*", "ConsumerGroup", ")", "StopListeningToConsumer", "(", "ctx", "context", ".", "Context", ")", "(", "err", "error", ")", "{", "if", "ctx", "==", "nil", "{", "ctx", "=", "context", ".", "Background", "(", ")", "\n", "}", "\n\n", ...
// StopListeningToConsumer stops any more messages being consumed off kafka topic
[ "StopListeningToConsumer", "stops", "any", "more", "messages", "being", "consumed", "off", "kafka", "topic" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/kafka/consumer-group.go#L49-L66
153,350
ONSdigital/go-ns
kafka/consumer-group.go
NewSyncConsumer
func NewSyncConsumer(brokers []string, topic string, group string, offset int64) (*ConsumerGroup, error) { return newConsumer(brokers, topic, group, offset, true) }
go
func NewSyncConsumer(brokers []string, topic string, group string, offset int64) (*ConsumerGroup, error) { return newConsumer(brokers, topic, group, offset, true) }
[ "func", "NewSyncConsumer", "(", "brokers", "[", "]", "string", ",", "topic", "string", ",", "group", "string", ",", "offset", "int64", ")", "(", "*", "ConsumerGroup", ",", "error", ")", "{", "return", "newConsumer", "(", "brokers", ",", "topic", ",", "gr...
// NewSyncConsumer returns a new synchronous consumer group using default configuration.
[ "NewSyncConsumer", "returns", "a", "new", "synchronous", "consumer", "group", "using", "default", "configuration", "." ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/kafka/consumer-group.go#L103-L105
153,351
ONSdigital/go-ns
kafka/consumer-group.go
NewConsumerGroup
func NewConsumerGroup(brokers []string, topic string, group string, offset int64) (*ConsumerGroup, error) { return newConsumer(brokers, topic, group, offset, false) }
go
func NewConsumerGroup(brokers []string, topic string, group string, offset int64) (*ConsumerGroup, error) { return newConsumer(brokers, topic, group, offset, false) }
[ "func", "NewConsumerGroup", "(", "brokers", "[", "]", "string", ",", "topic", "string", ",", "group", "string", ",", "offset", "int64", ")", "(", "*", "ConsumerGroup", ",", "error", ")", "{", "return", "newConsumer", "(", "brokers", ",", "topic", ",", "g...
// NewConsumerGroup returns a new asynchronous consumer group using default configuration.
[ "NewConsumerGroup", "returns", "a", "new", "asynchronous", "consumer", "group", "using", "default", "configuration", "." ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/kafka/consumer-group.go#L108-L110
153,352
ONSdigital/go-ns
clients/search/search.go
New
func New(searchAPIURL string) *Client { return &Client{ cli: rchttp.NewClient(), url: searchAPIURL, } }
go
func New(searchAPIURL string) *Client { return &Client{ cli: rchttp.NewClient(), url: searchAPIURL, } }
[ "func", "New", "(", "searchAPIURL", "string", ")", "*", "Client", "{", "return", "&", "Client", "{", "cli", ":", "rchttp", ".", "NewClient", "(", ")", ",", "url", ":", "searchAPIURL", ",", "}", "\n", "}" ]
// New creates a new instance of Client with a given search api url
[ "New", "creates", "a", "new", "instance", "of", "Client", "with", "a", "given", "search", "api", "url" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/clients/search/search.go#L61-L66
153,353
ONSdigital/go-ns
clients/search/search.go
Dimension
func (c *Client) Dimension(ctx context.Context, datasetID, edition, version, name, query string, params ...Config) (m *Model, err error) { offset := defaultOffset limit := defaultLimit if len(params) > 0 { if params[0].Offset != nil { offset = *params[0].Offset } if params[0].Limit != nil { limit = *params[0].Limit } } uri := fmt.Sprintf("%s/search/datasets/%s/editions/%s/versions/%s/dimensions/%s?", c.url, datasetID, edition, version, name, ) v := url.Values{} v.Add("q", query) v.Add("limit", strconv.Itoa(limit)) v.Add("offset", strconv.Itoa(offset)) uri = uri + v.Encode() clientlog.Do(ctx, "searching for dataset dimension option", service, uri) req, err := http.NewRequest("GET", uri, nil) if err != nil { return } if len(params) > 0 { if len(params[0].InternalToken) > 0 { req.Header.Set(common.DeprecatedAuthHeader, params[0].InternalToken) } if len(params[0].FlorenceToken) > 0 { req.Header.Set(common.FlorenceHeaderKey, params[0].FlorenceToken) } } resp, err := c.cli.Do(ctx, req) if err != nil { return nil, err } if resp.StatusCode != http.StatusOK { return nil, &ErrInvalidSearchAPIResponse{http.StatusOK, resp.StatusCode, uri} } defer resp.Body.Close() err = json.NewDecoder(resp.Body).Decode(&m) return }
go
func (c *Client) Dimension(ctx context.Context, datasetID, edition, version, name, query string, params ...Config) (m *Model, err error) { offset := defaultOffset limit := defaultLimit if len(params) > 0 { if params[0].Offset != nil { offset = *params[0].Offset } if params[0].Limit != nil { limit = *params[0].Limit } } uri := fmt.Sprintf("%s/search/datasets/%s/editions/%s/versions/%s/dimensions/%s?", c.url, datasetID, edition, version, name, ) v := url.Values{} v.Add("q", query) v.Add("limit", strconv.Itoa(limit)) v.Add("offset", strconv.Itoa(offset)) uri = uri + v.Encode() clientlog.Do(ctx, "searching for dataset dimension option", service, uri) req, err := http.NewRequest("GET", uri, nil) if err != nil { return } if len(params) > 0 { if len(params[0].InternalToken) > 0 { req.Header.Set(common.DeprecatedAuthHeader, params[0].InternalToken) } if len(params[0].FlorenceToken) > 0 { req.Header.Set(common.FlorenceHeaderKey, params[0].FlorenceToken) } } resp, err := c.cli.Do(ctx, req) if err != nil { return nil, err } if resp.StatusCode != http.StatusOK { return nil, &ErrInvalidSearchAPIResponse{http.StatusOK, resp.StatusCode, uri} } defer resp.Body.Close() err = json.NewDecoder(resp.Body).Decode(&m) return }
[ "func", "(", "c", "*", "Client", ")", "Dimension", "(", "ctx", "context", ".", "Context", ",", "datasetID", ",", "edition", ",", "version", ",", "name", ",", "query", "string", ",", "params", "...", "Config", ")", "(", "m", "*", "Model", ",", "err", ...
// Dimension allows the searching of a dimension for a specific dimension option, optionally // pass in configuration parameters as an additional field. This can include a request specific // internal token
[ "Dimension", "allows", "the", "searching", "of", "a", "dimension", "for", "a", "specific", "dimension", "option", "optionally", "pass", "in", "configuration", "parameters", "as", "an", "additional", "field", ".", "This", "can", "include", "a", "request", "specif...
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/clients/search/search.go#L85-L142
153,354
ONSdigital/go-ns
common/mock_common/rchttp_client.go
NewMockRCHTTPClienter
func NewMockRCHTTPClienter(ctrl *gomock.Controller) *MockRCHTTPClienter { mock := &MockRCHTTPClienter{ctrl: ctrl} mock.recorder = &MockRCHTTPClienterMockRecorder{mock} return mock }
go
func NewMockRCHTTPClienter(ctrl *gomock.Controller) *MockRCHTTPClienter { mock := &MockRCHTTPClienter{ctrl: ctrl} mock.recorder = &MockRCHTTPClienterMockRecorder{mock} return mock }
[ "func", "NewMockRCHTTPClienter", "(", "ctrl", "*", "gomock", ".", "Controller", ")", "*", "MockRCHTTPClienter", "{", "mock", ":=", "&", "MockRCHTTPClienter", "{", "ctrl", ":", "ctrl", "}", "\n", "mock", ".", "recorder", "=", "&", "MockRCHTTPClienterMockRecorder"...
// NewMockRCHTTPClienter creates a new mock instance
[ "NewMockRCHTTPClienter", "creates", "a", "new", "mock", "instance" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/common/mock_common/rchttp_client.go#L29-L33
153,355
ONSdigital/go-ns
common/mock_common/rchttp_client.go
GetMaxRetries
func (m *MockRCHTTPClienter) GetMaxRetries() int { ret := m.ctrl.Call(m, "GetMaxRetries") ret0, _ := ret[0].(int) return ret0 }
go
func (m *MockRCHTTPClienter) GetMaxRetries() int { ret := m.ctrl.Call(m, "GetMaxRetries") ret0, _ := ret[0].(int) return ret0 }
[ "func", "(", "m", "*", "MockRCHTTPClienter", ")", "GetMaxRetries", "(", ")", "int", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "int", ")", "\n...
// GetMaxRetries mocks base method
[ "GetMaxRetries", "mocks", "base", "method" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/common/mock_common/rchttp_client.go#L67-L71
153,356
ONSdigital/go-ns
common/mock_common/rchttp_client.go
GetMaxRetries
func (mr *MockRCHTTPClienterMockRecorder) GetMaxRetries() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMaxRetries", reflect.TypeOf((*MockRCHTTPClienter)(nil).GetMaxRetries)) }
go
func (mr *MockRCHTTPClienterMockRecorder) GetMaxRetries() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMaxRetries", reflect.TypeOf((*MockRCHTTPClienter)(nil).GetMaxRetries)) }
[ "func", "(", "mr", "*", "MockRCHTTPClienterMockRecorder", ")", "GetMaxRetries", "(", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"", "\"", ",", "reflect", ...
// GetMaxRetries indicates an expected call of GetMaxRetries
[ "GetMaxRetries", "indicates", "an", "expected", "call", "of", "GetMaxRetries" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/common/mock_common/rchttp_client.go#L74-L76
153,357
ONSdigital/go-ns
common/mock_common/rchttp_client.go
SetAuthToken
func (m *MockRCHTTPClienter) SetAuthToken(arg0 string) { m.ctrl.Call(m, "SetAuthToken", arg0) }
go
func (m *MockRCHTTPClienter) SetAuthToken(arg0 string) { m.ctrl.Call(m, "SetAuthToken", arg0) }
[ "func", "(", "m", "*", "MockRCHTTPClienter", ")", "SetAuthToken", "(", "arg0", "string", ")", "{", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "arg0", ")", "\n", "}" ]
// SetAuthToken mocks base method
[ "SetAuthToken", "mocks", "base", "method" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/common/mock_common/rchttp_client.go#L131-L133
153,358
ONSdigital/go-ns
common/mock_common/rchttp_client.go
SetDownloadServiceToken
func (m *MockRCHTTPClienter) SetDownloadServiceToken(arg0 string) { m.ctrl.Call(m, "SetDownloadServiceToken", arg0) }
go
func (m *MockRCHTTPClienter) SetDownloadServiceToken(arg0 string) { m.ctrl.Call(m, "SetDownloadServiceToken", arg0) }
[ "func", "(", "m", "*", "MockRCHTTPClienter", ")", "SetDownloadServiceToken", "(", "arg0", "string", ")", "{", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "arg0", ")", "\n", "}" ]
// SetDownloadServiceToken mocks base method
[ "SetDownloadServiceToken", "mocks", "base", "method" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/common/mock_common/rchttp_client.go#L141-L143
153,359
ONSdigital/go-ns
common/mock_common/rchttp_client.go
SetMaxRetries
func (m *MockRCHTTPClienter) SetMaxRetries(arg0 int) { m.ctrl.Call(m, "SetMaxRetries", arg0) }
go
func (m *MockRCHTTPClienter) SetMaxRetries(arg0 int) { m.ctrl.Call(m, "SetMaxRetries", arg0) }
[ "func", "(", "m", "*", "MockRCHTTPClienter", ")", "SetMaxRetries", "(", "arg0", "int", ")", "{", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "arg0", ")", "\n", "}" ]
// SetMaxRetries mocks base method
[ "SetMaxRetries", "mocks", "base", "method" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/common/mock_common/rchttp_client.go#L151-L153
153,360
ONSdigital/go-ns
common/mock_common/rchttp_client.go
SetTimeout
func (m *MockRCHTTPClienter) SetTimeout(arg0 time.Duration) { m.ctrl.Call(m, "SetTimeout", arg0) }
go
func (m *MockRCHTTPClienter) SetTimeout(arg0 time.Duration) { m.ctrl.Call(m, "SetTimeout", arg0) }
[ "func", "(", "m", "*", "MockRCHTTPClienter", ")", "SetTimeout", "(", "arg0", "time", ".", "Duration", ")", "{", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "arg0", ")", "\n", "}" ]
// SetTimeout mocks base method
[ "SetTimeout", "mocks", "base", "method" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/common/mock_common/rchttp_client.go#L161-L163
153,361
ONSdigital/go-ns
audit/log.go
LogActionFailure
func LogActionFailure(ctx context.Context, auditedAction string, auditedResult string, err error, logData log.Data) { if logData == nil { logData = log.Data{} } logData["auditAction"] = auditedAction logData["auditResult"] = auditedResult LogError(ctx, errors.WithMessage(err, AuditActionErr), logData) }
go
func LogActionFailure(ctx context.Context, auditedAction string, auditedResult string, err error, logData log.Data) { if logData == nil { logData = log.Data{} } logData["auditAction"] = auditedAction logData["auditResult"] = auditedResult LogError(ctx, errors.WithMessage(err, AuditActionErr), logData) }
[ "func", "LogActionFailure", "(", "ctx", "context", ".", "Context", ",", "auditedAction", "string", ",", "auditedResult", "string", ",", "err", "error", ",", "logData", "log", ".", "Data", ")", "{", "if", "logData", "==", "nil", "{", "logData", "=", "log", ...
// LogActionFailure adds auditting data to log.Data before calling LogError
[ "LogActionFailure", "adds", "auditting", "data", "to", "log", ".", "Data", "before", "calling", "LogError" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/audit/log.go#L17-L26
153,362
ONSdigital/go-ns
audit/log.go
LogError
func LogError(ctx context.Context, err error, data log.Data) { data = addLogData(ctx, data) log.ErrorCtx(ctx, err, data) }
go
func LogError(ctx context.Context, err error, data log.Data) { data = addLogData(ctx, data) log.ErrorCtx(ctx, err, data) }
[ "func", "LogError", "(", "ctx", "context", ".", "Context", ",", "err", "error", ",", "data", "log", ".", "Data", ")", "{", "data", "=", "addLogData", "(", "ctx", ",", "data", ")", "\n\n", "log", ".", "ErrorCtx", "(", "ctx", ",", "err", ",", "data",...
// LogError creates a structured error message when auditing fails
[ "LogError", "creates", "a", "structured", "error", "message", "when", "auditing", "fails" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/audit/log.go#L29-L33
153,363
ONSdigital/go-ns
audit/log.go
LogInfo
func LogInfo(ctx context.Context, message string, data log.Data) { data = addLogData(ctx, data) log.InfoCtx(ctx, message, data) }
go
func LogInfo(ctx context.Context, message string, data log.Data) { data = addLogData(ctx, data) log.InfoCtx(ctx, message, data) }
[ "func", "LogInfo", "(", "ctx", "context", ".", "Context", ",", "message", "string", ",", "data", "log", ".", "Data", ")", "{", "data", "=", "addLogData", "(", "ctx", ",", "data", ")", "\n\n", "log", ".", "InfoCtx", "(", "ctx", ",", "message", ",", ...
// LogInfo creates a structured info message when auditing succeeds
[ "LogInfo", "creates", "a", "structured", "info", "message", "when", "auditing", "succeeds" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/audit/log.go#L36-L40
153,364
ONSdigital/go-ns
clients/codelist/codelist.go
GetValues
func (c *Client) GetValues(id string) (vals DimensionValues, err error) { uri := fmt.Sprintf("%s/code-lists/%s/codes", c.url, id) clientlog.Do(context.Background(), "retrieving codes from codelist", service, uri) resp, err := c.cli.Get(context.Background(), uri) if err != nil { return } if resp.StatusCode != http.StatusOK { err = &ErrInvalidCodelistAPIResponse{http.StatusOK, resp.StatusCode, uri} return } b, err := ioutil.ReadAll(resp.Body) if err != nil { return } defer resp.Body.Close() err = json.Unmarshal(b, &vals) return }
go
func (c *Client) GetValues(id string) (vals DimensionValues, err error) { uri := fmt.Sprintf("%s/code-lists/%s/codes", c.url, id) clientlog.Do(context.Background(), "retrieving codes from codelist", service, uri) resp, err := c.cli.Get(context.Background(), uri) if err != nil { return } if resp.StatusCode != http.StatusOK { err = &ErrInvalidCodelistAPIResponse{http.StatusOK, resp.StatusCode, uri} return } b, err := ioutil.ReadAll(resp.Body) if err != nil { return } defer resp.Body.Close() err = json.Unmarshal(b, &vals) return }
[ "func", "(", "c", "*", "Client", ")", "GetValues", "(", "id", "string", ")", "(", "vals", "DimensionValues", ",", "err", "error", ")", "{", "uri", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", ".", "url", ",", "id", ")", "\n\n", "client...
// GetValues returns dimension values from the codelist api
[ "GetValues", "returns", "dimension", "values", "from", "the", "codelist", "api" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/clients/codelist/codelist.go#L69-L92
153,365
ONSdigital/go-ns
clients/codelist/codelist.go
GetIDNameMap
func (c *Client) GetIDNameMap(id string) (map[string]string, error) { uri := fmt.Sprintf("%s/code-lists/%s/codes", c.url, id) resp, err := c.cli.Get(context.Background(), uri) if err != nil { return nil, err } if resp.StatusCode != http.StatusOK { err = &ErrInvalidCodelistAPIResponse{http.StatusOK, resp.StatusCode, uri} return nil, err } b, err := ioutil.ReadAll(resp.Body) if err != nil { return nil, err } defer resp.Body.Close() var vals DimensionValues if err = json.Unmarshal(b, &vals); err != nil { return nil, err } idNames := make(map[string]string) for _, val := range vals.Items { idNames[val.ID] = val.Label } return idNames, nil }
go
func (c *Client) GetIDNameMap(id string) (map[string]string, error) { uri := fmt.Sprintf("%s/code-lists/%s/codes", c.url, id) resp, err := c.cli.Get(context.Background(), uri) if err != nil { return nil, err } if resp.StatusCode != http.StatusOK { err = &ErrInvalidCodelistAPIResponse{http.StatusOK, resp.StatusCode, uri} return nil, err } b, err := ioutil.ReadAll(resp.Body) if err != nil { return nil, err } defer resp.Body.Close() var vals DimensionValues if err = json.Unmarshal(b, &vals); err != nil { return nil, err } idNames := make(map[string]string) for _, val := range vals.Items { idNames[val.ID] = val.Label } return idNames, nil }
[ "func", "(", "c", "*", "Client", ")", "GetIDNameMap", "(", "id", "string", ")", "(", "map", "[", "string", "]", "string", ",", "error", ")", "{", "uri", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", ".", "url", ",", "id", ")", "\n", ...
// GetIDNameMap returns dimension values in the form of an id name map
[ "GetIDNameMap", "returns", "dimension", "values", "in", "the", "form", "of", "an", "id", "name", "map" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/clients/codelist/codelist.go#L95-L124
153,366
ONSdigital/go-ns
clients/codelist/codelist.go
GetGeographyCodeLists
func (c *Client) GetGeographyCodeLists() (results CodeListResults, err error) { uri := fmt.Sprintf("%s/code-lists?type=geography", c.url) resp, err := c.cli.Get(context.Background(), uri) if err != nil { return } defer resp.Body.Close() b, err := ioutil.ReadAll(resp.Body) if err != nil { return } err = json.Unmarshal(b, &results) if err != nil { return } return results, nil }
go
func (c *Client) GetGeographyCodeLists() (results CodeListResults, err error) { uri := fmt.Sprintf("%s/code-lists?type=geography", c.url) resp, err := c.cli.Get(context.Background(), uri) if err != nil { return } defer resp.Body.Close() b, err := ioutil.ReadAll(resp.Body) if err != nil { return } err = json.Unmarshal(b, &results) if err != nil { return } return results, nil }
[ "func", "(", "c", "*", "Client", ")", "GetGeographyCodeLists", "(", ")", "(", "results", "CodeListResults", ",", "err", "error", ")", "{", "uri", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", ".", "url", ")", "\n", "resp", ",", "err", ":=...
//GetGeographyCodeLists returns the geography codelists
[ "GetGeographyCodeLists", "returns", "the", "geography", "codelists" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/clients/codelist/codelist.go#L127-L145
153,367
ONSdigital/go-ns
clients/codelist/codelist.go
GetCodeListEditions
func (c *Client) GetCodeListEditions(codeListID string) (editions EditionsListResults, err error) { url := fmt.Sprintf("%s/code-lists/%s/editions", c.url, codeListID) resp, err := c.cli.Get(context.Background(), url) if err != nil { return } defer resp.Body.Close() b, err := ioutil.ReadAll(resp.Body) if err != nil { return } err = json.Unmarshal(b, &editions) if err != nil { return } return editions, nil }
go
func (c *Client) GetCodeListEditions(codeListID string) (editions EditionsListResults, err error) { url := fmt.Sprintf("%s/code-lists/%s/editions", c.url, codeListID) resp, err := c.cli.Get(context.Background(), url) if err != nil { return } defer resp.Body.Close() b, err := ioutil.ReadAll(resp.Body) if err != nil { return } err = json.Unmarshal(b, &editions) if err != nil { return } return editions, nil }
[ "func", "(", "c", "*", "Client", ")", "GetCodeListEditions", "(", "codeListID", "string", ")", "(", "editions", "EditionsListResults", ",", "err", "error", ")", "{", "url", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", ".", "url", ",", "codeL...
//GetCodeListEditions returns the editions for a codelist
[ "GetCodeListEditions", "returns", "the", "editions", "for", "a", "codelist" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/clients/codelist/codelist.go#L148-L166
153,368
ONSdigital/go-ns
clients/codelist/codelist.go
GetCodes
func (c *Client) GetCodes(codeListID string, edition string) (codes CodesResults, err error) { url := fmt.Sprintf("%s/code-lists/%s/editions/%s/codes", c.url, codeListID, edition) resp, err := c.cli.Get(context.Background(), url) if err != nil { return } defer resp.Body.Close() b, err := ioutil.ReadAll(resp.Body) if err != nil { return } err = json.Unmarshal(b, &codes) if err != nil { return } return codes, nil }
go
func (c *Client) GetCodes(codeListID string, edition string) (codes CodesResults, err error) { url := fmt.Sprintf("%s/code-lists/%s/editions/%s/codes", c.url, codeListID, edition) resp, err := c.cli.Get(context.Background(), url) if err != nil { return } defer resp.Body.Close() b, err := ioutil.ReadAll(resp.Body) if err != nil { return } err = json.Unmarshal(b, &codes) if err != nil { return } return codes, nil }
[ "func", "(", "c", "*", "Client", ")", "GetCodes", "(", "codeListID", "string", ",", "edition", "string", ")", "(", "codes", "CodesResults", ",", "err", "error", ")", "{", "url", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", ".", "url", ",...
//GetCodes returns the codes for a specific edition of a code list
[ "GetCodes", "returns", "the", "codes", "for", "a", "specific", "edition", "of", "a", "code", "list" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/clients/codelist/codelist.go#L169-L187
153,369
ONSdigital/go-ns
clients/codelist/codelist.go
GetCodeByID
func (c *Client) GetCodeByID(codeListID string, edition string, codeID string) (code CodeResult, err error) { url := fmt.Sprintf("%s/code-lists/%s/editions/%s/codes/%s", c.url, codeListID, edition, codeID) resp, err := c.cli.Get(context.Background(), url) if err != nil { return } defer resp.Body.Close() b, err := ioutil.ReadAll(resp.Body) if err != nil { return } err = json.Unmarshal(b, &code) if err != nil { return } return code, nil }
go
func (c *Client) GetCodeByID(codeListID string, edition string, codeID string) (code CodeResult, err error) { url := fmt.Sprintf("%s/code-lists/%s/editions/%s/codes/%s", c.url, codeListID, edition, codeID) resp, err := c.cli.Get(context.Background(), url) if err != nil { return } defer resp.Body.Close() b, err := ioutil.ReadAll(resp.Body) if err != nil { return } err = json.Unmarshal(b, &code) if err != nil { return } return code, nil }
[ "func", "(", "c", "*", "Client", ")", "GetCodeByID", "(", "codeListID", "string", ",", "edition", "string", ",", "codeID", "string", ")", "(", "code", "CodeResult", ",", "err", "error", ")", "{", "url", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", "...
// GetCodeByID returns informtion about a code
[ "GetCodeByID", "returns", "informtion", "about", "a", "code" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/clients/codelist/codelist.go#L190-L209
153,370
ONSdigital/go-ns
neo4j/healthcheck.go
Healthcheck
func (neo4j *HealthCheckClient) Healthcheck() (string, error) { logData := log.Data{"statement": pingStmt} conn, err := neo4j.dbPool.OpenPool() if err != nil { log.ErrorC("neo4j healthcheck open pool", err, logData) return neo4j.serviceName, err } defer conn.Close() rows, err := conn.QueryNeo(pingStmt, nil) if err != nil { log.ErrorC("neo4j healthcheck query", err, logData) return neo4j.serviceName, err } defer rows.Close() return neo4j.serviceName, nil }
go
func (neo4j *HealthCheckClient) Healthcheck() (string, error) { logData := log.Data{"statement": pingStmt} conn, err := neo4j.dbPool.OpenPool() if err != nil { log.ErrorC("neo4j healthcheck open pool", err, logData) return neo4j.serviceName, err } defer conn.Close() rows, err := conn.QueryNeo(pingStmt, nil) if err != nil { log.ErrorC("neo4j healthcheck query", err, logData) return neo4j.serviceName, err } defer rows.Close() return neo4j.serviceName, nil }
[ "func", "(", "neo4j", "*", "HealthCheckClient", ")", "Healthcheck", "(", ")", "(", "string", ",", "error", ")", "{", "logData", ":=", "log", ".", "Data", "{", "\"", "\"", ":", "pingStmt", "}", "\n", "conn", ",", "err", ":=", "neo4j", ".", "dbPool", ...
// Healthcheck calls neo4j to check its health status.
[ "Healthcheck", "calls", "neo4j", "to", "check", "its", "health", "status", "." ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/neo4j/healthcheck.go#L30-L48
153,371
ONSdigital/go-ns
common/identity.go
IsUserPresent
func IsUserPresent(ctx context.Context) bool { userIdentity := ctx.Value(UserIdentityKey) return userIdentity != nil && userIdentity != "" }
go
func IsUserPresent(ctx context.Context) bool { userIdentity := ctx.Value(UserIdentityKey) return userIdentity != nil && userIdentity != "" }
[ "func", "IsUserPresent", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "userIdentity", ":=", "ctx", ".", "Value", "(", "UserIdentityKey", ")", "\n", "return", "userIdentity", "!=", "nil", "&&", "userIdentity", "!=", "\"", "\"", "\n\n", "}" ]
// IsUserPresent determines if a user identity is present on the given context
[ "IsUserPresent", "determines", "if", "a", "user", "identity", "is", "present", "on", "the", "given", "context" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/common/identity.go#L46-L50
153,372
ONSdigital/go-ns
common/identity.go
IsFlorenceIdentityPresent
func IsFlorenceIdentityPresent(ctx context.Context) bool { florenceID := ctx.Value(FlorenceIdentityKey) return florenceID != nil && florenceID != "" }
go
func IsFlorenceIdentityPresent(ctx context.Context) bool { florenceID := ctx.Value(FlorenceIdentityKey) return florenceID != nil && florenceID != "" }
[ "func", "IsFlorenceIdentityPresent", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "florenceID", ":=", "ctx", ".", "Value", "(", "FlorenceIdentityKey", ")", "\n", "return", "florenceID", "!=", "nil", "&&", "florenceID", "!=", "\"", "\"", "\n", "}"...
// IsFlorenceIdentityPresent determines if a florence identity is present on the given context
[ "IsFlorenceIdentityPresent", "determines", "if", "a", "florence", "identity", "is", "present", "on", "the", "given", "context" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/common/identity.go#L53-L56
153,373
ONSdigital/go-ns
common/identity.go
AddUserHeader
func AddUserHeader(r *http.Request, user string) { r.Header.Add(UserHeaderKey, user) }
go
func AddUserHeader(r *http.Request, user string) { r.Header.Add(UserHeaderKey, user) }
[ "func", "AddUserHeader", "(", "r", "*", "http", ".", "Request", ",", "user", "string", ")", "{", "r", ".", "Header", ".", "Add", "(", "UserHeaderKey", ",", "user", ")", "\n", "}" ]
// AddUserHeader sets the given user ID on the given request
[ "AddUserHeader", "sets", "the", "given", "user", "ID", "on", "the", "given", "request" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/common/identity.go#L59-L61
153,374
ONSdigital/go-ns
common/identity.go
AddServiceTokenHeader
func AddServiceTokenHeader(r *http.Request, serviceToken string) { if len(serviceToken) > 0 { r.Header.Add(AuthHeaderKey, BearerPrefix+serviceToken) } }
go
func AddServiceTokenHeader(r *http.Request, serviceToken string) { if len(serviceToken) > 0 { r.Header.Add(AuthHeaderKey, BearerPrefix+serviceToken) } }
[ "func", "AddServiceTokenHeader", "(", "r", "*", "http", ".", "Request", ",", "serviceToken", "string", ")", "{", "if", "len", "(", "serviceToken", ")", ">", "0", "{", "r", ".", "Header", ".", "Add", "(", "AuthHeaderKey", ",", "BearerPrefix", "+", "servic...
// AddServiceTokenHeader sets the given service token on the given request
[ "AddServiceTokenHeader", "sets", "the", "given", "service", "token", "on", "the", "given", "request" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/common/identity.go#L64-L68
153,375
ONSdigital/go-ns
common/identity.go
AddDownloadServiceTokenHeader
func AddDownloadServiceTokenHeader(r *http.Request, serviceToken string) { if len(serviceToken) > 0 { r.Header.Add(DownloadServiceHeaderKey, serviceToken) } }
go
func AddDownloadServiceTokenHeader(r *http.Request, serviceToken string) { if len(serviceToken) > 0 { r.Header.Add(DownloadServiceHeaderKey, serviceToken) } }
[ "func", "AddDownloadServiceTokenHeader", "(", "r", "*", "http", ".", "Request", ",", "serviceToken", "string", ")", "{", "if", "len", "(", "serviceToken", ")", ">", "0", "{", "r", ".", "Header", ".", "Add", "(", "DownloadServiceHeaderKey", ",", "serviceToken...
// AddDownloadServiceTokenHeader sets the given download service token on the given request
[ "AddDownloadServiceTokenHeader", "sets", "the", "given", "download", "service", "token", "on", "the", "given", "request" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/common/identity.go#L71-L75
153,376
ONSdigital/go-ns
common/identity.go
User
func User(ctx context.Context) string { userIdentity, _ := ctx.Value(UserIdentityKey).(string) return userIdentity }
go
func User(ctx context.Context) string { userIdentity, _ := ctx.Value(UserIdentityKey).(string) return userIdentity }
[ "func", "User", "(", "ctx", "context", ".", "Context", ")", "string", "{", "userIdentity", ",", "_", ":=", "ctx", ".", "Value", "(", "UserIdentityKey", ")", ".", "(", "string", ")", "\n", "return", "userIdentity", "\n", "}" ]
// User gets the user identity from the context
[ "User", "gets", "the", "user", "identity", "from", "the", "context" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/common/identity.go#L78-L81
153,377
ONSdigital/go-ns
common/identity.go
SetUser
func SetUser(ctx context.Context, user string) context.Context { return context.WithValue(ctx, UserIdentityKey, user) }
go
func SetUser(ctx context.Context, user string) context.Context { return context.WithValue(ctx, UserIdentityKey, user) }
[ "func", "SetUser", "(", "ctx", "context", ".", "Context", ",", "user", "string", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "ctx", ",", "UserIdentityKey", ",", "user", ")", "\n", "}" ]
// SetUser sets the user identity on the context
[ "SetUser", "sets", "the", "user", "identity", "on", "the", "context" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/common/identity.go#L84-L86
153,378
ONSdigital/go-ns
common/identity.go
SetFlorenceIdentity
func SetFlorenceIdentity(ctx context.Context, user string) context.Context { return context.WithValue(ctx, FlorenceIdentityKey, user) }
go
func SetFlorenceIdentity(ctx context.Context, user string) context.Context { return context.WithValue(ctx, FlorenceIdentityKey, user) }
[ "func", "SetFlorenceIdentity", "(", "ctx", "context", ".", "Context", ",", "user", "string", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "ctx", ",", "FlorenceIdentityKey", ",", "user", ")", "\n", "}" ]
// SetFlorenceIdentity sets the florence identity for authentication
[ "SetFlorenceIdentity", "sets", "the", "florence", "identity", "for", "authentication" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/common/identity.go#L89-L91
153,379
ONSdigital/go-ns
common/identity.go
SetFlorenceHeader
func SetFlorenceHeader(ctx context.Context, r *http.Request) { if IsFlorenceIdentityPresent(ctx) { r.Header.Set(FlorenceHeaderKey, ctx.Value(FlorenceIdentityKey).(string)) } }
go
func SetFlorenceHeader(ctx context.Context, r *http.Request) { if IsFlorenceIdentityPresent(ctx) { r.Header.Set(FlorenceHeaderKey, ctx.Value(FlorenceIdentityKey).(string)) } }
[ "func", "SetFlorenceHeader", "(", "ctx", "context", ".", "Context", ",", "r", "*", "http", ".", "Request", ")", "{", "if", "IsFlorenceIdentityPresent", "(", "ctx", ")", "{", "r", ".", "Header", ".", "Set", "(", "FlorenceHeaderKey", ",", "ctx", ".", "Valu...
// SetFlorenceHeader sets a florence Header if the corresponding Identity key is in context
[ "SetFlorenceHeader", "sets", "a", "florence", "Header", "if", "the", "corresponding", "Identity", "key", "is", "in", "context" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/common/identity.go#L94-L98
153,380
ONSdigital/go-ns
common/identity.go
AddAuthHeaders
func AddAuthHeaders(ctx context.Context, r *http.Request, serviceToken string) { if IsUserPresent(ctx) { AddUserHeader(r, User(ctx)) } AddServiceTokenHeader(r, serviceToken) }
go
func AddAuthHeaders(ctx context.Context, r *http.Request, serviceToken string) { if IsUserPresent(ctx) { AddUserHeader(r, User(ctx)) } AddServiceTokenHeader(r, serviceToken) }
[ "func", "AddAuthHeaders", "(", "ctx", "context", ".", "Context", ",", "r", "*", "http", ".", "Request", ",", "serviceToken", "string", ")", "{", "if", "IsUserPresent", "(", "ctx", ")", "{", "AddUserHeader", "(", "r", ",", "User", "(", "ctx", ")", ")", ...
// AddAuthHeaders sets authentication headers for request
[ "AddAuthHeaders", "sets", "authentication", "headers", "for", "request" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/common/identity.go#L101-L106
153,381
ONSdigital/go-ns
common/identity.go
AddDeprecatedHeader
func AddDeprecatedHeader(r *http.Request, token string) { if len(token) > 0 { r.Header.Add(DeprecatedAuthHeader, token) } }
go
func AddDeprecatedHeader(r *http.Request, token string) { if len(token) > 0 { r.Header.Add(DeprecatedAuthHeader, token) } }
[ "func", "AddDeprecatedHeader", "(", "r", "*", "http", ".", "Request", ",", "token", "string", ")", "{", "if", "len", "(", "token", ")", ">", "0", "{", "r", ".", "Header", ".", "Add", "(", "DeprecatedAuthHeader", ",", "token", ")", "\n", "}", "\n", ...
// AddDeprecatedHeader sets the deprecated header on the given request
[ "AddDeprecatedHeader", "sets", "the", "deprecated", "header", "on", "the", "given", "request" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/common/identity.go#L109-L113
153,382
ONSdigital/go-ns
common/identity.go
IsCallerPresent
func IsCallerPresent(ctx context.Context) bool { callerIdentity := ctx.Value(CallerIdentityKey) isPresent := callerIdentity != nil && callerIdentity != "" return isPresent }
go
func IsCallerPresent(ctx context.Context) bool { callerIdentity := ctx.Value(CallerIdentityKey) isPresent := callerIdentity != nil && callerIdentity != "" return isPresent }
[ "func", "IsCallerPresent", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "callerIdentity", ":=", "ctx", ".", "Value", "(", "CallerIdentityKey", ")", "\n", "isPresent", ":=", "callerIdentity", "!=", "nil", "&&", "callerIdentity", "!=", "\"", "\"", ...
// IsCallerPresent determines if an identity is present on the given context.
[ "IsCallerPresent", "determines", "if", "an", "identity", "is", "present", "on", "the", "given", "context", "." ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/common/identity.go#L116-L122
153,383
ONSdigital/go-ns
common/identity.go
Caller
func Caller(ctx context.Context) string { callerIdentity, _ := ctx.Value(CallerIdentityKey).(string) return callerIdentity }
go
func Caller(ctx context.Context) string { callerIdentity, _ := ctx.Value(CallerIdentityKey).(string) return callerIdentity }
[ "func", "Caller", "(", "ctx", "context", ".", "Context", ")", "string", "{", "callerIdentity", ",", "_", ":=", "ctx", ".", "Value", "(", "CallerIdentityKey", ")", ".", "(", "string", ")", "\n", "return", "callerIdentity", "\n", "}" ]
// Caller gets the caller identity from the context
[ "Caller", "gets", "the", "caller", "identity", "from", "the", "context" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/common/identity.go#L125-L129
153,384
ONSdigital/go-ns
common/identity.go
SetCaller
func SetCaller(ctx context.Context, caller string) context.Context { return context.WithValue(ctx, CallerIdentityKey, caller) }
go
func SetCaller(ctx context.Context, caller string) context.Context { return context.WithValue(ctx, CallerIdentityKey, caller) }
[ "func", "SetCaller", "(", "ctx", "context", ".", "Context", ",", "caller", "string", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "ctx", ",", "CallerIdentityKey", ",", "caller", ")", "\n", "}" ]
// SetCaller sets the caller identity on the context
[ "SetCaller", "sets", "the", "caller", "identity", "on", "the", "context" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/common/identity.go#L132-L135
153,385
ONSdigital/go-ns
common/identity.go
GetRequestId
func GetRequestId(ctx context.Context) string { correlationId, _ := ctx.Value(RequestIdKey).(string) return correlationId }
go
func GetRequestId(ctx context.Context) string { correlationId, _ := ctx.Value(RequestIdKey).(string) return correlationId }
[ "func", "GetRequestId", "(", "ctx", "context", ".", "Context", ")", "string", "{", "correlationId", ",", "_", ":=", "ctx", ".", "Value", "(", "RequestIdKey", ")", ".", "(", "string", ")", "\n", "return", "correlationId", "\n", "}" ]
// GetRequestId gets the correlation id on the context
[ "GetRequestId", "gets", "the", "correlation", "id", "on", "the", "context" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/common/identity.go#L138-L141
153,386
ONSdigital/go-ns
common/identity.go
WithRequestId
func WithRequestId(ctx context.Context, correlationId string) context.Context { return context.WithValue(ctx, RequestIdKey, correlationId) }
go
func WithRequestId(ctx context.Context, correlationId string) context.Context { return context.WithValue(ctx, RequestIdKey, correlationId) }
[ "func", "WithRequestId", "(", "ctx", "context", ".", "Context", ",", "correlationId", "string", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "ctx", ",", "RequestIdKey", ",", "correlationId", ")", "\n", "}" ]
// WithRequestId sets the correlation id on the context
[ "WithRequestId", "sets", "the", "correlation", "id", "on", "the", "context" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/common/identity.go#L144-L146
153,387
ONSdigital/go-ns
common/identity.go
AddRequestIdHeader
func AddRequestIdHeader(r *http.Request, token string) { if len(token) > 0 { r.Header.Add(RequestHeaderKey, token) } }
go
func AddRequestIdHeader(r *http.Request, token string) { if len(token) > 0 { r.Header.Add(RequestHeaderKey, token) } }
[ "func", "AddRequestIdHeader", "(", "r", "*", "http", ".", "Request", ",", "token", "string", ")", "{", "if", "len", "(", "token", ")", ">", "0", "{", "r", ".", "Header", ".", "Add", "(", "RequestHeaderKey", ",", "token", ")", "\n", "}", "\n", "}" ]
// AddRequestIdHeader add header for given correlation ID
[ "AddRequestIdHeader", "add", "header", "for", "given", "correlation", "ID" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/common/identity.go#L149-L153
153,388
ONSdigital/go-ns
common/identity.go
NewRequestID
func NewRequestID(size int) string { b := make([]rune, size) randMutex.Lock() for i := range b { b[i] = letters[requestIDRandom.Intn(len(letters))] } randMutex.Unlock() return string(b) }
go
func NewRequestID(size int) string { b := make([]rune, size) randMutex.Lock() for i := range b { b[i] = letters[requestIDRandom.Intn(len(letters))] } randMutex.Unlock() return string(b) }
[ "func", "NewRequestID", "(", "size", "int", ")", "string", "{", "b", ":=", "make", "(", "[", "]", "rune", ",", "size", ")", "\n", "randMutex", ".", "Lock", "(", ")", "\n", "for", "i", ":=", "range", "b", "{", "b", "[", "i", "]", "=", "letters",...
// NewRequestID generates a random string of requested length
[ "NewRequestID", "generates", "a", "random", "string", "of", "requested", "length" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/common/identity.go#L160-L168
153,389
ONSdigital/go-ns
identity/authentication.go
Check
func Check(auditor Auditor, action string, handle func(http.ResponseWriter, *http.Request)) http.HandlerFunc { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() vars := mux.Vars(r) auditParams := audit.GetParameters(ctx, r.URL.EscapedPath(), vars) logData := audit.ToLogData(auditParams) log.DebugR(r, "checking for an identity in request context", nil) if err := auditor.Record(ctx, action, audit.Attempted, auditParams); err != nil { http.Error(w, "internal error", http.StatusInternalServerError) request.DrainBody(r) return } // just checking if an identity exists until permissions are being provided. if !common.IsCallerPresent(ctx) { log.ErrorR(r, errors.New("no identity was found in the context of this request"), logData) if auditErr := auditor.Record(ctx, action, audit.Unsuccessful, auditParams); auditErr != nil { http.Error(w, "internal error", http.StatusInternalServerError) request.DrainBody(r) return } http.Error(w, "unauthenticated request", http.StatusUnauthorized) request.DrainBody(r) return } log.DebugR(r, "identity found in request context, calling downstream handler", logData) // The request has been authenticated, now run the clients request handle(w, r) }) }
go
func Check(auditor Auditor, action string, handle func(http.ResponseWriter, *http.Request)) http.HandlerFunc { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() vars := mux.Vars(r) auditParams := audit.GetParameters(ctx, r.URL.EscapedPath(), vars) logData := audit.ToLogData(auditParams) log.DebugR(r, "checking for an identity in request context", nil) if err := auditor.Record(ctx, action, audit.Attempted, auditParams); err != nil { http.Error(w, "internal error", http.StatusInternalServerError) request.DrainBody(r) return } // just checking if an identity exists until permissions are being provided. if !common.IsCallerPresent(ctx) { log.ErrorR(r, errors.New("no identity was found in the context of this request"), logData) if auditErr := auditor.Record(ctx, action, audit.Unsuccessful, auditParams); auditErr != nil { http.Error(w, "internal error", http.StatusInternalServerError) request.DrainBody(r) return } http.Error(w, "unauthenticated request", http.StatusUnauthorized) request.DrainBody(r) return } log.DebugR(r, "identity found in request context, calling downstream handler", logData) // The request has been authenticated, now run the clients request handle(w, r) }) }
[ "func", "Check", "(", "auditor", "Auditor", ",", "action", "string", ",", "handle", "func", "(", "http", ".", "ResponseWriter", ",", "*", "http", ".", "Request", ")", ")", "http", ".", "HandlerFunc", "{", "return", "http", ".", "HandlerFunc", "(", "func"...
// Check wraps a HTTP handler. If authentication fails an error code is returned else the HTTP handler is called
[ "Check", "wraps", "a", "HTTP", "handler", ".", "If", "authentication", "fails", "an", "error", "code", "is", "returned", "else", "the", "HTTP", "handler", "is", "called" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/identity/authentication.go#L18-L54
153,390
ONSdigital/go-ns
kafka/producer.go
NewProducer
func NewProducer(brokers []string, topic string, envMax int) (Producer, error) { config := sarama.NewConfig() if envMax > 0 { config.Producer.MaxMessageBytes = envMax } producer, err := sarama.NewAsyncProducer(brokers, config) if err != nil { return Producer{}, err } outputChannel := make(chan []byte) errorChannel := make(chan error) closerChannel := make(chan struct{}) closedChannel := make(chan struct{}) go func() { defer close(closedChannel) log.Info("Started kafka producer", log.Data{"topic": topic}) for { select { case err := <-producer.Errors(): log.ErrorC("Producer", err, log.Data{"topic": topic}) errorChannel <- err case message := <-outputChannel: producer.Input() <- &sarama.ProducerMessage{Topic: topic, Value: sarama.StringEncoder(message)} case <-closerChannel: log.Info("Closing kafka producer", log.Data{"topic": topic}) return } } }() return Producer{producer, outputChannel, errorChannel, closerChannel, closedChannel}, nil }
go
func NewProducer(brokers []string, topic string, envMax int) (Producer, error) { config := sarama.NewConfig() if envMax > 0 { config.Producer.MaxMessageBytes = envMax } producer, err := sarama.NewAsyncProducer(brokers, config) if err != nil { return Producer{}, err } outputChannel := make(chan []byte) errorChannel := make(chan error) closerChannel := make(chan struct{}) closedChannel := make(chan struct{}) go func() { defer close(closedChannel) log.Info("Started kafka producer", log.Data{"topic": topic}) for { select { case err := <-producer.Errors(): log.ErrorC("Producer", err, log.Data{"topic": topic}) errorChannel <- err case message := <-outputChannel: producer.Input() <- &sarama.ProducerMessage{Topic: topic, Value: sarama.StringEncoder(message)} case <-closerChannel: log.Info("Closing kafka producer", log.Data{"topic": topic}) return } } }() return Producer{producer, outputChannel, errorChannel, closerChannel, closedChannel}, nil }
[ "func", "NewProducer", "(", "brokers", "[", "]", "string", ",", "topic", "string", ",", "envMax", "int", ")", "(", "Producer", ",", "error", ")", "{", "config", ":=", "sarama", ".", "NewConfig", "(", ")", "\n", "if", "envMax", ">", "0", "{", "config"...
// NewProducer returns a new producer instance using the provided config. The rest of the config is set to defaults.
[ "NewProducer", "returns", "a", "new", "producer", "instance", "using", "the", "provided", "config", ".", "The", "rest", "of", "the", "config", "is", "set", "to", "defaults", "." ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/kafka/producer.go#L59-L92
153,391
ONSdigital/go-ns
healthcheck/mock_healthcheck/mock_healthcheck.go
Healthcheck
func (m *MockClient) Healthcheck() (string, error) { ret := m.ctrl.Call(m, "Healthcheck") ret0, _ := ret[0].(string) ret1, _ := ret[1].(error) return ret0, ret1 }
go
func (m *MockClient) Healthcheck() (string, error) { ret := m.ctrl.Call(m, "Healthcheck") ret0, _ := ret[0].(string) ret1, _ := ret[1].(error) return ret0, ret1 }
[ "func", "(", "m", "*", "MockClient", ")", "Healthcheck", "(", ")", "(", "string", ",", "error", ")", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "...
// Healthcheck mocks base method
[ "Healthcheck", "mocks", "base", "method" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/healthcheck/mock_healthcheck/mock_healthcheck.go#L36-L41
153,392
ONSdigital/go-ns
clients/renderer/renderer.go
New
func New(url string) *Renderer { return &Renderer{ client: rhttp.DefaultClient, url: url, } }
go
func New(url string) *Renderer { return &Renderer{ client: rhttp.DefaultClient, url: url, } }
[ "func", "New", "(", "url", "string", ")", "*", "Renderer", "{", "return", "&", "Renderer", "{", "client", ":", "rhttp", ".", "DefaultClient", ",", "url", ":", "url", ",", "}", "\n", "}" ]
// New creates an instance of renderer with a default client
[ "New", "creates", "an", "instance", "of", "renderer", "with", "a", "default", "client" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/clients/renderer/renderer.go#L40-L45
153,393
ONSdigital/go-ns
clients/renderer/renderer.go
Healthcheck
func (r *Renderer) Healthcheck() (string, error) { resp, err := r.client.Get(r.url + "/healthcheck") if err != nil { return service, err } if resp.StatusCode != http.StatusOK { return service, ErrInvalidRendererResponse{resp.StatusCode} } return service, nil }
go
func (r *Renderer) Healthcheck() (string, error) { resp, err := r.client.Get(r.url + "/healthcheck") if err != nil { return service, err } if resp.StatusCode != http.StatusOK { return service, ErrInvalidRendererResponse{resp.StatusCode} } return service, nil }
[ "func", "(", "r", "*", "Renderer", ")", "Healthcheck", "(", ")", "(", "string", ",", "error", ")", "{", "resp", ",", "err", ":=", "r", ".", "client", ".", "Get", "(", "r", ".", "url", "+", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{",...
// Healthcheck calls the healthcheck endpoint on the renderer and returns any errors
[ "Healthcheck", "calls", "the", "healthcheck", "endpoint", "on", "the", "renderer", "and", "returns", "any", "errors" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/clients/renderer/renderer.go#L48-L59
153,394
ONSdigital/go-ns
clients/renderer/renderer.go
Do
func (r *Renderer) Do(path string, b []byte) ([]byte, error) { // Renderer required JSON to be sent so if byte array is empty, set it to be // empty json if b == nil { b = []byte(`{}`) } uri := r.url + "/" + path clientlog.Do(context.Background(), fmt.Sprintf("rendering template: %s", path), service, uri, log.Data{ "method": "POST", }) req, err := http.NewRequest("POST", uri, bytes.NewBuffer(b)) if err != nil { return nil, err } req.Header.Set("Content-Type", "application/json") resp, err := r.client.Do(req) if err != nil { return nil, err } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return nil, ErrInvalidRendererResponse{resp.StatusCode} } return ioutil.ReadAll(resp.Body) }
go
func (r *Renderer) Do(path string, b []byte) ([]byte, error) { // Renderer required JSON to be sent so if byte array is empty, set it to be // empty json if b == nil { b = []byte(`{}`) } uri := r.url + "/" + path clientlog.Do(context.Background(), fmt.Sprintf("rendering template: %s", path), service, uri, log.Data{ "method": "POST", }) req, err := http.NewRequest("POST", uri, bytes.NewBuffer(b)) if err != nil { return nil, err } req.Header.Set("Content-Type", "application/json") resp, err := r.client.Do(req) if err != nil { return nil, err } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return nil, ErrInvalidRendererResponse{resp.StatusCode} } return ioutil.ReadAll(resp.Body) }
[ "func", "(", "r", "*", "Renderer", ")", "Do", "(", "path", "string", ",", "b", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "// Renderer required JSON to be sent so if byte array is empty, set it to be", "// empty json", "if", "b", "==...
// Do sends a request to the renderer service to render a given template
[ "Do", "sends", "a", "request", "to", "the", "renderer", "service", "to", "render", "a", "given", "template" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/clients/renderer/renderer.go#L62-L93
153,395
ONSdigital/go-ns
common/errors.go
NewONSError
func NewONSError(e error, description string) *ONSError { err := &ONSError{RootError: e} err.AddParameter("ErrorDescription", description) return err }
go
func NewONSError(e error, description string) *ONSError { err := &ONSError{RootError: e} err.AddParameter("ErrorDescription", description) return err }
[ "func", "NewONSError", "(", "e", "error", ",", "description", "string", ")", "*", "ONSError", "{", "err", ":=", "&", "ONSError", "{", "RootError", ":", "e", "}", "\n", "err", ".", "AddParameter", "(", "\"", "\"", ",", "description", ")", "\n", "return"...
// NewONSError creates a new ONS error
[ "NewONSError", "creates", "a", "new", "ONS", "error" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/common/errors.go#L10-L14
153,396
ONSdigital/go-ns
common/errors.go
AddParameter
func (e *ONSError) AddParameter(name string, value interface{}) *ONSError { if e.Parameters == nil { e.Parameters = make(map[string]interface{}, 0) } e.Parameters[name] = value return e }
go
func (e *ONSError) AddParameter(name string, value interface{}) *ONSError { if e.Parameters == nil { e.Parameters = make(map[string]interface{}, 0) } e.Parameters[name] = value return e }
[ "func", "(", "e", "*", "ONSError", ")", "AddParameter", "(", "name", "string", ",", "value", "interface", "{", "}", ")", "*", "ONSError", "{", "if", "e", ".", "Parameters", "==", "nil", "{", "e", ".", "Parameters", "=", "make", "(", "map", "[", "st...
// AddParameter method creates or overwrites parameters attatched to an ONSError
[ "AddParameter", "method", "creates", "or", "overwrites", "parameters", "attatched", "to", "an", "ONSError" ]
81b393bfc6e80674df603b7fde2f31a35e81b9dd
https://github.com/ONSdigital/go-ns/blob/81b393bfc6e80674df603b7fde2f31a35e81b9dd/common/errors.go#L22-L28
153,397
hnakamur/zap-ltsv
encoder.go
safeAddString
func (enc *ltsvEncoder) safeAddString(s string) { for i := 0; i < len(s); { if enc.tryAddRuneSelf(s[i]) { i++ continue } r, size := utf8.DecodeRuneInString(s[i:]) if enc.tryAddRuneError(r, size) { i++ continue } enc.buf.AppendString(s[i : i+size]) i += size } }
go
func (enc *ltsvEncoder) safeAddString(s string) { for i := 0; i < len(s); { if enc.tryAddRuneSelf(s[i]) { i++ continue } r, size := utf8.DecodeRuneInString(s[i:]) if enc.tryAddRuneError(r, size) { i++ continue } enc.buf.AppendString(s[i : i+size]) i += size } }
[ "func", "(", "enc", "*", "ltsvEncoder", ")", "safeAddString", "(", "s", "string", ")", "{", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "s", ")", ";", "{", "if", "enc", ".", "tryAddRuneSelf", "(", "s", "[", "i", "]", ")", "{", "i", "++"...
// safeAddString JSON-escapes a string and appends it to the internal buffer. // Unlike the standard library's encoder, it doesn't attempt to protect the // user from browser vulnerabilities or JSONP-related problems.
[ "safeAddString", "JSON", "-", "escapes", "a", "string", "and", "appends", "it", "to", "the", "internal", "buffer", ".", "Unlike", "the", "standard", "library", "s", "encoder", "it", "doesn", "t", "attempt", "to", "protect", "the", "user", "from", "browser", ...
10a3dd1d839c3a7838fed08fe053fb5a8316d666
https://github.com/hnakamur/zap-ltsv/blob/10a3dd1d839c3a7838fed08fe053fb5a8316d666/encoder.go#L424-L438
153,398
iamduo/go-workq
client.go
Connect
func Connect(addr string) (*Client, error) { conn, err := net.Dial("tcp", addr) if err != nil { return nil, err } return NewClient(conn), nil }
go
func Connect(addr string) (*Client, error) { conn, err := net.Dial("tcp", addr) if err != nil { return nil, err } return NewClient(conn), nil }
[ "func", "Connect", "(", "addr", "string", ")", "(", "*", "Client", ",", "error", ")", "{", "conn", ",", "err", ":=", "net", ".", "Dial", "(", "\"", "\"", ",", "addr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", ...
// Connect to a Workq server returning a Client
[ "Connect", "to", "a", "Workq", "server", "returning", "a", "Client" ]
b301b13f232653cacf107864e699c30cc6e9d821
https://github.com/iamduo/go-workq/blob/b301b13f232653cacf107864e699c30cc6e9d821/client.go#L44-L51
153,399
iamduo/go-workq
client.go
NewClient
func NewClient(conn net.Conn) *Client { rdr := bufio.NewReader(conn) return &Client{ conn: conn, rdr: rdr, parser: &responseParser{rdr: rdr}, } }
go
func NewClient(conn net.Conn) *Client { rdr := bufio.NewReader(conn) return &Client{ conn: conn, rdr: rdr, parser: &responseParser{rdr: rdr}, } }
[ "func", "NewClient", "(", "conn", "net", ".", "Conn", ")", "*", "Client", "{", "rdr", ":=", "bufio", ".", "NewReader", "(", "conn", ")", "\n", "return", "&", "Client", "{", "conn", ":", "conn", ",", "rdr", ":", "rdr", ",", "parser", ":", "&", "re...
// NewClient returns a Client from a net.Conn.
[ "NewClient", "returns", "a", "Client", "from", "a", "net", ".", "Conn", "." ]
b301b13f232653cacf107864e699c30cc6e9d821
https://github.com/iamduo/go-workq/blob/b301b13f232653cacf107864e699c30cc6e9d821/client.go#L54-L61