• Stars
    star
    3,260
  • Rank 13,780 (Top 0.3 %)
  • Language
    Go
  • License
    MIT License
  • Created over 10 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Micro-service framework in Go

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.

More Repositories

1

koding

The Simplest Way to Manage Your Entire Dev Infrastructure!
Go
2,122
star
2

multiconfig

Load configuration from multiple sources in Go
Go
454
star
3

websocketproxy

WebSocket reverse proxy handler for Go
Go
426
star
4

tunnel

Tunnel proxy package in Go
Go
319
star
5

awesome-fuse-fs

Resources related to FUSE (filesystem in user space).
292
star
6

kd

UI Framework for web applications.
CoffeeScript
114
star
7

cache

Caching package for Go
Go
89
star
8

kite.js

Kite client in JavaScript
JavaScript
75
star
9

kdlearn

The source for Learn Koding, a Community Documentation site for Koding.com
CSS
44
star
10

vagrantutil

A toolset to manage Vagrant boxes in Go
Go
43
star
11

rabbitmq

Wrapper for Go's AMQP package
Go
41
star
12

logging

Simple logging package in Go
Go
29
star
13

kpm-scripts

Koding Package Manager Scripts
Shell
24
star
14

redis

Wrapper for redis functions
Go
17
star
15

koding-kubernetes

Run Koding with Kubernetes
16
star
16

terraform

A fork of Terraform
Go
15
star
17

Teamwork

Koding's official collaboration app
10
star
18

koding-system-stacks

Koding VM Images
Shell
9
star
19

kite-healthcheck

JavaScript
6
star
20

rabbitapi

Implementation of RabbitMq Management HTTP Api in Go
Go
6
star
21

docker-compose

5
star
22

hackathon.submit

Sample submission repository for Koding Global Virtual Hackathon.
5
star
23

styleguide-coffeescript

This is the guide we use for developing our own apps internally at Koding.
4
star
24

stacks

Example Koding Stack Scripts
4
star
25

kd-atom

Work locally in your cloud resources
JavaScript
4
star
26

kdhelp

KDHelp is a help bin for Koding VMs
CoffeeScript
4
star
27

shortcuts

CoffeeScript
3
star
28

docker-base

Shell
3
star
29

kdc

CoffeeScript
3
star
30

file

File related utils for Go
Go
3
star
31

packer

Packer templates for Koding's infra
Shell
3
star
32

awspurge

Go
2
star
33

pubnub

PubNub go-client wrapper
Go
2
star
34

eb-deploy

Wercker step for deploying elastic beanstalk
Shell
2
star
35

styleguide-content-sharing

Guide to Social Media Image Sizes, sharing rules etc.
2
star
36

tf_kafka

WIP - Terraform Template for Kafka Cluster.
HCL
2
star
37

docker-singular

Shell
2
star
38

coffee-unused

Find unused variables and imports in CoffeeScript files
CoffeeScript
2
star
39

playgrounds

JavaScript
2
star
40

qfunction

Make sure specified function runs one at a time
CoffeeScript
2
star
41

koding-gitlab

Koding With Gitlab in Google Container Engine
HCL
2
star
42

kloud-provider-example

Go
1
star
43

druid-packer

Packer templates for Druid
Shell
1
star
44

step-s3put

Fork of https://github.com/rioki/step-s3put that uploads to s3 using --acl-private
Shell
1
star
45

tf_druid

Terraform Druid Templates
HCL
1
star
46

backoff

backoff
JavaScript
1
star
47

eventexporter

Go
1
star
48

kodingemail

Go
1
star
49

docker-rabbitmq

1
star
50

kd-react

React components of KD framework views
CoffeeScript
1
star
51

keyconfig

CoffeeScript
1
star
52

gulp-kd-pistachio-compiler

pistachio compiler for KD's own templates
JavaScript
1
star
53

asgd

Listen ASG events and change local configuration files.
Go
1
star
54

sshkey

Package sshkey provides public and private key pair for ssh usage.
Go
1
star