Table of Contents
This is the simple fullstack project using Go,Python,SQL,HTML,CSS and Javascript.
User can query dates to get & save json data, aslo leaflet maps.
Functions of the project 😄
- Generating fake geo-data in json format --> Python
- Store geo-data in sql table --> Go, PostgreSQL
- Lightweight HTTP Server --> Go
- Interactive Web Page --> HTML,CSS and Javascript
- Language Version
Python >= 3.7 Go >= 1.12 (using go mod)
- Package
pq : Go PostgreSQL Driver
go get github.com/lib/pq
Git clone the project or download the whole ZIP file.
- Git
git clone https://github.com/GMfatcat/GO_Restful_api.git
- Download the zip file with the bellow instruction
1. Click <Code> (green button) 2. Download ZIP
Architecture:
- Frontend (User + Homepage + Result page)
- Backend (HTTP Server + SQL Server + File Server)
- Data Provider (Generate json data)
- Middleware Logger (save as "log.txt")
Data Provider:
- Argparse script for generating data, see arguments info below
Run whitout arguments
python generate_data.py
Run with arguments
usage: generate_data.py [-h] [--max_position MAX_POSITION] [--max_num MAX_NUM] [--days DAYS] [--start_date START_DATE]
options:
-h, --help show this help message and exit
--max_position MAX_POSITION Maximum number of positions to generate.
--max_num MAX_NUM Maximum number of objects to generate.
--days DAYS Number of days between to generate.
--start_date START_DATE Start date in the format YYYY-MM-DD.
Example: python generate_data.py --max_position 30 --max_num 30 --days 20 --start_date 2023-01-05
- Modify coordinates range if necessary
edit in generate_data.py line 24 & 25
- Run the script without any arguments is fine but those data has already been generated in "./data" folder
- Save json in "./data"
Backend Usage:
- Configure your PostgreSQL database user / dbname / password in "./action/connector/Connector.go"
- Add json data to SQL database
// change the *addNewData* to true in add_data.go, default to be false go run add_data.go
- Query dates for sql data
// v1 & v2 differences see test_backend.go go run test_backend.go
- Test Communication between frontend and backend
// After start the server , Open browser, type "http://localhost:8080" in url section. go run test_frontend.go
- Run Http Server - Must run before ANY Frontend Usage!!!
// After start the server , Open browser, type "http://localhost:9487" in url section. go run server.go
Server Log example after Server started
Frontend Usage (example video):
- Connect to Homepage
Open browser, type "http://localhost:9487" in url section. You can change the port in "server.go"
- Query dates for json data (Date format:XXXX-XX-XX)
Available Name same as the filename in ./data Current Available : <2022-01-01> to <2022-01-30>
- Auto-display json data (if data exists)
- Save json & Generate Leaflet map by button
I am trying to combine this project with my another geohash project.
That project can use geohash to find several groups of what3words.
Combination will be in the develop
branch.
- Data Generator
- SQL Server for Data
- Go HTTP Server
- Backend Functions
- JSON to SQL Server
- Query SQL TABLE
- Middleware Logger
- Update / Delete TABLE
- TBD
- Frontend Functions
- Webpage
- Query data
- Save JSON data
- Interactive Map (Leaflet)
- Direct "curl / get" to access data
- TBD
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch
- Commit your Changes
- Push to the Branch
- Open a Pull Request
Distributed under the MIT License. See LICENSE.txt
for more information.
GMfatcat : github
I've included all of free resources to kick things off!