package main
import (
"fmt"
"regexp"
"strings"
)
func main() {
var data string = `<if> {{t}} </if> {{s}}
<if> {{gg}} </if>`
var replace = map[string]string{
"t": "te",
"s": "ss",
"gg": "гг",
}
for key, value := range replace {
data = strings.Replace(data, "{{"+key+"}}", value, 2)
}
re := regexp.MustCompile("<if>(.*?)</if>")
if_array := re.FindAllString(data, -1)
fmt.Println(if_array[0] + "\n")
fmt.Println(if_array[1] + "\n")
}
var ifs = html.match(/<if>(.*?)<\/if>/g);
ifs.forEach(function(item) {
var logik = item.match(/<logik>(.*?)<\/logik>/g);
logik = logik[0];
logik = logik.replace('<logik>','');
logik = logik.replace('</logik>','');
var block_if = item.match(/<\/logik>(.*?)<else>/g);
block_if = block_if[0];
block_if = block_if.replace('<\/logik>',' ');
block_if = block_if.replace('<else>',' ');
var block_else = item.match(/<else>(.*?)<\/if>/g);
block_else = block_else[0];
block_else = block_else.replace('<else>',' ');
block_else = block_else.replace('<\/if>',' ');
var inners;
eval("if("+logik+"){inners='"+block_if+"'}else{inners='"+block_else+"'}");
html = html.replace(new RegExp(item,"g"), inners)
});
<if><logik>{{.boll}} == true</logik>
<h1>заголовок</h1>
<else>
не заголовок
</if>
function start_server(packages,router){
var registrPackages = {};
for (var key in packages) {
registrPackages[key] = {};
ajax.open('GET', key, false);
ajax.send(null);
eval(ajax.responseText);
for (var keys in func) {
registrPackages[key][keys] = func[keys];
}
}
return registrPackages;
}
var registrPackages = {};
var router = {
"/" : "kontrollers.Index",
"/game" : "kontrollers.Game"
}
var packages = {
"/js/src/supports/supports_html5.js" : "html5"
}
registrPackages = start_server(packages,router);
function test(){
alert(registrPackages["/js/src/supports/supports_html5.js"]["WebRTC"]());
}
test();
var importerHandler = {};
importerHandler.ok = function(){
onSuccess();
}
importerHandler.err = function(err){
onError(err);
}
script.onerror = function() {
importerHandler.err("Ошибка при импорте пакета" + url);
};
script.onload = function() {
if(count == coutLoad){
importerHandler.ok();
}
};
imports([
"/js/kernel/json_p.js"
],
function (){
if (packages("init")){
init.test = function (){
alert("test");
}
init.testing = function (){
alert("testing");
}
init.test();
init.testing();
} else {
importerHandler.err("Пакет init уже создан");
}
},
function (err){
alert(err);
});
var registrImport = {};
registrImport["/js/kernel/importer/importer.js"] = 0;
function imports(arr){
arr.forEach(function(item) {
if (registrImport[item] == undefined){
registrImport[item] = 0;
loadJs(item);
} else {
console.info(item + " загружен ранее.");
}
});
}
function loadJs(url){
var script = document.createElement('script');
script.src = url;
script.onerror = function() {
console.warn("Ошибка при загрузке "+url);
};
script.onload = function() {
console.info(url+" успешно загружен");
};
document.head.appendChild(script);
}
My first name is {{ first_name }}. My last name is {{ last_name }}.
{'first_name': 'John', 'last_name': 'Doe'}
шаблон отрендерит:My first name is John. My last name is Doe.
{{ my_dict.key }}
{{ my_object.attribute }}
{{ my_list.0 }}
/users.Auth/
{
"login":"",
"email":"", //необязательно но я использую
"pass":""
}
rb := make([]byte, 64)
_, err := rand.Read(rb)
if err != nil {
log.Print(err)
}
var token string = `{
"user_id":"",
"name":"",
...,
"salt": "`+base64.URLEncoding.EncodeToString(rb)+`",
"expiries":"", //время жизни токена
}`
encrypt_data := xxtea.Encrypt([]byte(token), []byte("Ваш ключ для шифровки токена"))
return base64.URLEncoding.EncodeToString(encrypt_data)