momentum

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

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

Go to latest
Published: Nov 3, 2018 License: BSD-3-Clause Imports: 23 Imported by: 0

README

[DEPRECATED]

Incompatible with Gopher Sauce +v0.6.0

Momentum

A GopherSauce package to convert template and func tags into accessible Javascript functions. The goal of this project is to be able to: 1) generate your templates on your server 2) Ease access to server side functionality.

Without GopherSauce

Download the CLI to build RPC functions without GopherSauce. Find it here

Requirements

How it works

Install

Add this import tag to the root of your gos.gxml file. Within the <gos> tag. This will activate momentum within your project. Remember to include the funcfactory within the pages you wish to use these functions. <script src="/funcfactory.js"></script>

<import src="github.com/cheikhshift/momentum/gos.gxml">
Templates

Each template created will have a JS function equivalent with the same name. The format of the generated functions are as follows :

function TemplateName(ObjectWithInterfaceFields, function callback(StringOfRenderedTemplate) {} )

Notes : Replace TemplateName with the string specified as the name attribute of your template tag. ObjectWithInterfaceFields is a JS object that will be converted to the interface specified within your template tag's struct attribute. On error, the reason why will be returned instead of the template HTML.

Funcs

Each func tag within your <methods> section will generate a JS equivalent function. To better visualize this follow the example below. Notes : Channels are not supported as a valid type within var and return attributes of your func tag. Using the term args ...interface will not work as well. This is why the <func> tag was introduced, to provide users with a tag to explicitly declare variable types. With this in mind <method> tags will not work with JS function factory because it relies args ..interface to pass variables.

A sample <func> tag is declared within the methods section of a gos.gxml file. The return type specifies names returned values.

 <func name="TestAdd" var="varx string,numv int" return="(test string, err error)">
	err = errors.New("error test on GOOOO")	
		test  = "Test" + varx
		return 
</func>

The previous func tag will generate JS function : (The variable definitions carry over to javascript.)

function TestAdd(Varx,Numv, function callback(ObjectResponse, success) )

Notes : ObjectResponse variable is an object with your function's returned values. With this <func> tag, the ObjectResponse will have keys err and test following the tag's return attribute. Success is an indication of successful method invocation. On error, Object response will have one key : error, which is a string explanation of why the request failed.

**More notes : You must specify the names of the return types as well, AKA Named returned values. These names will be used as key names to your response oject.

*** Angular notes : If you plan on using Angular JS, use this $scope function to update your data after setting it within your callback $scope.$apply();.

Api format

You can access each of your functions via server URI /momentum/funcs.

Get Parameters
  • name : specifies the name of the function to invoke.
Post Body

The body is used to pass a json of your function's variables/parameters. Each json key should match a correponding function variable name, with that variable's data specified as the key's value.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func Bang

func Bang(intstr interface{}) string

func Bjquery

func Bjquery(intstr interface{}) string

func Bserver

func Bserver(intstr interface{}) string

func BytesToString

func BytesToString(b []byte) string

func DebugTemplate

func DebugTemplate(w http.ResponseWriter, r *http.Request, tmpl string)

func DebugTemplatePath

func DebugTemplatePath(tmpl string, intrf interface{})

func FileServer

func FileServer() http.Handler

func GetLine

func GetLine(fname string, match string) int

func Handler

func Handler(w http.ResponseWriter, r *http.Request, contxt string, session *sessions.Session)

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func NetLoadWebAsset

func NetLoadWebAsset(args ...interface{}) string

func Netadd

func Netadd(x, v float64) float64

func Netang

func Netang(args ...interface{}) string

func Netbang

func Netbang(d NoStruct) string

func Netbjquery

func Netbjquery(d NoStruct) string

func Netbserver

func Netbserver(d NoStruct) string

func Netdivided

func Netdivided(x, v float64) float64

func Netimportcss

func Netimportcss(s string) string

func Netimportjs

func Netimportjs(s string) string

func Netjquery

func Netjquery(args ...interface{}) string

func Netmultiply

func Netmultiply(x, v float64) float64

func Netserver

func Netserver(args ...interface{}) string

func NetsessionDelete

func NetsessionDelete(s *sessions.Session) string

func NetsessionGet

func NetsessionGet(key string, s *sessions.Session) string

func NetsessionGetInt

func NetsessionGetInt(key string, s *sessions.Session) interface{}

func NetsessionKey

func NetsessionKey(key string, s *sessions.Session) bool

func NetsessionRemove

func NetsessionRemove(key string, s *sessions.Session) string

func NetsessionSet

func NetsessionSet(key string, value string, s *sessions.Session) string

func NetsessionSetInt

func NetsessionSetInt(key string, value interface{}, s *sessions.Session) string

func Netsubs

func Netsubs(x, v float64) float64

func ReadyTemplate

func ReadyTemplate(body []byte) string

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

func SetField

func SetField(obj interface{}, name string, value interface{}) error

func UrlAtZ

func UrlAtZ(url, base string) (isURL bool)

Types

type NoStruct

type NoStruct struct {
}

func Netcang

func Netcang(args ...interface{}) (d NoStruct)

func Netcjquery

func Netcjquery(args ...interface{}) (d NoStruct)

func Netcserver

func Netcserver(args ...interface{}) (d NoStruct)

type Page

type Page struct {
	Title string
	Body  []byte

	R       *http.Request
	Session *sessions.Session
	// contains filtered or unexported fields
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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