-
Notifications
You must be signed in to change notification settings - Fork 1
Template modules.
As of Gopher Sauce version 0.6.0
, you may import packages to your templates as modules. The module approach was implemented to give developers the possibility of isolating (encapsulating) code and choosing which packages are loaded (to manage performance, avoid declaration conflicts).
Package modules are generated from Gopher Sauce projects with deploy type set to package
. The package name set will be used to load your module within a template. Insert a new import tag within your project to add a package with template modules. The newly inserted tag must point to a GXML source file, Gopher Sauce will handle the rest.
You must export a Gopher Sauce project with type package. This is to export the code from GXML to Go code. Use command gos --export
to export a project, make sure your terminal's working directory is your project's.
Gopher Sauce does not support package modules with endpoint declarations or files within your package's web root.
Each module is loaded through a template pipeline. The pipeline will be named after the value set within your package's GXML tag : <package>${MODULE NAME}</package>
. This pipeline returns a struct literal from your module's package, this struct has your package's templates and declared pipelines as struct methods.
Exporting a function or template works the same way as in Go, prefix the name of your method or template with a capital letter.
To load a module, invoke the pipeline corresponding to the package name. Having a method name, local to your project, similar to the name of an imported package, will cause an error.
Try out the Package module
workshops to see modules in action :
-
e-Workshop 03 : Invoke a Go function, without GopherSauce abstractions as pipeline
-
Have a suggestion of what should be covered, send me an email at : cheikhhseck@gmail.com
- Your exported package methods must return a variable.
- Your package's GXML must have a package name set.
- Your templates' name should be capitalized to export it.
- Your package should include a readme with basic examples of template module.
- Your package should include unit tests.