https://github.com/braginantonev/gcalc-server
Go calculator server
https://github.com/braginantonev/gcalc-server
calculator go golang server
Last synced: 6 months ago
JSON representation
Go calculator server
- Host: GitHub
- URL: https://github.com/braginantonev/gcalc-server
- Owner: braginantonev
- Created: 2024-12-15T21:30:30.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-17T12:35:22.000Z (about 1 year ago)
- Last Synced: 2025-06-17T10:55:50.672Z (about 1 year ago)
- Topics: calculator, go, golang, server
- Language: Go
- Homepage:
- Size: 435 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# gcalc-server
A web service that accepts a complex expression in the form of JSON and returns the result. Available actions: +, -, *, /. And the precedence operators ().
## Installation
1. Install [Go](https://go.dev/doc/install)
2. Install [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
3. Clone repository: ```git clone https://github.com/braginantonev/gcalc-server```
## Usage
### Run Server
1. Go to installed repository
2. Install dependencies: ```go mod tidy```
3. Setup your server:
- Create ```.env``` file:
* For Linux: ```touch .env```
* For Windows: ```echo. > .env``` (P.S. У меня нет винды, простите если не сработает. Создайте файл другим образом)
- In ```.env``` write the following environments:
``` .env
PORT=8080
GRPCPort=5000
COMPUTING_POWER=5
JWTSecretSignature="your_super_secret_signature"
```
4. For run http server: ```go run cmd/main.go``` (For Windows use Git Bash or WSL).
* If you have error:
```
!!! Attention !!!
JWT signature in env JWTSecretSignature not found.
Please go to README.md - Usage, and follow the instruction!
```
Run server with next command: ``` PORT=8080 GRPCPort=5000 COMPUTING_POWER=5 JWTSecretSignature="your_super_secret_signature" go run cmd/main.go ```
5. To stop server use ```Ctrl+C```
### Available request (examples)
1. Registration (```localhost:/api/v1/register```):
* Curl: ```curl localhost:8080/api/v1/register -X POST --header 'Content-Type: application/json' --data '{"name": "Anton","password": "12345"}'```
* Postman: 
* In result you get ```JWT``` token. Use him for calculate and get expressions
2. Login (```localhost:/api/v1/login```):
* Curl: ```curl localhost:8080/api/v1/login -X POST --header 'Content-Type: application/json' --data '{"name": "Anton","password": "12345"}'```
* Postman: 
* In result you get ```JWT``` token. Use him for calculate and get expressions
3. Calculate (```localhost:/api/v1/calculate```):
* If you authorized (have ```JWT``` token):
- Curl: ```curl localhost:/api/v1/calculate -X POST -H 'Content-Type: application/json' -H "Authorization: " --data '<выражение>'```.
- Example: ```curl localhost:8080/api/v1/calculate -X POST -H 'Content-Type: application/json' -H "Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NDcwNzk3MDcsImlhdCI6MTc0Njk5MzMwNywibmFtZSI6IkFudG9uIiwibmJmIjoxNzQ2OTkzMzA3fQ.TgJoztS5R0neg_Am6fKTVoXNEexz53ev1g36rZvjqgg" --data '{"expression": "1+1"}'```
- Postman:  
* If you not authorized:
- Curl: ```curl localhost:/api/v1/calculate -X POST -H 'Content-Type: application/json' --data '<выражение>'```
- Example: ```curl localhost:8080/api/v1/calculate -X POST -H 'Content-Type: application/json' --data '{"expression": "1+1"}'```
- Postman: 
4. Get all your expressions (```localhost:/api/v1/expressions```):
* If you authorized (have ```JWT``` token):
- Curl: ```curl localhost:/api/v1/expressions -X GET -H "Authorization: "```
- Example: ```curl localhost:8080/api/v1/expressions -X GET -H "Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NDcwNzk3MDcsImlhdCI6MTc0Njk5MzMwNywibmFtZSI6IkFudG9uIiwibmJmIjoxNzQ2OTkzMzA3fQ.TgJoztS5R0neg_Am6fKTVoXNEexz53ev1g36rZvjqgg"```
- Postman: 
* If you not authorized:
- Curl: ```curl localhost:/api/v1/expressions -X GET```
- Example: ```curl localhost:8080/api/v1/expressions -X GET```
- Postman: 
5. Get expression (```localhost:/api/v1/expressions/```):
* If you authorized (have ```JWT``` token):
- Curl: ```curl localhost:/api/v1/expressions/ -X GET -H "Authorization: "```
- Example: ```curl localhost:8080/api/v1/expressions/0 -X GET -H "Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NDcwNzk3MDcsImlhdCI6MTc0Njk5MzMwNywibmFtZSI6IkFudG9uIiwibmJmIjoxNzQ2OTkzMzA3fQ.TgJoztS5R0neg_Am6fKTVoXNEexz53ev1g36rZvjqgg"```
- Postman: 
* If you not authorized:
- Curl: ```curl localhost:/api/v1/expressions/ -X GET```
- Example: ```curl localhost:8080/api/v1/expressions/0 -X GET```
- Postman: 
## Documentation
For documentation on the library, usage examples and possible errors, follow the link:
* [Русская](https://github.com/Antibrag/gcalc-server/blob/main/docs/ru/index.md)
* [English](https://github.com/Antibrag/gcalc-server/blob/main/docs/en/index.md)