vbooks

package module
v0.0.0-...-44b14cd Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2019 License: BSD-3-Clause Imports: 7 Imported by: 0

README

vbooks

This is the backend server for the vbooks project - a place for small communities to share PDFs, ePubs, and other reading resources with each other.

Resources

Planning, feature requests, and bugs live at our issue tracker.

Send patches and questions to ~izzy/vbooks-dev@lists.sr.ht.

Building

Dependencies:

  • go (>=1.12)

    cd $REPO/cmd/vbooks-server && go build

(If using Go 1.12: Because the vbooks project is using go modules, the repository should be checked out in a location outside of GOPATH or compiled with GO111MODULE=on. This doesn't apply to Go >= 1.13.)

Live Reloading for Development

Live reload of the server while editing code can be accomplished with codegangsta/gin by running

gin --build cmd/vbooks-server

in the root of the repository.

Add --all to watch HTML templates, also.

Initializing the database

First, make sure you have postgresql installed. vbooks will attempt to connect to a database that's named after your user. You'd need to change the username in server.go, line 39.

Then, import the schema:

psql < $REPO/db/sql/schema.sql

Documentation

Index

Constants

View Source
const (
	MinUsernameLen = 3
	MinPasswordLen = 6
)

Minimum lengths for validation of user registration

View Source
const MinGroupNameLen = 3

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	// contains filtered or unexported fields
}

A Server handles routing and dependency injection into the routes. This is the main controller of the application: all "top level" handlers hang off of it.

If you want to add a route, look at Server.routes. Routes should be methods of the server type that return an http.HandlerFunc. In general, this should be an anonymous function. This design was done to:

  • Allow initialization to happen per route at definition time
  • Allow the handlers to close over the parts of the server they need access to.
  • Not require any "magic" to understand what's being called in response to a route.

Currently, we're just using the standard library http.ServeMux - we haven't needed any features of the more advanced routers. If we need those features, we'll cross that bridge when we come to it - we're not opposed to them.

In general, this package should be the only one that's aware of the http part of the app.

func NewServer

func NewServer(db db.Store) *Server

NewServer creates a Server backed by a backing database

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

Directories

Path Synopsis
cmd
Package db defines the requirements for our database, via the Store interface, and implements it for postgres.
Package db defines the requirements for our database, via the Store interface, and implements it for postgres.

Jump to

Keyboard shortcuts

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