nusskylabx

command module
v0.0.0-...-baf4ea5 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2021 License: MIT Imports: 8 Imported by: 0

README

GoDoc CI Go Report Card Coverage Status

Setup Instructions

NOTE: The $ sign that comes before a line of code denotes the prompt, and should not be copied and pasted as part of the command.

Prequisites

  • You will need to install Docker, Go and Node.
    • Make sure you can run docker, go and npm from the command line.
    • For Windows users, use Powershell for the command line (instead of Command Prompt).
  • Install air (or modd) for automatically recompiling and running your server on changes.
  • Install an IDE or text editor of your choice. I recommend you use JetBrains's Goland IDE, which is free for students.

Create .env and .air.conf

  • Make a copy of .env.default as a new file called .env in project root directory.
    • You will have to fill in GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET. You can either use the nusskylab@gmail.com's google OAuth2 credentials or you can generate your own (next step).
  • Make a copy .air.conf.sample as a new file called .air.conf in project root directory.
    • You will only need to do this if you are using air. You can also use modd instead.
    • Windows Users: You will have to change all occurrences of 'main' to 'main.exe' inside .air.conf file (under 'cmd' and 'bin')

Get OAuth2 credentials

  • Obtain Google Oauth2 Client ID and Client Secret from here.
    http://localhost:8080/join/callback
    http://localhost:8080/login/callback
    
    • Update GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET in .env accordingly.

Setup the database

# Create and run the postgres container
$ docker-compose up -d

# Make sure the image exists on your computer
$ docker images # you should see a nusskylab2/postgres_plpgsql_check_pgtap image

# Make sure a container instance of the image is running.
# If you don't see it, run `docker-compose up -d` again.
$ docker container ls # you should see a nusskylab2/postgres_plpgsql_check_pgtap container

Start the application

# Load the sql views/functions/dummy data into the database.
$ go run cmd/loadsql/main.go

# Install npm packages
$ npm install

# Transpile the JavaScript files with webpack
$ npx webpack

# Finally make sure the program can run
$ go run main.go

# To avoid manually recompiling and running the server everytime you make a
# change, run the server with air or modd instead. Since you have already
# installed those programs, just run `air` or `modd` directly on the command line
# (without any arguments).

macOS Users: macOS imposes a 256 file limit which prevents air from starting (since we have more than 256 files). To get around it, temporarily increase the open file descriptor limit to 1024 with ulimit -n 1024 before running air again. You can also combine it into one command and run ulimit -n 1024; air instead.

Add yourself as an admin

Manually

You can add yourself as an admin manually by visiting the server, clicking on the 'Create User' button on the navbar and entering following line into the text box:

,admin,<YOUR_NAME>,<YOUR_NUSNET_EMAIL>

Notice that the cohort field (the first field) is left blank so that the current cohort will automatically be used. You can manually pass in the current cohort as well.

The downside of adding yourself manually is that you will have to re-add yourself again anytime you reset the database.

As part of the sql data loading pipeline

The other way (which is recommended over the first) is to add your user details into an sql data script that will be run as part of go run cmd/loadsql/main.go -clean or when you run go run cmd/loadsql/main.go for the first time.

  • Create a file called temp.sql inside the directory app/db/data/.
    • Any sql files starting with temp will be gitignored. You can put whatever developer specific data you want into this sql file without it being committed into the repository.
  • Add the following contents into temp.sql:
-- app/db/data/temp.sql
DO $$ BEGIN
    -- app.create_user_role is a plpgsql function that was added into the database
    -- by running `go run cmd/loadsql/main.go`. You can see its source code
    -- definition inside the file app/db/functions/create_user_role.sql.
    PERFORM app.create_user_role(NULL, 'admin', '<YOUR_NAME>', '<YOUR_NUSNET_EMAIL>');
END $$;
  • Do a clean database reset
$ go run cmd/loadsql/main.go -clean

You should now be able to login via NUS OpenID (the top right button on the navbar).

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
app
admins
Package admins implements the admin-facing pages on Skylab
Package admins implements the admin-facing pages on Skylab
advisers
Package advisers implements the adviser-facing pages on Skylab
Package advisers implements the adviser-facing pages on Skylab
applicants
Package applicants implements the applicant-facing pages on Skylab
Package applicants implements the applicant-facing pages on Skylab
db
mentors
Package mentors implements the mentor-facing pages on Skylab
Package mentors implements the mentor-facing pages on Skylab
skylab
Package app implements the Skylab website for Orbital
Package app implements the Skylab website for Orbital
students
Package students implements the student-facing pages on Skylab
Package students implements the student-facing pages on Skylab
cmd
examples
helpers
auth
Package auth provides various authentication related utilities
Package auth provides various authentication related utilities
auth/oauth
Package oauth is a wrapper around x/oauth2 to provide oauth2 authetication for various providers
Package oauth is a wrapper around x/oauth2 to provide oauth2 authetication for various providers
auth/openid
Package openid partially implements the OpenID 2.0 specification for the Relying Party (RP) in Stateless Mode
Package openid partially implements the OpenID 2.0 specification for the Relying Party (RP) in Stateless Mode
cookies
Package cookies provides cookie related utilities
Package cookies provides cookie related utilities
dbutil
Package dbutil provides database related utilities
Package dbutil provides database related utilities
erro
Package erro provides error handling related utilities
Package erro provides error handling related utilities
flash
Package flash provides flash message utilities
Package flash provides flash message utilities
formx
Package formx provides user-editable forms
Package formx provides user-editable forms
headers
Package headers provides utilities for setting various headers
Package headers provides utilities for setting various headers
logutil
Package logutil provides logging utilities
Package logutil provides logging utilities
mailutil
Package mailutil provides mail sending utilities
Package mailutil provides mail sending utilities
templateutil
Package templateutil provides various utility functions for golang templates
Package templateutil provides various utility functions for golang templates
testutil
Package testutil contains helper functions for writing tests
Package testutil contains helper functions for writing tests
timeutil
Package timeutil provides various time related utilities
Package timeutil provides various time related utilities
Code generated by 'sqgen-postgres functions'; DO NOT EDIT.
Code generated by 'sqgen-postgres functions'; DO NOT EDIT.

Jump to

Keyboard shortcuts

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