go-study

command module
v0.0.0-...-8fd06f2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2022 License: MIT Imports: 8 Imported by: 0

README

GO-STUDY REST API KEY VALUE CACHE AND MONGO FETCH DATA

This is a REST API with go for puting , getting key-value in-memory database and also getting data from mongo.

Get Data From In-Memory

Request
GET /in-memory?key=some key
curl --location --request GET 'http://localhost:8080/in-memory?key=test'
Response
{
    "key": "test",
    "value": "test"
}

Post Data to In-Memory

Request
POST /in-memory
curl --location --request POST 'http://localhost:8080/in-memory' \
--header 'Content-Type: application/json' \
--data-raw '{
    "key":"test",
    "value":"test value132"
}'
Response
{
    "key": "test",
    "value": "test value132"
}

Get Data From Mongo

Request
GET /records?startDate=some date&endDate=some date&minCount=some min count&maxCount=some max count
curl --location --request GET 'http://localhost:8080/records?startDate=2015-11-28&endDate=2015-12-29&minCount=30&maxCount=3000'
Response
{
    "code": 0,
    "msg": "Success",
    "records": [
        {
            "key": "KfqEhXyg",
            "createdAt": "2015-12-19T04:07:00.712Z",
            "totalCount": 46
        }
    ]
}

Dependencies

go version  go1.17.7

Project setup

cp(or copy) example.env .env
go mod download

Settings

You can set settings via .env file

Server Settings
PORT= #API working port
READ_TIMEOUT=#Read timeout in seconds
WRITE_TIMEOUT=#Write timeout in seconds
Database Settings
DATABASE_URI = #MONGO URI #example mongodb+srv://<username>:<password>@example.mongodb.net/myFirstDatabase?retryWrites=true&w=majority
DATABASE_NAME = #MONGO DATABASE NAME
Run API
go run main.go
Run with Docker
docker build -t go-study:latest .
docker run -p 8080:8080 go-study:latest
 ```

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
models
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL