Skip to content

Latest commit

 

History

History
113 lines (72 loc) · 2.3 KB

README.md

File metadata and controls

113 lines (72 loc) · 2.3 KB

Gopher Library

Description

This is a Library Management system built in Golang using the mvc architecture. The website consists of two seperate panels for student and admin. The user can see the existing books in the library and can also search for a specific book.

The admin can additionally perform these tasks:

  • Add a book in the library

  • Issue a book to a student

  • Delete a book from library

  • Receive a book from a student

admin creds: admin:admin

Local setup (with docker)

(Tests and migrations won't work on this method)

To start run the following commands:

 cp config/example.env .env
 docker-compose build
 docker-compose  up 

To stop run this command:

  docker-compose down 

Local Setup (Without docker)

Go Project setup

  • Run the following commands in terminal:
  go mod tidy
  go mod vendor
  cp config/example.env .env

Change the contents on .env according to the requirements specified inside

Note: you need to have a same .env file inside the tests folder too for tests to work

Mysql Setup

  • Start your Mysql server and log into it, create a new database and then import the database from config/library_dump.sql using this command:
   mysql -u [username] -p [database_name] < library_dump.sql

Apache2 setup

  • Install apache2 if not installed already

  • Copy and paste the sample vhost file given in config/ to /etc/apache2/sites-available with the name go.gopherlibrary.local.config

  • Now run these commands in the terminal:

sudo a2enmod proxy proxy_http
sudo a2ensite go.gopherlibrary.local
sudo a2dissite 000-default.conf
  • add 127.0.0.1 go.gopherlibrary.local to /etc/hosts

Now finally, run these commands and the library website should be online at http://go.gopherlibrary.local:

sudo systemctl restart apache2
go run main.go

Version control

Migrate up

go run migrations/migrate.go up

Migrate down

go run migrations/migrate.go down

Create new migrations

  migrate create -ext sql -dir migrations/ -seq init_mg

In case of version error - fix manually sry

Testing

Unit test for adding book -

go test  -v ./tests/add_test.go