Code Monkey home page Code Monkey logo

kb's Introduction

KB

Go Report Card

KB is a Go API that shows computer availability in the Kilburn Building at the University of Manchester

Using the API

To get the availability in the whole school:

GET /api/status

{
  "e-c07kilf1601.it.manchester.ac.uk": {
    "status": "free",
    "timestamp": "2000-01-01T00:00:00.000000000+01:00",
    "lab": "Tootil 1"
  },
  "e-c07kilf901.it.manchester.ac.uk": {
    "status": "used",
    "timestamp": "2000-01-01T00:00:00.000000000+01:00",
    "lab": "Tootil 0"
  },
  "e-c07kilf3101.it.manchester.ac.uk": {
    "status": "offline",
    "timestamp": "2000-01-01T00:00:00.000000000+01:00",
    "lab": "LF31"
  }
}

To get the availability in one lab:

GET /api/status/labs/:lab

{
  "e-c07kilf901.it.manchester.ac.uk": {
    "status": "free",
    "timestamp": "2000-01-01T00:00:00.000000000+01:00",
    "lab": "Tootil 0"
  },
  "e-c07kilf902.it.manchester.ac.uk": {
    "status": "free",
    "timestamp": "2000-01-01T00:00:00.000000000+01:00",
    "lab": "Tootil 0"
  },
  "e-c07kilf903.it.manchester.ac.uk": {
    "status": "used",
    "timestamp": "2000-01-01T00:00:00.000000000+01:00",
    "lab": "Tootil 0"
  }
}

To check if a particular machine is available:

GET /api/status/machines/:machine

{
  "status": "free",
  "timestamp": "2000-01-01T00:00:00.000000000+01:00",
  "lab": "Tootil 0"
}

Updating the state

The reporter feeds the data to the API via the /report/ endpoint:

POST /report/

{
  "e-c07kilf901.it.manchester.ac.uk": {
    "status": "free",
    "timestamp": "2000-01-01T00:00:00.000000000+01:00",
    "lab": "Tootil 0"
  },
  "e-c07kilf902.it.manchester.ac.uk": {
    "status": "free",
    "timestamp": "2000-01-01T00:00:00.000000000+01:00",
    "lab": "Tootil 0"
  },
  "e-c07kilf903.it.manchester.ac.uk": {
    "status": "used",
    "timestamp": "2000-01-01T00:00:00.000000000+01:00",
    "lab": "Tootil 0"
  }
}

Will return a 200 OK and the state will be updated

Building it

You need two components, one is the API which caches the status of the machines and returns the info (/pull), and the remote part which pushes the information from the network to the API (/push)

To build them you run:

go build -o out/pull pull/main.go
go build -o out/push push/main.go

To run the push, you do:

./out/push <path/to/logs>

To run the API, you do:

./out/pull

kb's People

Contributors

calini avatar

Stargazers

 avatar  avatar  avatar

Watchers

 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.