In this project we implement a web server (http-server) in order to filtered inputs. These inputs are some retangles with their coordinates. If their coordinates does not have intersection with the coordinates of domain, then they would be filtered. otherwise they will be saved in a Text
file.
This project is implemented in golang
.
Name: Saeedeh (Javaneh) Bahrami
Email: bahramisaeede@gmail.com
List of packages:
- "fmt"
- "errors"
- "os"
- "time"
- "net/http"
- "reflect"
- "io/ioutil"
- "io"
- "encoding/json"
- "log"
- "bufio"
- "github.com/mitchellh/mapstructure"
- "github.com/gorilla/mux"
the last 2 packages must be installed by these commands:
go get -u github.com/mitchellh/mapstructure
go get -u github.com/gorilla/mux
for running the model:
- first create a mod init file and select a name for your module cd to the project folder
cd Filtering_Project
go mod init http_server
- then compile the file
go build
- finally run the program using module name
./http_server
Note
: the http server will log automativally, all event and error handling during each request.
So user can see the log, after running ./http_server
.
In order to feed request data to the http server, plase use curl post
as below example:
curl -X POST -s localhost:8080 -d '{"main": {"x": 3, "y": 2, "width": 5, "height": 10},"input": [{"x": 4, "y": 10, "width": 1, "height": 1},{"x": 9, "y": 10,"width": 5, "height": 4}]}'
curl -X POST -s localhost:8080 -d '{"main": {"x":0, "y": 0, "width": 10, "height": 20},"input": [{"x":2, "y": 18, "width": 5, "height": 4},{"x":12, "y": 18, "width": 5, "height": 4},{"x":-1, "y": -1, "width": 5, "height": 4}]}'
in the above command, the domain coordinate nameed as "main"
.
the rest of coordinates are coordinates of input rectangles named "input"
Note
: we set localhost
as our endpoint.
Note
: we set 8080
port. one can change it to another free port.
In order to get the response of data from the http server, plase use curl get
as below exmaple:
curl -X GET -s localhost:8080
Note
: the output will represnet the list of rectangles which are saved in the Text file
.
output exmaple:
[
{"x":4,"y":10,"width":1,"height":1,"time":"2022-08-10 19:25:07"},
{"x":2,"y":18,"width":5,"height":4,"time":"2022-08-10 19:29:00"},
{"x":-1,"y":-1,"width":5,"height":4,"time":"2022-08-10 19:29:00"},
]