graf

package module
v0.0.0-...-06974e0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2013 License: BSD-3-Clause Imports: 29 Imported by: 0

README

GRAF

go get github.com/carbocation/go.graf

GRAF Recursively Arranged Forum is a golang toolkit that contains all of the necessary parts for building a live-updating threaded forum using golang and a database (currently, only postgres is explicitly supported). This is the source code for http://askgolang.com .

To get started, take a look at the "example" directory. This example assumes you are using OS X for development and Postgres as your database server. If so, you can create what is needed in Postgres with "example/forum.sql", and then you can compile the project from that path with ./compile.sh . (That will get you a dev.forum.osx to run locally and will also produce a prod.forum.linux, assuming that your actual server is a linux box. You can change this by modifying the contents of compile.sh .)

If you just want to see a live-loading websocked-based chat functionality, check out Go.Websocket-Chat, a library that is used in this project to provide comment live-loading.

The LICENSE specifies the terms; essentially, this project is licensed under an MIT-style license.

Please report any issues to me here on Github.

Documentation

Overview

Define exported config types so they can be overwritten.

Note that for things such as the Public config, an alternative strategy would be to pass the templates an interface{} so you can pack it with whatever fields you please.

Derived from zeebo's https://github.com/zeebo/gostbook/blob/master/template.go

Index

Constants

View Source
const (
	ThisUser = 0
)

Variables

View Source
var (
	Config *ConfigFile

	LogWriter      *log.Logger
	ErrorLogWriter *log.Logger
)

Functions

func AboutHandler

func AboutHandler(w http.ResponseWriter, r *http.Request) error

func CloseContext

func CloseContext(req *http.Request, buf http.ResponseWriter) (httpStatus int)

Anything that satisfies the http.ResponseWriter interface is sufficient

func DeleteContext

func DeleteContext(req *http.Request, w http.ResponseWriter)

func ErrorHTML

func ErrorHTML(w http.ResponseWriter, r *http.Request, errorTitle, errorMessage string, errorCode int, internalError error) error

Produce an HTML error page based on a title and a message, and return a desired error code. It is encouraged but not mandatory to use http.StatusXXX codes instead of raw integers for errorCode

func ForumHandler

func ForumHandler(w http.ResponseWriter, r *http.Request) (err error)

func IndexHandler

func IndexHandler(w http.ResponseWriter, r *http.Request) error

For now, the index is actually just a hardlink to the forum with ID #1

func Initialize

func Initialize(cfg *ConfigFile, d *sql.DB, s *sessions.FilesystemStore, r *mux.Router, de *schema.Decoder)

func LoginHandler

func LoginHandler(w http.ResponseWriter, r *http.Request) (err error)

func LogoutHandler

func LogoutHandler(w http.ResponseWriter, r *http.Request) error

func OpenContext

func OpenContext(req *http.Request)

func PostLoginHandler

func PostLoginHandler(w http.ResponseWriter, r *http.Request) error

func PostRegisterHandler

func PostRegisterHandler(w http.ResponseWriter, r *http.Request) error

func PostThreadHandler

func PostThreadHandler(w http.ResponseWriter, r *http.Request) error

func PostVoteHandler

func PostVoteHandler(w http.ResponseWriter, r *http.Request) error

func RegisterHandler

func RegisterHandler(w http.ResponseWriter, r *http.Request) (err error)

func T

func T(name string) *template.Template

Parse a template ('name') against _base.html

func ThreadHandler

func ThreadHandler(w http.ResponseWriter, r *http.Request) error

func ThreadRootHandler

func ThreadRootHandler(w http.ResponseWriter, r *http.Request) (err error)

Handles the specific URL /thread without any ID affixed to it

func ThreadWsHandler

func ThreadWsHandler(w http.ResponseWriter, req *http.Request)

func ValidUrl

func ValidUrl(u *url.URL) bool

We require all URLs to have a scheme (e.g., http) and a host (e.g., www.google.com)

Types

type ConfigApp

type ConfigApp struct {
	Identifier  string    //This distinguishes this app for logging and other purposes
	Environment string    //production, dev, ...
	LogAccess   io.Writer //Log every request
	LogError    io.Writer //Errors
	Port        string
	Secret      string
	RootForumID string //The numeric (but stringified) identifier for your root forum
}

App-level settings like HTTP ports and secret keys

type ConfigDB

type ConfigDB struct {
	User     string
	Password string
	DBName   string
	Port     string
	PoolSize int //Should be <= max_connections in /etc/postgresql/(version #)/main/postgresql.conf
}

DB connection config

type ConfigFile

type ConfigFile struct {
	App    *ConfigApp
	DB     *ConfigDB
	Public *ConfigPublic
}

A config file type is an object that nests various public and other config structures

type ConfigPublic

type ConfigPublic struct {
	Site         string //Site name
	Url          string //Full URL, e.g., http://www.google.com
	ContactEmail string //Webmaster email address
	GACode       string //Google Analytics Code
	GAUrl        string //URL of your site, according to Google Analytics
}

Public values that can be passed around into e.g., templates

type Handler

type Handler func(http.ResponseWriter, *http.Request) error

func (Handler) ServeHTTP

func (h Handler) ServeHTTP(w http.ResponseWriter, req *http.Request)

type ResponseLogger

type ResponseLogger struct {
	httpbuf.Buffer
	// contains filtered or unexported fields
}

Derived from https://github.com/gorilla/handlers/blob/master/handlers.go The main purpose here is to be able to pass around http.Status codes, which the net/http package does not natively enable.

func (ResponseLogger) Status

func (l ResponseLogger) Status() int

Get the current status code

func (*ResponseLogger) Write

func (l *ResponseLogger) Write(b []byte) (int, error)

Call Status before you call this

func (*ResponseLogger) WriteHeader

func (l *ResponseLogger) WriteHeader(s int)

Set a status code. ints are accepted, but http.StatusXXX is easier to read. Your choice.

Directories

Path Synopsis
Development (non-production) settings go here.
Development (non-production) settings go here.

Jump to

Keyboard shortcuts

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