Help us shape the future of Go! Take the 2026 Go Developer Survey

clockwork

package module
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2025 License: MIT Imports: 6 Imported by: 6

README

codecov Go Report Card

Server-side component for Clockwork browser extension written in GO

Attach and use data-sources to clockwork instance.

package main
import (

"github.com/coretrix/clockwork"
"github.com/go-redis/redis"
)


func main()  {
 client := redis.NewClient(&redis.Options{
 		Addr:     "127.0.0.1:6379", //your address
 		Password: "", // your password
 		DB:       0, 
 	})
 	
 var redisDataProvider clockwork.DataProviderInterface
 redisDataProvider = clockwork.RedisDataProvider{RedisStorageProvider: client}
 profiler := clockwork.Clockwork{DataProvider: redisDataProvider}
}

Mysql data source

var mysqlDataSource dataSource.QueryLoggerDataSourceInterface = &dataSource.MysqlDataSource{}
profiler.SetDatabaseDataSource(mysqlDataSource)

var bind1 []interface{}
var bind2 []interface{}
bind2 = append(bind2, 1, 2, "test param")
mysqlDataSource.LogQuery("mysql", "SELECT * FROM users", 12.224, bind1)
mysqlDataSource.LogQuery("mysql", "SELECT * FROM address where id = ?", 1, bind2)

Redis data source

var redisDataSource dataSource.CommandLoggerDataSourceInterface = &dataSource.RedisDataSource{}
profiler.AddDataSource(redisDataSource)

redisDataSource.LogCommand("hSet", "test_key_1", 0.12)
redisDataSource.LogCommand("hGet", "test_key_2", 0.15)

Cache data source

var cacheDataSource dataSource.CacheLoggerDataSourceInterface = &dataSource.CacheDataSource{}
profiler.AddDataSource(cacheDataSource)

cacheDataSource.LogCache("miss", "price", "30.10$", 12.22, 3000)

Timeline data source

var timelineDataSource dataSource.TimelineLoggerDataSourceInterface = &dataSource.TimelineDataSource{}
profiler.SetTimeLineDataSource(timelineDataSource)

profiler.GetTimeLineDataSource().StartEvent("Event_11", "My first event desc")
//put some logic here
profiler.GetTimeLineDataSource().EndEvent("Event_11")

profiler.GetTimeLineDataSource().StartEvent("Event_22", "My second event desc")
//put some logic here
profiler.GetTimeLineDataSource().EndEvent("Event_22")

Request data source

var requestDataSource dataSource.RequestLoggerDataSourceInterface = &dataSource.RequestResponseDataSource{}
profiler.SetRequestDataSource(requestDataSource)

//in the begining of request
profiler.GetRequestDataSource().SetStartTime(time.Now())
profiler.GetRequestDataSource().StartMemoryUsage()
profiler.GetRequestDataSource().SetController("HomeController", "IndexAction")
profiler.GetRequestDataSource().SetMiddleware([]string{"Authorize", "Normalization", "Guard", "Handler"})

//at the end of request	
profiler.GetRequestDataSource().SetResponseTime(time.Now())
profiler.GetRequestDataSource().SetResponseStatus(200)

Logger(debugger) data source

var loggerDataSource dataSource.LoggerDataSourceInterface = &dataSource.LoggerDataSource{}
profiler.SetLoggerDataSource(loggerDataSource)

profiler.GetLoggerDataSource().LogDebugString("test payment", "payment method works")
test1 := make([]string, 2)
test1[0] = "item1"
test1[1] = "item 2"
profiler.GetLoggerDataSource().LogDebugSlice("cart", test1)

users := make(map[string]string)
users["Adam"] = "33 ages"
users["Fred"] = "15 ages"
profiler.GetLoggerDataSource().LogDebugMap("users", users)	

Before end of the request

You should call this method

profiler.SaveData()

The last thing u need to do is to send 2 special headers into the response:

c.Writer.Header().Set("X-Clockwork-Id", profiler.GetUniqueID())
c.Writer.Header().Set("X-Clockwork-Version", "4.0.13")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clockwork

type Clockwork struct {
	DataProvider DataProviderInterface
	// contains filtered or unexported fields
}

func (*Clockwork) AddDataSource

func (clockwork *Clockwork) AddDataSource(source dataSource.DataSource) *dataSource.DataSource

func (*Clockwork) GetDatabaseDataSource

func (clockwork *Clockwork) GetDatabaseDataSource() dataSource.QueryLoggerInterface

func (*Clockwork) GetLoggerDataSource

func (clockwork *Clockwork) GetLoggerDataSource() dataSource.LoggerDataSourceInterface

func (*Clockwork) GetRequestDataSource

func (clockwork *Clockwork) GetRequestDataSource() dataSource.RequestLoggerDataSourceInterface

func (*Clockwork) GetSavedData

func (clockwork *Clockwork) GetSavedData(id string) dataSource.DataBuffer

func (*Clockwork) GetTimeLineDataSource

func (clockwork *Clockwork) GetTimeLineDataSource() dataSource.TimelineLoggerDataSourceInterface

func (*Clockwork) GetUniqueID

func (clockwork *Clockwork) GetUniqueID() string

func (*Clockwork) Resolve

func (clockwork *Clockwork) Resolve() *dataSource.DataBuffer

func (*Clockwork) SaveData

func (clockwork *Clockwork) SaveData()

func (*Clockwork) SetDatabaseDataSource

func (clockwork *Clockwork) SetDatabaseDataSource(source dataSource.QueryLoggerDataSourceInterface)

func (*Clockwork) SetLoggerDataSource

func (clockwork *Clockwork) SetLoggerDataSource(source dataSource.LoggerDataSourceInterface)

func (*Clockwork) SetRequestDataSource

func (clockwork *Clockwork) SetRequestDataSource(source dataSource.RequestLoggerDataSourceInterface)

func (*Clockwork) SetTimeLineDataSource

func (clockwork *Clockwork) SetTimeLineDataSource(source dataSource.TimelineLoggerDataSourceInterface)

type DataProviderInterface

type DataProviderInterface interface {
	Get(key string, id string) dataSource.DataBuffer
	Set(key string, id string, data *dataSource.DataBuffer)
}

type RedisDataProvider

type RedisDataProvider struct {
	RedisStorageProvider *redis.Client
}

func (*RedisDataProvider) Get

func (provider *RedisDataProvider) Get(key string, id string) dataSource.DataBuffer

func (*RedisDataProvider) Set

func (provider *RedisDataProvider) Set(key string, id string, data *dataSource.DataBuffer)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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