Library architecture

Library architecture

This section covers the functionality of each generated sub level package. Each package can be replaced, as long as the new package has the required exported identifiers.

package types

This package contains your project’s data (struct) types. Abstracted gos data types are exported to this package as Go code.


API packages

The following packages are located in sub level package api.

package assets

This package has your project’s web and tmpl directory compiled to Go code. You can find more information about using the API here.

package exported

This package declares gos modules exported for use by your project. You can read more about modules here.

package globals

This package contains your project’s global variables, constants and enumerations.

package handlers

This package contains your project’s HTTP handlers.

Required functions:
// Adapter function to generate http.HandlerFunc, only required with
// projects in development mode.
func MakeHandler(fn func(http.ResponseWriter, *http.Request, opentracing.Span)) http.HandlerFunc

// Adapter function to generate http.HandlerFunc, only required with
// projects in production mode.
func MakeHandler(fn func(http.ResponseWriter, *http.Request)) http.HandlerFunc
package methods

This package contains your project’s functions.

package sessions

This package contains your sessions’ store.

Required exported variables:
var Store *"github.com/gorilla/sessions".CookieStore
package templates

This package contains code to render templates and log template errors.

Required variables:
var Prod bool

var templateCache  "github.com/cheikhshift/gos/web".TemplateCacheStore
var WebCache  "github.com/cheikhshift/gos/web".CacheStore

// map of custom template pipelines
var TemplateFuncStore "html/template".FuncMap
Required functions:
// Load a web page based on the path passed. 
// Path is relative to your web root.
func LoadPage(path string) (*"github.com/cheikhshift/gos/web".Page, error) 

// Render template as HTTP response.
// This function is only required with projects in development mode.
// span parameter will have the current request span.
func RenderTemplate(w http.ResponseWriter, p *"github.com/cheikhshift/gos/web".Page, span opentracing.Span)

// Render template as HTTP response.
// This function is only required with projects in production mode.
func RenderTemplate(w http.ResponseWriter, p *"github.com/cheikhshift/gos/web".Page)

// Inspect template using a relative path to project root.
// templatePath parameter specifies the relative path to resource
// within assets package.
// data parameter specifies the struct literal to use with template
// rendering
func DebugTemplatePath(templatePath string, data interface{})

// Inspect request and template string to log fault
func DebugTemplate(w http.ResponseWriter, r *http.Request, tmpl string)
package tracer

This package is used to setup a tracing server for your web server. Please make sure to use a Go routine to listen on any port.

Required functions:
// Setup and launch trace server.
func LoadTraceServer()