Skip to content

From Scratch

This guide will include a basic project setup with just a basic index page, components and examples. For advanced setup with examples, check Example with Guide.

Entry Point

Firstly, we need to setup the serving foundations.

package main

import (

func main() {
    // Init serve mux
    mux := http.NewServeMux()

    // Routes
    // ...

    // Run
    if os.Getenv("PORT") == "" {
        log.Println("Listening on localhost:25025")
        http.ListenAndServe("localhost:25025", mux)
    } else {
        log.Println("Listening on" + os.Getenv("PORT"))
        http.ListenAndServe(":"+os.Getenv("PORT"), mux)


Now, we can define our page.

package main

import (

type PageIndex struct {}

func (p *PageIndex) Template() *template.Template {
    return template.Must(template.New("page.index.html").Funcs(kyoto.Funcs()).ParseGlob("*.html"))


You can define bootstrap functions for easier template definitions. For example:

func newtemplate(page string) *template.Template {
    return template.Must(template.New(page).Funcs(kyoto.Funcs()).ParseGlob("*.html"))

Page routing

For attaching your page, you can simply use the built-in page handler (kyoto.PageHandler), right below the Routes comment in your main function.

mux.HandleFunc("/", kyoto.PageHandler(&PageIndex{}))


Your can run your app with the usual:

go run .

For setting custom ports or exposing on a local network, you can run with the following:

PORT=25025 go run .
Back to top