A web blog and personal homepage engine written in Go.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.6 KiB

package gophertype
import (
// Site is the master struct for the Gophertype server.
type Site struct {
n *negroni.Negroni
mux *mux.Router
// NewSite initializes the Site.
func NewSite(pubroot string) *Site {
// Initialize the settings.json inside the user root.
if err := settings.SetFilename(pubroot); err != nil {
site := &Site{}
n := negroni.New()
site.n = n
// Register blog global template functions.
responses.ExtraFuncs = template.FuncMap{
"BlogIndex": controllers.PartialBlogIndex,
"RenderComments": controllers.RenderComments,
"RenderCommentsRO": controllers.RenderCommentsRO,
"RenderComment": controllers.RenderComment,
"RenderCommentForm": controllers.RenderCommentForm,
return site
// UseDB specifies the database to use.
func (s *Site) UseDB(driver string, path string) error {
db, err := gorm.Open(driver, path)
if err != nil {
return err
console.Info("Using database driver '%s'", driver)
return nil
// ListenAndServe starts the HTTP service.
func (s *Site) ListenAndServe(addr string) error {
console.Info("Listening on %s", addr)
return http.ListenAndServe(addr, s.n)