Skip to content

diditaditya/lazer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lazer

Overview

This is mere a fun project of utter laziness. Essentially the app directly reads the mysql database table and it can then be requested through http. Nothing fancy. Just so the backend ready without writing any structs for each table, then go back lazing around wholeheartedly.

Development

Make sure docker and docker-compose are installed.

To start development, clone and navigate to the cloned folder.

$ git clone https://github.com/diditaditya/lazer
$ cd lazer

Create .env file with the following variables

DB=mysql
DB_HOST=mysql8
DB_USER=root
DB_PASSWORD=thedbpassword
DB_NAME=thedbname

Note that the DB_HOST is the mysql container name in the docker-compose.yml in this case mysql8. The DB_USER is root because nothing is set for the container. If you want to change it please check here which also contains other settings for the mysql container.

Start the docker

$ docker-compose up -d

This will create 2 containers, the go and the mysql.

In the mysql container, a database named the same as DB_NAME in .env file will be created. You can get inside the mysql container and create some tables.

$ docker exec -it mysql8 bash
$ mysql -p

Password will be asked, enter the one you set in DB_PASSWORD. And then you can start creating some tables.

The app will not automatically run. You must start it manually from inside the go container.

$ docker exec -it go bash
$ cd src/lazer
$ go run main.go

You can access the app from your browser or whatever at localhost:3500. If you want to change the port just change the docker-compose.yml which maps default gin port at 8080 to 3500. Or just experiment with traefik to access it from your localhost with subdomain, which is cool and helpful, so you don't need to care about clashing ports.

Features

Currently the features are developed really slowly. No test whatsoever, hence expect bugs, and when you find them please do fix them and create pull request 😃

The features are:

  1. Automatically creates routes based on tables in the database. If you go to your browser and hit the root, you'll get the list of the tables which can be used as the routes or paths. For example if you have tables named users and books, they can be accessed through http://localhost:3500/users and http://localhost:3500/books assuming default setting for host and port.
  2. The routes can filter the data by using querystring. For example if your books table has columns id, title, author, and year, you can filter the books by author like so http://localhost:3500/books?author=nobody or maybe the year also http://localhost:3500/books?author=nobody&year=2000. If you want multiple authors, use it like author=nobody&author=somebody. Please note this feature is still very basic and simplistic, manage your expectation.
  3. The routes can also be used to POST data to create new entry. For example if you want to add new book, POST to http://localhost:3500/books with JSON body like {"title": "abc", "author": 'me', "year": 1890}, which returns nothing 😆
  4. The PUT verb can be used as well to update an entry by using /:tablename/:primaykey route and body in JSON just like the aforementioned POST example.
  5. By using DELETE verb, you can delete entries from a table. The deletion will be bulk delete with parameters in the querystring almost similar to filter.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages