Coder Social home page Coder Social logo

go-urbit's Introduction

Urbit HTTP API implementation in Go

PkgGoDev

This module provides functionality to communicate with Urbit ships. See Urbit home page for more details about it.

NOTE: the packages in this module are still in experimental stage, and the API may change as it gets more developed -- the major version is still 0.

Basic usage

Connect with an Urbit ship using

ship, err := urbit.Dial(address, passcode, nil)

Note that the code can be obtained with the command |code in Dojo inside the Urbit environment. The returned value is a Client that can be used to send requests and receive events.

// Send a Poke
ship.Poke("chat-hook", jsonMessage)

// Subscribe to a path inside an app. The ID in result can be used to
// identify events containing updates for this subscription.
result, err := ship.Subscribe("chat-store", "/keys")

// ...

// Consume events.
for ev := range ship.Events() {
	switch (ev.Type) {
	case "diff":
		if (ev.ID == result.ID) {
			// ev.Data contains the data
		}
	}
}

It is important to consume the Events channel, because the Client will not try to buffer individual events, so processing only happens when that channel is consumed. Depending on the program, either a separate goroutine or including the processing the in the program's mainloop will be the typical solutions.

The next step after being able to talk, is to know what to talk. Most apps running inside Urbit are able to talk via JSON. Their own protocols are currently only documented in the source code (see /sur in Urbit). It is also helpful to see how requests are created and responses are parsed in Landscape (Urbit's reference web client).

For Go, these definitions can be mapped into types and serialization helpers, see the chat package for example.

Examples

A good way to learn how to use the module is to look at the commented examples. Run each of them with

go run EXAMPLE.go

By default the examples will try to connect with the default address and passcode used running local development ships ("fake zod"). They can also be specified in the command line

go run EXAMPLE.go --addr ADDRESS --code CODE

each example has a few more options, see them with

go run EXAMPLE.go --help

go-urbit's People

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.