Code Monkey home page Code Monkey logo

goma's Introduction

GOpher MAchine ("goma") is a toolkit for serving resources over The Internet Gopher Protocol. Its design is influenced by Webmachine, in that applications provide resource modules, the functions of which are called in order to navigate the decisions of a flowchart.

A simple resource

This is your basic Hello World resource:

-module(goma_hw).

-compile([export_all]).

init(Args) ->
    {ok, Args}.

resource_exists(_Selector, Context) ->
    {true, Context}.

produce_content(Selector, Context) ->
    Content = io_lib:format("Hello ~s World!",
                            [Selector#goma_selector.raw]),
    {{text, Content}, Context}.

The wiki has more information about what the parameters and expected outputs of these functions. A more interesting resource is found in goma_fs_resource.erl.

Dispatching

Goma chooses the module to handle a selector by splitting the selector on / characters, and then comparing the pieces to a dispatch table. The dispatch table is a list of 3-tuples of the form:

{SelectorMatch, ModuleName, InitArg}

The first element, SelectorMatch is a list of strings and atoms. Each string must match its corresponding selector piece exactly. Each atom is "bound" to its corresponding selector piece, and a list of those bindings is passed to the module's functions. The atom '*' is special: it must come last, and it matches the rest of the selector.

As an example, the SelectorMatch

["foo", bar, '*']

Would match the selector

foo/bar/baz/quux

And create bindings of

[{bar, <<"bar">>}, {'*', <<"baz/quux">>}]

Startup

To startup goma with your dispatch table, use goma:child_spec/1 to create a supervisor child specification, and add that child to your app's supervisor. For example:

-module(myapp_sup).

%% ...other supervisor functions...

init([]) ->
    Name = myapp_goma,
    IP = {127,0,0,1},
    Port = 7070,
    Dispatch = {['*'], goma_hw, []},
    GomaSupSpec = goma:child_spec(Name, IP, Port, Dispatch),
    {ok, {{one_for_one,5,10}, [GomaSupSpec]}}.

goma's People

Contributors

beerriot avatar cmeiklejohn avatar

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.