github.com/blend/go-sdk@v1.20220411.3/examples/web/views/main.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package main
     9  
    10  import (
    11  	"os"
    12  
    13  	"github.com/blend/go-sdk/graceful"
    14  	"github.com/blend/go-sdk/logger"
    15  	"github.com/blend/go-sdk/web"
    16  )
    17  
    18  func main() {
    19  	app := web.MustNew(web.OptLog(logger.All()))
    20  	app.Views.AddPaths(
    21  		"_views/header.html",
    22  		"_views/footer.html",
    23  		"_views/index.html",
    24  	)
    25  
    26  	app.Views.FuncMap["foo"] = func() string {
    27  		return "hello!"
    28  	}
    29  
    30  	if len(os.Getenv("LIVE_RELOAD")) > 0 {
    31  		app.Views.LiveReload = true
    32  	}
    33  
    34  	app.GET("/", func(r *web.Ctx) web.Result {
    35  		return r.Views.View("index", nil)
    36  	})
    37  
    38  	if err := graceful.Shutdown(app); err != nil {
    39  		app.Log.Fatal(err)
    40  		os.Exit(1)
    41  	}
    42  }