github.com/servernoj/jade@v0.0.0-20231225191405-efec98d19db1/example/v1.0/jade_include/main.go (about)

     1  package main
     2  
     3  import (
     4  	"html/template"
     5  	"log"
     6  	"net/http"
     7  
     8  	"github.com/Joker/hpp"
     9  	"github.com/Joker/jade"
    10  )
    11  
    12  func handler(w http.ResponseWriter, r *http.Request) {
    13  	jade_tpl, err := jade.ParseFile("template.jade")
    14  	if err != nil {
    15  		log.Printf("\nParseFile error: %v", err)
    16  	}
    17  	log.Printf("%s\n\n", hpp.PrPrint(jade_tpl))
    18  
    19  	//
    20  
    21  	funcMap := template.FuncMap{
    22  		"bold": func(content string) (template.HTML, error) {
    23  			return template.HTML("<b>" + content + "</b>"), nil
    24  		},
    25  	}
    26  
    27  	//
    28  
    29  	go_tpl, err := template.New("html").Funcs(funcMap).Parse(jade_tpl)
    30  	if err != nil {
    31  		log.Printf("\nTemplate parse error: %v", err)
    32  	}
    33  
    34  	err = go_tpl.Execute(w, "")
    35  	if err != nil {
    36  		log.Printf("\nExecute error: %v", err)
    37  	}
    38  }
    39  
    40  func js(w http.ResponseWriter, r *http.Request) {}
    41  
    42  func main() {
    43  	log.Println("open  http://localhost:8080/")
    44  	http.HandleFunc("/javascripts/", js)
    45  	http.HandleFunc("/", handler)
    46  	http.ListenAndServe(":8080", nil)
    47  }