Micro-service framework in Go
Go to file
Sönmez Kartal baa1a54919
Merge pull request #214 from koding/webrtc
protocol: webrtc support
2018-07-10 05:13:47 +03:00
config protocol: add webrtc support 2018-01-08 19:46:35 +03:00
dnode Small fixes in code suggested by go vet tool 2017-01-30 01:56:29 -02:00
examples example: fix math kite 2017-11-29 17:59:13 +01:00
kitectl Correcting misspelled words in string and comments 2017-01-30 01:47:04 -02:00
kitekey Correcting misspelled words in string and comments 2017-01-30 01:47:04 -02:00
kitetest Merge pull request #214 from koding/webrtc 2018-07-10 05:13:47 +03:00
kontrol Merge pull request #214 from koding/webrtc 2018-07-10 05:13:47 +03:00
postgres.d make: add postgres target 2016-05-13 00:25:21 +02:00
protocol protocol: add webrtc support 2018-01-08 19:46:35 +03:00
reverseproxy Correcting misspelled words in string and comments 2017-01-30 01:47:04 -02:00
sockjsclient kite: make done channels bufferred to avoid potential leaks 2017-03-24 20:23:29 +01:00
systeminfo Gofmted all files 2017-01-30 01:24:54 -02:00
test appveyor: add initial configuration file 2016-06-16 08:34:10 +02:00
testkeys kontrol: deny self-signed kite keys 2016-06-05 15:10:36 +02:00
testutil kite: adapt code to latest go.uuid version 2018-06-17 12:13:35 +02:00
tunnelproxy sockjs: rewrite import paths 2017-03-20 11:20:20 +01:00
utils Correcting misspelled words in string and comments 2017-01-30 01:47:04 -02:00
.gitignore make: add .env file 2016-05-19 00:07:37 +02:00
.travis.yml dep: init deps with dep tool 2018-01-08 15:31:19 +03:00
appveyor.yml dep: init deps with dep tool 2018-01-08 15:31:19 +03:00
bug_test.go kite: don't explicitely close sessions 2016-06-21 22:52:24 +02:00
client.go protocol: add webrtc support 2018-01-08 19:46:35 +03:00
errors.go kite: add request ID to server-side kite handlers 2016-08-15 12:46:14 +02:00
Gopkg.lock kite: update dep files 2018-06-17 09:51:49 +02:00
Gopkg.toml kite: update dep files 2018-06-17 09:51:49 +02:00
handlers.go protocol: add webrtc support 2018-01-08 19:46:35 +03:00
heartbeat.go client: set timeout for heartbeats / register over HTTP 2017-03-20 11:51:44 +01:00
kite_test.go kite: adapt code to latest go.uuid version 2018-06-17 12:13:35 +02:00
kite.go Merge pull request #214 from koding/webrtc 2018-07-10 05:13:47 +03:00
kontrolclient.go protocol: add webrtc support 2018-01-08 19:46:35 +03:00
LICENSE Update LICENSE 2016-01-07 11:11:37 -08:00
logger_unix.go appveyor: add initial configuration file 2016-06-16 08:34:10 +02:00
logger.go Correcting misspelled words in string and comments 2017-01-30 01:47:04 -02:00
Makefile dep: init deps with dep tool 2018-01-08 15:31:19 +03:00
method_test.go request: refactor Context 2017-11-28 22:59:55 +01:00
method.go Correcting misspelled words in string and comments 2017-01-30 01:47:04 -02:00
README.md Merge pull request #94 from techjanitor/master 2015-04-29 10:49:49 +03:00
registerurl.go kite: limit reading HTTP response payloads 2016-07-27 09:48:02 +02:00
request.go kite: cancel Context when client disconnects 2017-11-29 17:47:10 +01:00
server.go config: add Serve field 2017-06-01 13:16:12 +02:00
tokenrenewer.go tokenrenewer: do not buffer signals 2017-01-04 11:41:52 +01:00

Kite Micro-Service Framework

Kite is a framework for developing micro-services in Go.

GoDoc Build Status

Kite

Kite is both the name of the framework and the micro-service that is written by using this framework. Basically, Kite is a RPC server as well as a client. It connects to other kites and peers to communicate with each other. They can discover other kites using a service called Kontrol, and communicate with them bidirectionaly. The communication protocol uses a WebSocket (or XHR) as transport in order to allow web applications to connect directly to kites.

Kites can talk with each other by sending dnode messages over a socket session. If the client knows the URL of the server kite it can connect to it directly. If the URL is not known, client can ask for it from Kontrol (Service Discovery).

For more info checkout the blog post at GopherAcademy which explains Kite in more detail: http://blog.gopheracademy.com/birthday-bash-2014/kite-microservice-library/

Install and Usage

Install the package with:

go get github.com/koding/kite

Import it with:

import "github.com/koding/kite"

and use kite as the package name inside the code.

What is Kontrol?

Kontrol is the service registry and authentication service used by Kites. It is itself a kite too.

When a kite starts to run, it can registers itself to Kontrol with the Register() method if wished. That enables others to find it by querying Kontrol. There is also a Proxy Kite for giving public URLs to registered kites.

Query has 7 fields:

/<username>/<environment>/<name>/<version>/<region>/<hostname>/<id>
  • You must at least give the username.
  • The order of the fields is from general to specific.
  • Query cannot contains empty parts between fields.

Installing Kontrol

Install Kontrol:

go get github.com/koding/kite/kontrol/kontrol

Generate keys for the Kite key:

openssl genrsa -out key.pem 2048
openssl rsa -in key.pem -pubout > key_pub.pem

Set environment variables:

KONTROL_PORT=6000
KONTROL_USERNAME="kontrol"
KONTROL_STORAGE="etcd"
KONTROL_KONTROLURL="http://127.0.0.1:6000/kite"
KONTROL_PUBLICKEYFILE="certs/key_pub.pem"
KONTROL_PRIVATEKEYFILE="certs/key.pem"

Generate initial Kite key:

./bin/kontrol -initial

How can I use kites from a browser?

A browser can also be a Kite. It has it's own methods ("log" for logging a message to the console, "alert" for displaying alert to the user, etc.). A connected kite can call methods defined on the webpage.

See kite.js library for more information.

How can I write a new kite?

  • Import kite package.
  • Create a new instance with kite.New().
  • Add your method handlers with k.HandleFunc() or k.Handle().
  • Call k.Run()

Below you can find an example, a math kite which calculates the square of a received number:

package main

import "github.com/koding/kite"

func main() {
	// Create a kite
	k := kite.New("math", "1.0.0")

	// Add our handler method with the name "square"
	k.HandleFunc("square", func(r *kite.Request) (interface{}, error) {
		a := r.Args.One().MustFloat64()
		result := a * a    // calculate the square
		return result, nil // send back the result
	}).DisableAuthentication()

	// Attach to a server with port 3636 and run it
	k.Config.Port = 3636
	k.Run()
}

Now let's connect to it and send a 4 as an argument.

package main

import (
	"fmt"

	"github.com/koding/kite"
)

func main() {
	k := kite.New("exp2", "1.0.0")

	// Connect to our math kite
	mathWorker := k.NewClient("http://localhost:3636/kite")
	mathWorker.Dial()

	response, _ := mathWorker.Tell("square", 4) // call "square" method with argument 4
	fmt.Println("result:", response.MustFloat64())
}

Check out the examples folder for more examples.