Code Monkey home page Code Monkey logo

hash-o-matic's Introduction

This is a playground. There are changes in different branches that include more idiomatic code.

Feel free to browse around. When I get time I do a little more. Some changes have not been merged because tests have not been updated.

A Go based hashing REST API server

What it does

The server accepts a form POST to http://localhost:8080/hash in the form of password=stringToHa$h. At this time the % character seems to be the only standard utf8 ASCII character not accepted, so avoid that one for now. When the POST comes in the server responds with an id (numeric) that can be used to retrieve the calculated hash. The hash is retrieved by using the id in a GET to http://localhost:8080/hash/{id}. The server responds to the POST immediately with the id, however system waits 5 seconds before actually generating the hash. Attempts to immediately retrieve the hash will not fail but will receive a 202 Accepted and a JSON body containing {"ErrorMessage":"hash string not ready"}. Meaning, "your request has been received. Further processing needs to be done to fulfill your request, come back later."

Running the server

Running hash-o-matic will log connections to STDOUT, so you will see the queries come in. Logging control is planned for a future update.

$> hash-o-matic
2018/01/06 16:25:00 Server listening on: :8080
2018/01/06 16:34:31 [::1]:54591 GET / curl/7.49.0
2018/01/06 16:34:45 [::1]:54592 GET /hash curl/7.49.0
2018/01/06 16:35:19 [::1]:54597 POST /hash curl/7.49.0
2018/01/06 16:35:33 [::1]:54598 POST /hash curl/7.49.0
2018/01/06 16:35:42 [::1]:54599 GET /hash/1 curl/7.49.0

You can use any tool you wish to send the POST and GET requests to the server, including curl.

$> curl -XPOST http://localhost:8080/hash -d 'password=angryMonkey' -H 'Content-Type: application/x-www-form-urlencoded'
{"HashId":1}
$> curl http://localhost:8080/hash/1
{"HashString":"ZEHhWB65gUlzdVwtDQArEyx+KVLzp/aTaRaPlBzYRIFj6vjFdqEb0Q5B8zVKCZ0vKbZPZklJz0Fd7su2A+gf7Q=="}

Stopping the server

Stopping the running hash-o-matic server can be done by simply entering ^C or by sending a PUT request to http://localhost:8080/shutdown. Either shutdown method will wait for any current sessions to complete before closing the connection and exiting.

^C method

$> hash-o-matic
2018/01/06 17:24:50 Server listening on: :8080
^C2018/01/06 17:24:53 Received signal interrupt; shutting down
2018/01/06 17:24:53 Stopping server
2018/01/06 17:24:53 Shutdown complete.
$>

PUT method Start server:

$> hash-o-matic
2018/01/06 17:25:40 Server listening on: :8080

Send PUT:

$> curl -XPUT http://localhost:8080/shutdown
shutting down...%
$>

Output by server:

2018/01/06 17:26:21 Received call to /shutdown, shutting down
2018/01/06 17:26:21 Stopping server
2018/01/06 17:26:21 Shutdown complete.
$>

Getting Started

Clone this repo git clone https://github.com/dbyington/hash-o-matic.git Then cd into hash-o-matic and run go get

Prerequisites

You will need Go (Golang)

Installing

Install Go Clone this repo workdir $> git clone https://github.com/dbyington/hash-o-matic.git Change into the hash-o-matic directory and run go install

workdir $> cd hash-o-matic
workdir\hash-o-matic $> go install

Or you can run the server with the go run command.

workdir\hash-o-matic $> go run hash-o-matic.go

Running the tests

To run the included tests run

hash-o-matic $> go test ./...

Deployment

I doubt you want to actually deploy this for anything, and I recommend you don't.

Built With

Contributing

Since this is more of a learning project for me I would appreciate any comments, updates, or fixes come to me as an issue with a description and a clue, rather than straight-up code. Thanks.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Don Byington - Initial work - Don

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

hash-o-matic's People

Contributors

dbyington avatar

Watchers

 avatar

hash-o-matic's Issues

Handle json input

Modify the /hash POST handler to decode a JSON package with '{"password":"foobar"}'.

Redirect /

Redirect a GET request on / to the GH repo.

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.