wren-web

command module
v0.0.0-...-85a4184 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

README

wren-web

A web framework for Wren

installation

requirements: git & go 1.16+

$ git clone https://git.zvava.org/zvava/wren-web
$ cd wren-web
$ go get git.zvava.org/zvava/wren-web/cmd
$ go install

usage

index.wren

import "web" for Routes, App, Templates

Routes.GET("/") {
    return "hello"
}

Routes.GET("/param/*param") { | params |
    // /param/       → /
    // /param/hi     → /hi
    // /param/hi/lol → /hi/lol
    return params["param"]
}

Routes.GET("/add/:num1/:num2") { | params |
    var num1 = Num.fromString(params["num1"])
    var num2 = Num.fromString(params["num2"])

    return "%(num1) + %(num2) = %(num1 + num2)"
}

Routes.GET("/add/:num1/:num2/html") { | params |
    var num1 = Num.fromString(params["num1"])
    var num2 = Num.fromString(params["num2"])
    var res = num1 + num2

    return Templates.render("addition.html", {
        "num1": num1.toString,
        "num2": num2.toString,
        "result": r.toString
    })
}

App.run(3000)

addition.html

<!DOCTYPE html>
<html lang="en">
	<head><title>Addition</title></head>
	<body style="background: gray; color: pink;">{{num1}} + {{num2}} = {{result}}</body>
</html>

to start the application just run

$ wren-web start index.wren

in production

$ GIN_MODE=release wren-web start index.wren

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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