Skip to content

Instantly share code, notes, and snippets.

View simt2's full-sized avatar
🐔
magic is bad

Simon Tesar simt2

🐔
magic is bad
View GitHub Profile
@simt2
simt2 / main.go
Last active February 27, 2017 06:53
mesh-go-example main logic
func main() {
// Log into the Gentics Mesh backend to retrieve session cookie
MeshLogin(USERNAME, PASSWORD)
// Set up router handling incoming requests
router := mux.NewRouter()
router.HandleFunc("/", IndexHandler)
router.HandleFunc("/{path:.*}", PathHandler)
loggedRouter := handlers.LoggingHandler(os.Stdout, router)
@simt2
simt2 / templateData.go
Created February 21, 2017 08:11
mesh-go-example templateData
// templateData is the struct that we pass to our HTML templates, containing
// necessary data to render pages
type templateData struct {
Breadcrumb []gjson.Result
Category *gjson.Result
Products *[]gjson.Result
}
// LoadBreadcrumb retrieves the top level nodes used to display the navigation
func LoadBreadcrumb() []gjson.Result {
r := MeshGetRequest("demo/navroot/?maxDepth=1&resolveLinks=short")
defer r.Body.Close()
bytes, _ := ioutil.ReadAll(r.Body)
json := gjson.ParseBytes(bytes).Get("root.children").Array()
return json
}
@simt2
simt2 / base.html
Created February 21, 2017 08:13
mesh-go-example base.html
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css">
<meta charset="UTF-8">
<title>Gentics Mesh Demo</title>
<style>
.row.products > div {
height: 500px
}
@simt2
simt2 / navigation.html
Created February 21, 2017 08:14
mesh-go-example navigation.html
{{define "navigation"}}
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a href="/" class="navbar-brand">Home</a>
</div>
<ul class="nav navbar-nav">
{{range $node := .Breadcrumb}}
@simt2
simt2 / welcome.html
Created February 21, 2017 08:14
mesh-go-example welcome.html
{{define "content"}}
<div class="jumbotron">
<div class="row">
<div class="col-sm-3 text-right">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg" style="max-width: 150px;" viewBox="0 0 500.000000 579.000000" preserveAspectRatio="xMidYMid meet">
<g transform="translate(0.000000,579.000000) scale(0.100000,-0.100000)" fill="#00a0d2" stroke="none">
<path class="gtx-logo-main" d="M2417 5780 c-21 -6 -52 -17 -70 -26 -24 -13 -2014 -1184 -2183 -1285 -43 -26 -108 -98 -136 -151 l-23 -43 -3 -1362 -2 -1362 21 -56 c44 -119 20 -102 1213 -805 598 -353 1109 -652 1135 -663 65 -30 197 -30 262 0 34 15 1874 1096 2205 1294 43 26 108 98 136 151 l23 43 3 1362 c2 1355 2 1362 -18 1417 -61 163 -257 260 -425 211 -41 -12 -278 -145 -765 -432 -774 -455 -786 -463 -829 -578 -28 -75 -28 -184 0 -260 27 -72 104 -156 176 -191 75 -37 185 -44 263 -17 30 10 240 127 466 261 227 133 414 242 418 242 3 0 5 -383 4 -851 l-3 -851 -888 -524 c-488 -288 -892 -524 -897 -524 -5 0 -409 236 -897 524 l-888 524 0 1067
@simt2
simt2 / productDetail.html
Created February 21, 2017 08:15
mesh-go-example productDetail.html
{{define "content"}}
{{with $product := index .Products 0}}
<div>
<h1>{{ $product.Get "fields.name" }}</h1>
<div class="row">
<div class="col-md-6">
<form name="productForm">
@simt2
simt2 / productList.html
Created February 21, 2017 08:16
mesh-go-example productList.html
{{define "content"}}
<div>
<h1>{{ .Category.Get "fields.name" }}</h1>
<div class="row products">
{{range $product := .Products}}
<div class="col-xs-12 col-sm-6 col-md-4">
<div class="panel panel-default">
<div class="panel-body">
<h3>
@simt2
simt2 / LoadChildren.go
Created February 21, 2017 08:16
mesh-go-example LoadChildren.go
// LoadChildren takes a nodes uuid and returns its children.
func LoadChildren(uuid string) *[]gjson.Result {
r := MeshGetRequest("demo/nodes/" + uuid + "/children?expandAll=true&resolveLinks=short")
defer r.Body.Close()
bytes, _ := ioutil.ReadAll(r.Body)
json := gjson.ParseBytes(bytes).Get("data").Array()
return &json
}
@simt2
simt2 / SessionCookie.go
Created February 21, 2017 08:17
mesh-go-example SessionCookie.go
// MeshLogin logs into the mesh backend and sets the session id
func MeshLogin(username string, password string) {
body := map[string]string{
"username": USERNAME,
"password": PASSWORD,
}
payload, _ := json.Marshal(body)
r, _ := http.Post(BASEURL+"auth/login", "application/json", bytes.NewBuffer(payload))
for _, cookie := range r.Cookies() {
if cookie.Name == "mesh.session" {