core

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2022 License: Apache-2.0 Imports: 8 Imported by: 6

README

SQLCommenter Core [In development]

SQLcommenter is a plugin/middleware/wrapper to augment application related information/tags with SQL Statements that can be used later to correlate user code with SQL statements.

This package contains configuration options, framework interface and support functions for all the sqlcommenter go modules

Installation

This is a support package and will be installed indirectly by other go sqlcommenter packages

Usages

Configuration

Users are given control over what tags they want to append by using core.CommenterConfig struct.

type CommenterConfig struct {
    EnableDBDriver    bool
    EnableRoute       bool
    EnableFramework   bool
    EnableController  bool
    EnableAction      bool
    EnableTraceparent bool
    EnableApplication bool
}

Users can also set the values for some static tags by using core.StaticTags struct.

type StaticTags struct {
    Application string
    DriverName  string
}

These two structs together form the core.CommenterOptions struct, which is used by sqlcommenter/go/database/sql.

type CommenterOptions struct {
    Config CommenterConfig
    Tags   StaticTags
}

Documentation

Index

Constants

View Source
const (
	Route       string = "route"
	Controller         = "controller"
	Action             = "action"
	Framework          = "framework"
	Driver             = "db_driver"
	Traceparent        = "traceparent"
	Application        = "application"
)

Constants used as key string for tags. It is not necessary that all SQLCommenter frameworks/ORMs will contain all these keys i.e. it is on best-effort basis.

Variables

This section is empty.

Functions

func ContextInject

func ContextInject(ctx context.Context, h RequestTagsProvider) context.Context

ContextInject injects the tags key-value pairs into context, which can be later passed into drivers/ORMs to finally inject them into SQL queries.

func ConvertMapToComment

func ConvertMapToComment(tags map[string]string) string

ConvertMapToComment returns a comment string given a map of key-value pairs of tags. There are few steps involved here:

  • Sorting the tags by key string
  • url encoding the key value pairs
  • Formatting the key value pairs as "key1=value1,key2=value2" format.

func ExtractTraceparent

func ExtractTraceparent(ctx context.Context) propagation.MapCarrier

ExtractTraceparent extracts the traceparent field using OpenTelemetry library.

func GetFunctionName

func GetFunctionName(i any) string

GetFunctionName returns the name of the function passed.

Types

type CommenterConfig

type CommenterConfig struct {
	EnableDBDriver    bool
	EnableRoute       bool
	EnableFramework   bool
	EnableController  bool
	EnableAction      bool
	EnableTraceparent bool
	EnableApplication bool
}

CommenterConfig contains configurations for SQLCommenter library. We can enable and disable certain tags by enabling these configurations.

type CommenterOptions

type CommenterOptions struct {
	Config CommenterConfig
	Tags   StaticTags
}

CommenterOptions contains all options regarding SQLCommenter library. This includes the configurations as well as any static tags.

type RequestTagsProvider

type RequestTagsProvider interface {
	Route() string
	Action() string
	Framework() string
}

RequestTagsProvider adds a basic interface for other libraries like gorilla/mux to implement.

type StaticTags

type StaticTags struct {
	Application string
	DriverName  string
}

StaticTags are few tags that can be set by the application and will be constant for every API call.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL