You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Victor 2eb07de25e
Merge pull request #5 from NULLx76/fix/ci-image-branch
1 year ago
deployment Add redis support 1 year ago
store Fix typo in store.go 1 year ago
.dockerignore Added dockerfile 1 year ago
.drone.yml Updated Drone CI 1 year ago
.gitignore Added disk storage 1 year ago
Dockerfile changed env var to SOURCE_COMMIT for hopefully docker build intergration 1 year ago
LICENSE Add 'LICENSE' 1 year ago
README.md Add Go Report Card 1 year ago
config.go Added e2e tests 1 year ago
go.mod Added badger support 1 year ago
go.sum Add patch method instead of put 'fuck backward compatibility - Victor' 1 year ago
main.go Add patch method instead of put 'fuck backward compatibility - Victor' 1 year ago
main_test.go Add patch method instead of put 'fuck backward compatibility - Victor' 1 year ago
routes.go Add patch method instead of put 'fuck backward compatibility - Victor' 1 year ago
routes_test.go Add patch method instead of put 'fuck backward compatibility - Victor' 1 year ago

README.md

Counter

Drone (self-hosted) Docker Image Size (latest by date) Codecov MIT License Go Report

Simple Go app for keeping count.

Running

The easiest way of trying this out is by using the docker image 0x76/counter like so:

docker run -p 8080:8080 0x76/counter

Now you can follow the Usage section, be aware that running counter like this is non-persistent.

Usage

The basic idea is that each path represents a key or counter which can be interacted with in a RESTful way.

Here is an example:

# First create the counter
curl -X POST localhost:8080/some/path
> { "/some/path": 0, "AccessKey": "acf38625-bc7b-4241-97be-55d4f20219f6" }

# Now we can increment it using the returned access key 
#   (the header of the response will also contain the key)
curl -X PUT -H "Authorization: Bearer acf38625-bc7b-4241-97be-55d4f20219f6" localhost:8080/some/path
> { "/some/path": 1 }

# Query it using GET
curl -X GET localhost:8080/some/path
> { "/some/path": 1 }

# We can also delete a counter if we want
curl -X DELETE -H "Authorization: Bearer acf38625-bc7b-4241-97be-55d4f20219f6" localhost:8080/some/path

# Now if we query it we'll get a 404 back
curl -X GET localhost:8080/some/path
> Counter not yet created

Configuration

Environment variable table

key example values default value comment
DB memory, etcd, disk, redis or badger memory this selects which database to use
DBHOST etcd1:2379,etcd2:2379,etcd3:2379 UNSET address of database server(s) (if applicable)
DISKPATH /data, ./relative-data UNSET where to store database data (if applicable)
ADDRESS :8080, 127.0.0.1:4242 :8080 address for webserver to listen on