{"id":18780373,"url":"https://github.com/karan/unit","last_synced_at":"2025-07-17T08:38:53.851Z","repository":{"id":57612392,"uuid":"46102538","full_name":"karan/unit","owner":"karan","description":"A highly modular, fast API framework in Golang, perfectly fitted for Docker","archived":false,"fork":false,"pushed_at":"2015-11-17T04:39:53.000Z","size":545,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-15T06:37:20.566Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/karan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-13T05:44:15.000Z","updated_at":"2023-09-08T17:03:36.000Z","dependencies_parsed_at":"2022-08-27T09:51:34.939Z","dependency_job_id":null,"html_url":"https://github.com/karan/unit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/karan/unit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karan%2Funit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karan%2Funit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karan%2Funit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karan%2Funit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/karan","download_url":"https://codeload.github.com/karan/unit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karan%2Funit/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265586014,"owners_count":23792833,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T20:26:08.522Z","updated_at":"2025-07-17T08:38:53.832Z","avatar_url":"https://github.com/karan.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# unit\n\n![](https://raw.githubusercontent.com/karan/unit/master/_dna.jpg?token=ADHGIXpzysS9hkZ0sEW0XDuvDLHM8Tk3ks5WT3XPwA%3D%3D)\n\nA highly **modular**, **fast** API framework in Go backed by [martini](https://github.com/go-martini/martini), and distributed as a **Docker** container for easy installation and deployment.\n\n`unit` is designed to be a highly modular and extensible API. These modules or extensions are called *units* and live in `units/` folder. Each unit is part of the `package units`.\n\n`units` are independent modules that can do anything you want them to do. Imagine having one that can draw an image, another that saves an image to s3, and another that notifies users - all exposed through your own HTTP API.\n\nSimply drop your `units` in the `units/` directory, and restart (rebuild) the API. `unit` discovers and links the API, and **installs the necessary dependencies** automagically.\n\nTo get started, take a look the [installation](#installation) steps, and [units docs](#writing-units).\n\n## Contents\n\n- [Prerequisites](#prerequisites)\n- [Installation](#installation)\n- [Accessing the API](#accessing-the-api)\n- [Writing Units](#writing-units)\n  - [Examples](#examples)\n- [Benchmark](#benchmark)\n\n## Prerequisites\n\n- [Docker](https://docs.docker.com/installation/)\n- [Docker Compose](https://docs.docker.com/compose/install/)\n- [Docker Machine](https://docs.docker.com/machine/install-machine/) (Mac OS X)\n\n## Installation\n\n- `$ git clone git@github.com:karan/unit.git \u0026\u0026 cd unit/`\n- `$ docker-compose up`\n\n#### Mac \u0026 Docker Machine\n\nIf you're using Docker Machine, follow these instructions for installation:\n\n```bash\n# Provision the docker engine\n$ docker-machine create --driver virtualbox unit\n\n# Set the environment\n$ eval \"$(docker-machine env unit)\"\n\n# See the IP address of the host\n$ docker-machine ip unit\n\n# Start the container\n$ docker-compose up\n```\n\n## Accessing the API\n\nIf using Docker Machine, run `$ docker-machine ls` to find out the VM IP address.\n\nIf your IP is `192.168.99.100`, load `192.168.99.100:5000` in the browser of the computer running docker to access the API.\n\n## Writing units\n\nEvery unit must import at least these two:\n\n```go\nimport \"github.com/go-martini/martini\"\nimport \"./../unit\"\n```\n\nFor any third-party imports, mark them with the `//- unit-deps` comment so `unit` can discover them and install them for you.\n\nExample:\n\n```go\nimport (\n  \"github.com/go-martini/martini\"\n\n  \"./../unit\"\n\n  \"github.com/martini-contrib/render\" //- unit-dep\n)\n```\n\nThe only thing needed after that is to register at least one group of routes like so:\n\n```go\ng := unit.Group(func(router martini.Router) {\n\n  // Use martini like you would\n  router.Get(\"/1\", func() string {\n    return \"v2 - 1!\"\n  })\n\n  router.Get(\"/2\", func() string {\n    return \"v2 - 2!\"\n  })\n\n})\n\n// Register with the following path\ng.Register(\"/v2\")\n```\n\nThe routes will then be available at `host/v2/1` and `host/v2/2`.\n\nThe most beautiful thing here is that you use martini to setup the routes like you normally would. You have full access to all features of martini - you can render a static page, or send JSON or send XML response. `unit` does not really care.\n\n#### Example\n\n[`units/plugin1.go`](https://github.com/karan/unit/blob/master/units/plugin1.go)\n```go\npackage units\n\nimport (\n  \"github.com/go-martini/martini\"\n\n  \"./../unit\"\n)\n\nfunc init() {\n  g := unit.Group(func(router martini.Router) {\n\n    router.Get(\"/1\", func() string {\n      return \"v2 - 1!\"\n    })\n\n    router.Get(\"/2\", func() string {\n      return \"v2 - 2!\"\n    })\n\n  })\n\n  g.Register(\"/v2\")\n}\n\n```\n\n## Benchmark\n\n`unit` is fast as a cheetah.\n\n```bash\n$ ab -n 1000 -c 20 http://192.168.99.100:5000/v1/1\nThis is ApacheBench, Version 2.3 \u003c$Revision: 1663405 $\u003e\nCopyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/\nLicensed to The Apache Software Foundation, http://www.apache.org/\n\nBenchmarking 192.168.99.100 (be patient)\nCompleted 100 requests\nCompleted 200 requests\nCompleted 300 requests\nCompleted 400 requests\nCompleted 500 requests\nCompleted 600 requests\nCompleted 700 requests\nCompleted 800 requests\nCompleted 900 requests\nCompleted 1000 requests\nFinished 1000 requests\n\n\nServer Software:\nServer Hostname:        192.168.99.100\nServer Port:            5000\n\nDocument Path:          /v1/1\nDocument Length:        7 bytes\n\nConcurrency Level:      20\nTime taken for tests:   2.450 seconds\nComplete requests:      1000\nFailed requests:        0\nTotal transferred:      123000 bytes\nHTML transferred:       7000 bytes\nRequests per second:    408.15 [#/sec] (mean)\nTime per request:       49.002 [ms] (mean)\nTime per request:       2.450 [ms] (mean, across all concurrent requests)\nTransfer rate:          49.03 [Kbytes/sec] received\n\nConnection Times (ms)\n              min  mean[+/-sd] median   max\nConnect:        0    4  63.8      0    1167\nProcessing:     4   45  19.0     40     166\nWaiting:        3   42  17.9     39     164\nTotal:          4   49  66.2     41    1213\n\nPercentage of the requests served within a certain time (ms)\n  50%     41\n  66%     47\n  75%     53\n  80%     59\n  90%     71\n  95%     82\n  98%     97\n  99%    113\n 100%   1213 (longest request)\n```\n\n*Inspired by the slower, much less user-friendly [modapi](https://github.com/csu/modapi)*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaran%2Funit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkaran%2Funit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaran%2Funit/lists"}