Giter Site home page Giter Site logo

clockwork's Introduction

Server-side component for Clockwork browser extension written in GO

Attach and use data-sources to clockwork instance.

package main
import (

"github.com/anton-shumanski/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")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.