itpg

package module
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: GPL-3.0 Imports: 26 Imported by: 0

README

Is This Professor Good ? - Backend (itpg-backend)

Go Reference

Backend server for itpg, which is a platform where students can grade their professors after taking courses. This permits future students to make more informed decisions when choosing their courses. This repository handles http requests, database transactions, and user state management.

Installation

Go install

$ go install github.com/vanillaiice/itpg/cmd/itpg@latest

Docker

$ docker pull vanillaiice/itpg:latest

Usage

NAME:
   itpg-backend - Backend server for ITPG, handles database transactions and user state management through HTTP(S) requests.

USAGE:
   itpg-backend [global options] command [command options]

VERSION:
   v0.4.4

AUTHOR:
   vanillaiice <vanillaiice1@proton.me>

COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --port PORT, -p PORT                                                               listen on PORT (default: "443")
   --db-backend value, -b value                                                       database backend, either sqlite or postgres (default: "sqlite")
   --db URL, -d URL                                                                   database connection URL (default: "itpg.db")
   --users-db value, -u value                                                         user state management bolt database (default: "users.db")
   --log-level value, -g value                                                        log level (default: "info")
   --cookie-timeout value, -i value                                                   cookie timeout in minutes (default: 30)
   --env FILE, -e FILE                                                                load SMTP configuration from FILE (default: ".env")
   --pass-reset-url URL, -r URL                                                       password reset web page URL
   --allowed-origins value, -o value [ --allowed-origins value, -o value ]            only allow specified origins to access resources (default: "*")
   --allowed-mail-domains value, -m value [ --allowed-mail-domains value, -m value ]  only allow specified mail domains to register (default: "*")
   --smtp, -s                                                                         use SMTP instead of SMTPS (default: false)
   --http, -t                                                                         use HTTP instead of HTTPS (default: false)
   --cert-file FILE, -c FILE                                                          load SSL certificate file from FILE
   --key-file FILE, -k FILE                                                           laod SSL secret key from FILE
   --handler-config FILE, -n FILE                                                     load JSON handler config from FILE (default: "handlers.json")
   --load FILE, -l FILE                                                               load TOML config from FILE
   --help, -h                                                                         show help
   --version, -v                                                                      print the version

Examples

Using Go

If itpg was installed using go install, you can simply run it from the command line.

However, there should be an .env file containing the SMTP credentials needed to send confirmation emails.

# run the server with HTTP and pass an env file
$ itpg -t -e .smtp-env

# run the server with a TOML config file
$ itpg -l config.toml

Using Docker

# run the server with HTTPS and pass a TOML config file
$ ls itpg-data
# output: server.crt cert.key config.toml
$ docker run --rm -v ${PWD}/itpg-data:/itpg-data vanillaiice/itpg --load itpg-data/config.toml

Author

vanillaiice

Licence

GPLv3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DummyMiddleware

func DummyMiddleware(next http.HandlerFunc) http.HandlerFunc

DummyMiddleware is middleware that does nothing. It is used to wrap the go-chi/httprate limiter around a handler

func Run

func Run(cfg *RunConfig) (err error)

Run starts the HTTP server on the specified port and connects to the specified database.

Types

type Credentials

type Credentials struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

Credentials represents the user credentials.

type CredentialsChange

type CredentialsChange struct {
	OldPassword string `json:"old"`
	NewPassword string `json:"new"`
}

CredentialsChange represents the user credentials for changing passwords.

type CredentialsReset

type CredentialsReset struct {
	Code     string `json:"code"`
	Email    string `json:"email"`
	Password string `json:"password"`
}

CredentialsReset represents the user credentials for resetting password.

type DatabaseBackend

type DatabaseBackend string

DatabaseBackend is the type of database backend to use.

type GradeData

type GradeData struct {
	CourseCode      string  `json:"code"`
	ProfUUID        string  `json:"uuid"`
	GradeTeaching   float32 `json:"teaching"`
	GradeCoursework float32 `json:"coursework"`
	GradeLearning   float32 `json:"learning"`
}

GradeData contains data needed to grade a course.

type Handler added in v0.4.4

type Handler struct {
	Handlers []struct {
		Path     string `json:"path"`
		PathType string `json:"pathType"`
		Handler  string `json:"handler"`
		Limiter  string `json:"limiter"`
		Method   string `json:"method"`
	} `json:"handlers"`
}

Handler holds data for a handler.

type HandlerInfo

type HandlerInfo struct {
	Path     string                                   // Path specifies the URL pattern for which the handler is responsible.
	Handler  func(http.ResponseWriter, *http.Request) // Handler is the function that will be called to handle HTTP requests.
	Method   string                                   // Method specifies the HTTP method associated with the handler.
	PathType PathType                                 // PathType is the type of the path (admin, user, public).
	// contains filtered or unexported fields
}

HandlerInfo represents a struct containing information about an HTTP handler.

type LogLevel added in v0.4.2

type LogLevel string

LogLevel is the log level to use.

type PathType

type PathType int

PathType is the type of the path (admin, user, public).

type RunConfig

type RunConfig struct {
	Port                    string          // Port on which the server will run.
	DbURL                   string          // Path to the SQLite database file.
	DbBackend               DatabaseBackend // Database backend type.
	LogLevel                LogLevel        // Log level.
	UsersDBPath             string          // Path to the users BOLT database file.
	SMTPEnvPath             string          // Path to the .env file containing SMTP cfguration.
	PasswordResetWebsiteURL string          // URL to the password reset website page.
	AllowedOrigins          []string        // List of allowed origins for CORS.
	AllowedMailDomains      []string        // List of allowed mail domains for registering with the service.
	UseSMTP                 bool            // Whether to use SMTP (false for SMTPS).
	UseHTTP                 bool            // Whether to use HTTP (false for HTTPS).
	CertFilePath            string          // Path to the certificate file (required for HTTPS).
	KeyFilePath             string          // Path to the key file (required for HTTPS).
	CookieTimeout           int             // Duration in minute after which a session cookie expires.
	HandlerCfg              string          // Handler config json file.
}

RunConfig defines the server's confiuration.

Directories

Path Synopsis
cmd
db

Jump to

Keyboard shortcuts

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