tick

package module
v0.0.0-...-8ceecaa Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2022 License: BSD-3-Clause Imports: 14 Imported by: 0

README

Ticker - Live data streams on Golang

This Gopher Sauce framework requires Gopher sauce to work as well as a notion of its template engine.

Tick tracks realtime data from your Mongo database to your client's browser. This is possible with the help of web sockets ws://

How to use it

Ticker supports templates by default. To use a Template function within your gos app functions add the prefix net_<function name> to your function name.

Checkout Tick Sample project.

Import Ticker framework
<import src="github.com/cheikhshift/tick/gos.gxml"/>
Init and set MongoDB

Add this snippet within your <main> tag. Copy the whole snippet if you're Gopher Sauce project has no main tag.

	<main>	
	//Tick encryption key	
	tick.Key = "example key 1234"
	//HostName string syntax [host]:[port]
	// var HostName string included on tick/gos.gxml import
	HostName = "localhost:8080"
	// dbs included on tick/gos.gxml import
	dbs,_ = db.Connect("localhost", "database")
	tick.SetDb(dbs)
	</main>
Declare DB Object pipeline

Struct of dbObjcet. This Struct will be made available on tick import :

	<struct name="dbObject">
	 	Id bson.ObjectId `bson:"_id,omitempty"`
	 	Created time.Time
	 	Track int
	 	Signature string `valid:"unique"`
	</struct>

Add a new method within your <methods> tag (in Gopher Sauce). Replace dbObject with your own model. This snippet will find any database object :

	<method name="GetdbObject" return="dbObject">
		dbo := dbObject{}
		dbs.Q(&dbo).Find(nil).One(&dbo)
		return dbo
	</method>
Template

With the prior section in mind, this is how you track your database object's values. Within your templates on Gopher sauce use the following code.

Get object via pipeline :

{{ $item := GetdbObject }}

Open socket to item :

{{ Tick $item }}

(optional) Display live value of object key. (Any struct field must be in lower case) :

{{ Watch $item "track" }}

Syntax :

{{ Watch mongo_databse_object key_string }}		

Javascript API

Prior to calling each of the JS functions, remember to invoke {{Tick database_object }} to load the API. Follow this syntax to create event handlers for your object :

	<script>
 	//Tick Js function
 	Tick({{ IdOf $item }} , function(data){
 			console.log("Update")
 	})
 	</script>

JS function : Tick(id string , callback function(data) )

  • id : ID of database item.
  • callback : function called on each update.
Detect websocket close on client :
<script>
	$tick.close = function(event ) {
		console.log(event)
	}
</script>

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Key string
	DB  db.DB
)

Functions

func Decrypt

func Decrypt(key []byte, cryptoText string) string

decrypt from base64 to decrypted string

func Encrypt

func Encrypt(key []byte, text string) string

encrypt string to base64 crypto using AES

func ServeWs

func ServeWs(w http.ResponseWriter, r *http.Request)

func SetDb

func SetDb(db db.DB)

Types

This section is empty.

Jump to

Keyboard shortcuts

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