Skip to content

Commit

Permalink
dependent files
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramky-Infoblox committed Nov 13, 2024
1 parent 972b2c9 commit 1aad213
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 63 deletions.
2 changes: 1 addition & 1 deletion gateway/field_presence.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions gateway/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion gorm/filtering.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
4 changes: 2 additions & 2 deletions gorm/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...) {
Expand Down Expand Up @@ -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))
Expand Down
20 changes: 10 additions & 10 deletions query/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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)
}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions query/filtering_lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion requestid/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions rpc/resource/jsonpb.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (

// MarshalJSONPB implements jsonpb.JSONPBMarshaler interface by marshal
// Identifier from a JSON string in accordance with Atlas Reference format
// <application_name>/<resource_type>/<resource_id>
//
// <application_name>/<resource_type>/<resource_id>
//
// Support "null" value.
func (m Identifier) MarshalJSONPB(*jsonpb.Marshaler) ([]byte, error) {
v := BuildString(m.GetApplicationName(), m.GetResourceType(), m.GetResourceId())
Expand All @@ -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
// <application_name>/<resource_type>/<resource_id>
//
// <application_name>/<resource_type>/<resource_id>
//
// Support "null" value.
func (m *Identifier) UnmarshalJSONPB(_ *jsonpb.Unmarshaler, data []byte) error {
v := strings.Trim(string(data), "\"")
Expand Down
5 changes: 4 additions & 1 deletion rpc/resource/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const (
)

// BuildString builds string id according to Atlas Reference format:
// <application_name>/<resource_type>/<resource_id>
//
// <application_name>/<resource_type>/<resource_id>
func BuildString(aname, rtype, rid string) string {
var l []string

Expand All @@ -26,7 +27,9 @@ func BuildString(aname, rtype, rid string) string {
}

// ParseString parses id according to Atlas Reference format:
//
// <application_name>/<resource_type>/<resource_id>
//
// 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).
Expand Down
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tracing/annotator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions tracing/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
}
26 changes: 13 additions & 13 deletions tracing/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
26 changes: 13 additions & 13 deletions tracing/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
}
Loading

0 comments on commit 1aad213

Please sign in to comment.