application-framework

command module
v0.0.0-...-373873a Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2015 License: GPL-3.0 Imports: 8 Imported by: 0

README

####application-framework

This project is a full modular web application framework. Useful when we want to put many specific tasks or services in one application with authentication.

The modularity is based on some go specific characteristics and modules are plugable at compile time.

Everithing but main.go is a module and have the same structure. You can add or remove any of mod_*.go file and program compile and run flawless (wow!).

Basically, application is a puzzle of modules linked after a rule to give a speed in developing applications.

Note that included modules do not some useful things but show some techniques to write real things and interact with framework and other modules.

[last-version-blue] (https://github.com/gophergala/application-framework/archive/master.zip)

8

How to use

Compile program. Se here (https://golang.org/doc/code.html) how.

Run and open http://localhost:8080 in your favorite browser (default user is george without password).

Back button is disabled in browser and is nice to run with Google Chrome in app mode

     google-chrome --app=http://localhost:8080

Note that using a HTML5 browser like Chrome you have automatic forms validation.

Tools used in this project

How it works

Basicaly, you have a module template (see mod_template.go) and a technique to plugin or plugout into main application.

init() function make go module plugable. Here we put only the web handler

     http.HandleFunc("/ModuleName", ModuleName)

handler structure

     func ModuleName(w http.ResponseWriter, r *http.Request) {
     	//this must add at begin of every session code
     	c, err := r.Cookie("session")
     	if err != nil || c.Value == "" {
     		http.Error(w, "Session expired", 401)
     		return
     	}
     
     	//build page content
     	b := `<pre> Page content`
     	
     	//finally show the page
     	p := Page{
     		Title:    "Module Title",
     		Status:   c.Value,		// e.g connected user
     		Body:     template.HTML(b),
     	}
     	t.ExecuteTemplate(w, "index.html", p)
     }

as you see the structure are fixed

  • cookie checker
  • build page content in b variable
  • show page with go template

Note that a simple cookie mecanism are used to implement sessions in modules (see mod_login.go). Also, module has access to a global logfile with

     log.Println("message")

Thats all folks about modules. Now, adding a menu line in templates/index.html file like

     <a href="/ModuleName" >ModuleName</a> 

make visible ModuleName to application. Remove this line and coresponding module,recompile application and module are removed. Nothing else to do.

Database used is sqlite (see https://github.com/mattn/go-sqlite3)

I used a nice preformatted text to make templates more readable (see templates/style.html)

Included modules

Minimal modules list (but compile even are removed too):

  • mod_login autenticate user,init session, set cookie, launch mod_index
  • mod_index make main page and show menus

For demo puposes i put some simple modules:

  • mod_checkUser show forms using,search a user in database
  • mod_showPersons show some persons informations from a database
  • mod_addPerson add a person into a database and call showPerson module
  • mod_ajax show integration of a simple ajax module who show a clock

Enjoy!

Documentation

Overview

this is a template module. do nothing. use to start your application.

Jump to

Keyboard shortcuts

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