This repository has been archived by the owner on May 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc.go
48 lines (40 loc) · 1.52 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* doc.go
*
* Copyright (c) 2017-2019 Forest Hoffman. All Rights Reserved.
* License: MIT License (see the included LICENSE file) or download at
* https://raw.githubusercontent.com/foresthoffman/localize/master/LICENSE
*/
/*
Package localize provides functions for translating Golang data
structures to JavaScript primitives. The translated, or
"localized", JavaScript that can be produced by this package is
intended to be used directly with the html/template package.
This package eases the process of passing global data down to
front-end scripts.
Here's a simple example of the syntax:
import(
"github.com/foresthoffman/localize"
)
func main() {
// Generates a new localization map with the provided data.
dataMap, err := localize.NewMap(
// This will tell the localizer to assign the data to
// the "_localData" global JavaScript variable.
"_localData",
localize.Data{
"motd": "Hello world, welcome to a new day!",
// "nonce" will hold an object with an element with
// the key, "login", and the value,
// "LaKJIIjIOUhjbKHdBJHGkhg"
"nonce": map[string]string{
"login": "LaKJIIjIOUhjbKHdBJHGkhg",
},
},
)
// ...proper error handling, data manipulation, etc.
}
For a more complex example using the standard html/template and
net/http packages check the test/template.go file.
*/
package localize