diff --git a/gateway/field_presence.go b/gateway/field_presence.go index c3143585..79b5793a 100644 --- a/gateway/field_presence.go +++ b/gateway/field_presence.go @@ -151,7 +151,7 @@ type presenceInterceptorOptionsDecorator struct { type presenceInterceptorOption func(*presenceInterceptorOptionsDecorator) -//WithOverrideFieldMask represent an option to override field mask generated by grpc-gateway +// WithOverrideFieldMask represent an option to override field mask generated by grpc-gateway func WithOverrideFieldMask(d *presenceInterceptorOptionsDecorator) { d.overrideFieldMask = true } diff --git a/gateway/fields.go b/gateway/fields.go index 9fa73fa8..e112a947 100644 --- a/gateway/fields.go +++ b/gateway/fields.go @@ -7,10 +7,10 @@ import ( "github.com/infobloxopen/atlas-app-toolkit/query" ) -//retainFields function extracts the configuration for fields that -//need to be ratained either from gRPC response or from original testRequest -//(in case when gRPC side didn't set any preferences) and retains only -//this fields on outgoing response (dynmap). +// retainFields function extracts the configuration for fields that +// need to be ratained either from gRPC response or from original testRequest +// (in case when gRPC side didn't set any preferences) and retains only +// this fields on outgoing response (dynmap). func retainFields(ctx context.Context, req *http.Request, dynmap map[string]interface{}) { fieldsStr := "" if req != nil { diff --git a/gorm/filtering.go b/gorm/filtering.go index 776ddcca..8d4d2060 100644 --- a/gorm/filtering.go +++ b/gorm/filtering.go @@ -57,7 +57,7 @@ func FilterStringToGorm(ctx context.Context, filter string, obj interface{}, pb return FilteringToGormEx(ctx, f, obj, c) } -//Deprecated: Use FilteringToGormEx instead +// Deprecated: Use FilteringToGormEx instead // FilteringToGorm returns GORM Plain SQL representation of the filtering expression. func FilteringToGorm(ctx context.Context, m *query.Filtering, obj interface{}, pb proto.Message) (string, []interface{}, map[string]struct{}, error) { c := &DefaultFilteringConditionConverter{&DefaultFilteringConditionProcessor{pb}} diff --git a/gorm/utilities.go b/gorm/utilities.go index ef16cedd..13e28d4c 100644 --- a/gorm/utilities.go +++ b/gorm/utilities.go @@ -41,7 +41,7 @@ func HandleFieldPath(ctx context.Context, fieldPath []string, obj interface{}) ( return dbPath, "", nil } -//HandleJSONFiledPath translate field path to JSONB path for postgres jsonb +// HandleJSONFiledPath translate field path to JSONB path for postgres jsonb func HandleJSONFieldPath(ctx context.Context, fieldPath []string, obj interface{}, values ...string) (string, string, error) { operator := "#>>" if isRawJSON(values...) { @@ -82,7 +82,7 @@ func isRawJSON(values ...string) bool { return true } -//TODO: add supprt for embeded objects +// TODO: add supprt for embeded objects func IsJSONCondition(ctx context.Context, fieldPath []string, obj interface{}) bool { fieldName := generator.CamelCase(fieldPath[0]) objType := indirectType(reflect.TypeOf(obj)) diff --git a/query/fields.go b/query/fields.go index 872c083f..b1af86d7 100644 --- a/query/fields.go +++ b/query/fields.go @@ -9,8 +9,8 @@ const ( opCommonInnerDelimiter = "." ) -//FieldSelectionMap is a convenience type that represents map[string]*Field -//used in FieldSelection and Field structs +// FieldSelectionMap is a convenience type that represents map[string]*Field +// used in FieldSelection and Field structs type FieldSelectionMap map[string]*Field func innerDelimiter(delimiter ...string) string { @@ -26,9 +26,9 @@ func toParts(input string, delimiter ...string) []string { return strings.Split(input, split) } -//ParseFieldSelection transforms a string with comma-separated fields that comes -//from client to FieldSelection struct. For complex fields dot is used as a delimeter by -//default, but it is also possible to specify a different delimiter. +// ParseFieldSelection transforms a string with comma-separated fields that comes +// from client to FieldSelection struct. For complex fields dot is used as a delimeter by +// default, but it is also possible to specify a different delimiter. func ParseFieldSelection(input string, delimiter ...string) *FieldSelection { if len(input) == 0 { return nil @@ -44,8 +44,8 @@ func ParseFieldSelection(input string, delimiter ...string) *FieldSelection { return result } -//GoString converts FieldSelection to a string representation -//It implements fmt.GoStringer interface and returns dot-notated fields separated by commas +// GoString converts FieldSelection to a string representation +// It implements fmt.GoStringer interface and returns dot-notated fields separated by commas func (f *FieldSelection) GoString() string { return strings.Join(f.AllFieldStrings(), opCommonDelimiter) } @@ -70,7 +70,7 @@ func addChildFieldString(result *[]string, parent string, field *Field) { } } -//Add allows to add new fields to FieldSelection +// Add allows to add new fields to FieldSelection func (f *FieldSelection) Add(field string, delimiter ...string) { if len(field) == 0 { return @@ -97,7 +97,7 @@ func (f *FieldSelection) Add(field string, delimiter ...string) { } } -//Delete allows to remove fields from FieldSelection +// Delete allows to remove fields from FieldSelection func (f *FieldSelection) Delete(field string, delimiter ...string) bool { if len(field) == 0 || f.Fields == nil { return false @@ -122,7 +122,7 @@ func (f *FieldSelection) Delete(field string, delimiter ...string) bool { return true } -//Get allows to get specified field from FieldSelection +// Get allows to get specified field from FieldSelection func (f *FieldSelection) Get(field string, delimiter ...string) *Field { if len(field) == 0 || f.Fields == nil { return nil diff --git a/query/filtering_lexer.go b/query/filtering_lexer.go index 974b0145..c3874ca6 100644 --- a/query/filtering_lexer.go +++ b/query/filtering_lexer.go @@ -221,7 +221,7 @@ func (t InToken) String() string { return "in" } -//NumberArrayToken represent number array e.g. [1,2,5] +// NumberArrayToken represent number array e.g. [1,2,5] type StringArrayToken struct { TokenBase Values []string @@ -231,7 +231,7 @@ func (t StringArrayToken) String() string { return fmt.Sprintf("%v", t.Values) } -//NumberArrayToken represent number array e.g. [1,2,5] +// NumberArrayToken represent number array e.g. [1,2,5] type NumberArrayToken struct { TokenBase Values []float64 diff --git a/requestid/interceptor.go b/requestid/interceptor.go index 2b8d140c..6218283a 100644 --- a/requestid/interceptor.go +++ b/requestid/interceptor.go @@ -11,7 +11,6 @@ import ( // that should be used as a middleware to generate/include Request-Id in headers and context // for tracing and tracking user's request. // -// // Returned middleware populates Request-Id from gRPC metadata if // they defined in a testRequest message else creates a new one. func UnaryServerInterceptor() grpc.UnaryServerInterceptor { diff --git a/rpc/resource/jsonpb.go b/rpc/resource/jsonpb.go index 32098c31..275ada9e 100644 --- a/rpc/resource/jsonpb.go +++ b/rpc/resource/jsonpb.go @@ -9,7 +9,9 @@ import ( // MarshalJSONPB implements jsonpb.JSONPBMarshaler interface by marshal // Identifier from a JSON string in accordance with Atlas Reference format -// // +// +// // +// // Support "null" value. func (m Identifier) MarshalJSONPB(*jsonpb.Marshaler) ([]byte, error) { v := BuildString(m.GetApplicationName(), m.GetResourceType(), m.GetResourceId()) @@ -28,7 +30,9 @@ var _ json.Marshaler = &Identifier{} // UnmarshalJSONPB implements jsonpb.JSONPBUnmarshaler interface by unmarshal // Identifier to a JSON string in accordance with Atlas Reference format -// // +// +// // +// // Support "null" value. func (m *Identifier) UnmarshalJSONPB(_ *jsonpb.Unmarshaler, data []byte) error { v := strings.Trim(string(data), "\"") diff --git a/rpc/resource/string.go b/rpc/resource/string.go index 444fd91f..c3d0f272 100644 --- a/rpc/resource/string.go +++ b/rpc/resource/string.go @@ -8,7 +8,8 @@ const ( ) // BuildString builds string id according to Atlas Reference format: -// // +// +// // func BuildString(aname, rtype, rid string) string { var l []string @@ -26,7 +27,9 @@ func BuildString(aname, rtype, rid string) string { } // ParseString parses id according to Atlas Reference format: +// // // +// // All leading and trailing Delimiter are removed. // The resource_id is parsed first, then resource type and last application name. // The id "/a/b/c/" will be converted to "a/b/c" and returned as (a, b, c). diff --git a/server/server.go b/server/server.go index ee4624c7..fa839cc5 100644 --- a/server/server.go +++ b/server/server.go @@ -43,7 +43,7 @@ type Server struct { isAutomaticStop bool } -//Middleware wrapper +// Middleware wrapper type Middleware func(handler http.Handler) http.Handler // Option is a functional option for creating a Server diff --git a/tracing/annotator.go b/tracing/annotator.go index f86dc18e..8e613883 100644 --- a/tracing/annotator.go +++ b/tracing/annotator.go @@ -16,8 +16,8 @@ const ( var defaultFormat propagation.HTTPFormat = &b3.HTTPFormat{} -//SpanContextAnnotator retrieve information about current span from context or HTTP headers -//and propagate in binary format to gRPC service +// SpanContextAnnotator retrieve information about current span from context or HTTP headers +// and propagate in binary format to gRPC service func SpanContextAnnotator(ctx context.Context, req *http.Request) metadata.MD { md := make(metadata.MD) diff --git a/tracing/exporter.go b/tracing/exporter.go index bbc548cd..b979174f 100644 --- a/tracing/exporter.go +++ b/tracing/exporter.go @@ -7,7 +7,7 @@ import ( "go.opencensus.io/trace" ) -//Exporter creates a new OC Agent exporter and configure for tracing +// Exporter creates a new OC Agent exporter and configure for tracing func Exporter(address string, serviceName string, sampler trace.Sampler) error { // TRACE: Setup OC agent for tracing exporter, err := ocagent.NewExporter( @@ -25,7 +25,7 @@ func Exporter(address string, serviceName string, sampler trace.Sampler) error { return nil } -//SamplerForFraction init sampler for specified fraction +// SamplerForFraction init sampler for specified fraction func SamplerForFraction(fraction float64) trace.Sampler { return trace.ProbabilitySampler(fraction) } diff --git a/tracing/grpc.go b/tracing/grpc.go index 5db4e8a2..023620bb 100644 --- a/tracing/grpc.go +++ b/tracing/grpc.go @@ -19,7 +19,7 @@ var sensitiveMetadata = map[string]struct{}{ "authorization": struct{}{}, } -//GRPCOption allows extending handler with additional functionality +// GRPCOption allows extending handler with additional functionality type GRPCOption func(*gRPCOptions) type metadataMatcher func(string) (string, bool) @@ -42,48 +42,48 @@ func defaultGRPCOptions() *gRPCOptions { } } -//WithMetadataAnnotation annotate span with request metadata +// WithMetadataAnnotation annotate span with request metadata func WithMetadataAnnotation(f func(context.Context, stats.RPCStats) bool) GRPCOption { return func(ops *gRPCOptions) { ops.spanWithMetadata = f } } -//WithMetadataMatcher set metadata matcher to filterout or preprocess metadata +// WithMetadataMatcher set metadata matcher to filterout or preprocess metadata func WithMetadataMatcher(f func(string) (string, bool)) GRPCOption { return func(ops *gRPCOptions) { ops.metadataMatcher = f } } -//WithGRPCPayloadAnnotation add Inbound/Outbound payload as an attribute to span if f returns true +// WithGRPCPayloadAnnotation add Inbound/Outbound payload as an attribute to span if f returns true func WithGRPCPayloadAnnotation(f func(context.Context, stats.RPCStats) bool) GRPCOption { return func(ops *gRPCOptions) { ops.spanWithPayload = f } } -//WithGRPCPayloadLimit limit payload size propogated to span -//in case payload exceeds limit, payload truncated and -//annotation payload.truncated=true added into span +// WithGRPCPayloadLimit limit payload size propogated to span +// in case payload exceeds limit, payload truncated and +// annotation payload.truncated=true added into span func WithGRPCPayloadLimit(limit int) GRPCOption { return func(ops *gRPCOptions) { ops.maxPayloadSize = limit } } -//Check that &ServerHandler{} comply stats.Handler interface +// Check that &ServerHandler{} comply stats.Handler interface var _ stats.Handler = &ServerHandler{} -//ServerHandler is a wrapper over ocgrpc.ServerHandler -//wrapper extends metadata added into the span +// ServerHandler is a wrapper over ocgrpc.ServerHandler +// wrapper extends metadata added into the span type ServerHandler struct { ocgrpc.ServerHandler options *gRPCOptions } -//NewServerHandler returns wrapper over ocgrpc.ServerHandler +// NewServerHandler returns wrapper over ocgrpc.ServerHandler func NewServerHandler(ops ...GRPCOption) *ServerHandler { options := defaultGRPCOptions() for _, op := range ops { @@ -197,12 +197,12 @@ func payloadToAttributes(key string, value interface{}, limit int) ([]trace.Attr return attrs, truncated, nil } -//defaultHeaderMatcher is a header matcher which just accept all headers +// defaultHeaderMatcher is a header matcher which just accept all headers func defaultMetadataMatcher(h string) (string, bool) { return h, true } -//AlwaysGRPC for each call returns true +// AlwaysGRPC for each call returns true func AlwaysGRPC(_ context.Context, _ stats.RPCStats) bool { return true } diff --git a/tracing/http.go b/tracing/http.go index aad117d9..0a9db2ce 100644 --- a/tracing/http.go +++ b/tracing/http.go @@ -62,7 +62,7 @@ type httpOptions struct { maxPayloadSize int } -//HTTPOption allows extending handler with additional functionality +// HTTPOption allows extending handler with additional functionality type HTTPOption func(*httpOptions) func defaultHTTPOptions() *httpOptions { @@ -75,37 +75,37 @@ func defaultHTTPOptions() *httpOptions { } } -//WithHeadersAnnotation annotate span with http headers +// WithHeadersAnnotation annotate span with http headers func WithHeadersAnnotation(f func(*http.Request) bool) HTTPOption { return func(ops *httpOptions) { ops.spanWithHeaders = f } } -//WithHeaderMatcher set header matcher to filterout or preprocess headers +// WithHeaderMatcher set header matcher to filterout or preprocess headers func WithHeaderMatcher(f func(string) (string, bool)) HTTPOption { return func(ops *httpOptions) { ops.headerMatcher = f } } -//WithPayloadAnnotation add request/response body as an attribute to span if f returns true +// WithPayloadAnnotation add request/response body as an attribute to span if f returns true func WithPayloadAnnotation(f func(*http.Request) bool) HTTPOption { return func(ops *httpOptions) { ops.spanWithPayload = f } } -//WithHTTPPayloadSize limit payload size propagated to span -//in case payload exceeds limit, payload truncated and -//annotation payload.truncated=true added into span +// WithHTTPPayloadSize limit payload size propagated to span +// in case payload exceeds limit, payload truncated and +// annotation payload.truncated=true added into span func WithHTTPPayloadSize(maxSize int) HTTPOption { return func(ops *httpOptions) { ops.maxPayloadSize = maxSize } } -//NewMiddleware wrap handler +// NewMiddleware wrap handler func NewMiddleware(ops ...HTTPOption) func(http.Handler) http.Handler { options := defaultHTTPOptions() for _, op := range ops { @@ -124,10 +124,10 @@ func NewMiddleware(ops ...HTTPOption) func(http.Handler) http.Handler { } } -//Check that &Handler comply with http.Handler interface +// Check that &Handler comply with http.Handler interface var _ http.Handler = &Handler{} -//Handler is a opencensus http plugin wrapper which do some useful things to reach traces +// Handler is a opencensus http plugin wrapper which do some useful things to reach traces type Handler struct { child http.Handler @@ -213,7 +213,7 @@ func newResponseWrapper(w http.ResponseWriter) *responseBodyWrapper { } } -//responseBodyWrapper duplicate all bytes written to it to buffer +// responseBodyWrapper duplicate all bytes written to it to buffer type responseBodyWrapper struct { http.ResponseWriter @@ -249,12 +249,12 @@ func obfuscate(x string) string { return x[:countChars] + "..." } -//defaultHeaderMatcher is a header matcher which just accept all headers +// defaultHeaderMatcher is a header matcher which just accept all headers func defaultHeaderMatcher(h string) (string, bool) { return h, true } -//AlwaysHTTP for each request returns true +// AlwaysHTTP for each request returns true func AlwaysHTTP(_ *http.Request) bool { return true } diff --git a/tracing/span.go b/tracing/span.go index 04e07792..c4e5d593 100644 --- a/tracing/span.go +++ b/tracing/span.go @@ -14,7 +14,7 @@ var ( ErrSpanNotFound = errors.New("there is no currently active spans") ) -//CurrentSpan returns current span +// CurrentSpan returns current span func CurrentSpan(ctx context.Context) (*trace.Span, error) { span := trace.FromContext(ctx) if span == nil { @@ -24,17 +24,17 @@ func CurrentSpan(ctx context.Context) (*trace.Span, error) { return span, nil } -//StartSpan starts span with name +// StartSpan starts span with name func StartSpan(ctx context.Context, name string) (context.Context, *trace.Span) { return trace.StartSpan(ctx, name) } -//TagSpan tags span +// TagSpan tags span func TagSpan(span *trace.Span, attrs ...trace.Attribute) { span.AddAttributes(attrs...) } -//TagCurrentSpan get current span from context and tag it +// TagCurrentSpan get current span from context and tag it func TagCurrentSpan(ctx context.Context, attrs ...trace.Attribute) error { span, err := CurrentSpan(ctx) if err != nil { @@ -45,12 +45,12 @@ func TagCurrentSpan(ctx context.Context, attrs ...trace.Attribute) error { return nil } -//AddMessageSpan adds message into span +// AddMessageSpan adds message into span func AddMessageSpan(span *trace.Span, message string, attrs ...trace.Attribute) { span.Annotate(attrs, message) } -//AddMessageCurrentSpan get current span from context and adds message into it +// AddMessageCurrentSpan get current span from context and adds message into it func AddMessageCurrentSpan(ctx context.Context, message string, attrs ...trace.Attribute) error { span, err := CurrentSpan(ctx) if err != nil { @@ -61,7 +61,7 @@ func AddMessageCurrentSpan(ctx context.Context, message string, attrs ...trace.A return nil } -//AddErrorCurrentSpan get current span from context and adds error into it +// AddErrorCurrentSpan get current span from context and adds error into it func AddErrorCurrentSpan(ctx context.Context, err error) error { if err != nil { return nil @@ -76,7 +76,7 @@ func AddErrorCurrentSpan(ctx context.Context, err error) error { return AddErrorSpan(span, err) } -//AddErrorSpan adds error into span +// AddErrorSpan adds error into span func AddErrorSpan(span *trace.Span, err error) error { var code int32 = trace.StatusCodeUnknown status, ok := status.FromError(err)