armony

package module
v0.0.0-...-c1ba9ab Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2017 License: GPL-3.0 Imports: 10 Imported by: 0

README

armony

GPLv3 PRs Welcome GoDoc

Golang Web Framework for fast development

Install
go get "github.com/kidandcat/armony"
Example
package main

import (
	"fmt"
	"net/http"

	"github.com/kidandcat/armony"
)

func reparse(w *http.ResponseWriter, r *http.Request, ss *armony.Session) (string, interface{}) {
	fmt.Println("reparsing templates")

  // Reload Templates
	armony.ParseTemplates([]string{
		"views",
		"components",
	})

  // Set session variable
	ss.Set("username", "World")

  // Return nothing
	return "", nil
}

func index(w *http.ResponseWriter, r *http.Request, ss *armony.Session) (string, interface{}) {
  // Get sesion variable
	user := ss.Get("username")
  
  // Return commands and data
  // Render template "index" with data 
	return "template:index", armony.Data{
		"Username": user,
	}
}

func main() {
  // Load database for sessions
	armony.LoadDatabase()
  // Parse folders for templates (templates must end in .html)
	armony.ParseTemplates([]string{
		"views",
		"components",
	})
  // Add routes with handlers
	armony.AddRoute("/reloadTemplates", reparse)
	armony.AddRoute("/", index)

  // Let the Armony Handler handle all routes (or the ones you want)
	http.HandleFunc("/", armony.Handler)

  // Proceed like always
	server := http.Server{
		Addr: "127.0.0.1:80",
	}
	fmt.Println("Server listening in", "127.0.0.1:80")
	server.ListenAndServe()
}

Documentation

GoDoc

Contribute

Please send a GitHub Pull Request to armony with a clear list of what you've done (read more about pull requests). Please make sure all of your commits are atomic (one feature per commit).

Always write a clear log message for your commits.

Documentation

Overview

Package armony is a web framework for fast development, it's inspired by PHP/Symfony, NodeJS/FeathersJS and NodeJS/ExpressJS

Index

Constants

This section is empty.

Variables

View Source
var Routes routes

Routes : all routes

View Source
var Templates *template.Template

Templates : *template.Template

Functions

func AddRoute

func AddRoute(path string, controller Controller)

AddRoute : Adds a new route

func CloseDatabase

func CloseDatabase()

CloseDatabase : Gracefully closes the database

func Handler

func Handler(w http.ResponseWriter, r *http.Request)

Handler : Armony router handler

func LoadDatabase

func LoadDatabase() error

LoadDatabase : Load database in "database" Dir

func ParseTemplates

func ParseTemplates(templateFolders []string)

ParseTemplates : Parse templates from configured folders

func RandString

func RandString(n int) string

RandString generates a random string

func RemoveRoute

func RemoveRoute(path string, controller Controller)

RemoveRoute : Removes a new route

Types

type Controller

type Controller func(*http.ResponseWriter, *http.Request, *Session) (string, interface{})

Controller : A type representing a controller funcion

type Data

type Data map[string]string

Data : Represents a map of strings

type Session

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

Session Object representing a session

func LoadSession

func LoadSession(w *http.ResponseWriter, r *http.Request) Session

LoadSession look for a existing session || load a new one

func (*Session) Get

func (ss *Session) Get(key string) string

Get a value from the session

func (*Session) Set

func (ss *Session) Set(key string, value string)

Set a key:value pair in the session

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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