Go-WebProject

go-webproject

Package gwp_module

Overview

import "gwp/gwp_module"

Package gwp_module gives API for writing 3rd party modules.

Modules can extend functionality in variety of ways:

* every module gets a chance to export its own custom parameters to global server.conf, which makes it perfect for integration of 3rd party Go packages, like database libs. See mod_sessions as an example of such a module.

* every module gets limited access to internal calls for managing runtime. API is exposed through this package.

* a module can register handlers, which can make it sort of sub-application that can be reused by many. mod_example provided, ilustrates this.

* a module can spawn goroutines for background tasks that are not request based.

Package files

doc.go gwp_module.go

func RegisterHandler

func RegisterHandler(ctx *gwp_context.Context, pattern string, handler func(http.ResponseWriter, *http.Request))

RegisterHandler can be called to register handlers directly from modules. It takes standard http's(or mux's) pattern and a HandlerFunc as arguments, along with a pointer to the global Context.

func RegisterModule

func RegisterModule(ctx *gwp_context.Context, m Module)

RegisterModule takes Module interface and registers the module within global Context. It calls *Module.ModInit() passing the ModContext, or nil if there as an error.

type ModContext

ModContext is passed back to module after registration

type ModContext struct {
    Name   string                 // module name
    Ctx    *gwp_context.Context   // pointer to global context
    Params *gwp_context.ModParams // parsed parameters
}

type Module

Module interface

type Module interface {
    ModInit(*ModContext, error)
    GetName() string
    GetParams() *gwp_context.ModParams
    SaveParams(gwp_context.ModParams)
}

Build version weekly.2011-12-14 10879+.