updated env variables to be from OS
This commit is contained in:
parent
147b79eceb
commit
fbfee0edaa
@ -5,12 +5,10 @@ import (
|
||||
)
|
||||
|
||||
func (app *application) home(writer http.ResponseWriter, request *http.Request) {
|
||||
baseURI := request.Host
|
||||
|
||||
data := templateData{
|
||||
AppLinks: getAppLinks(app.tier, baseURI),
|
||||
AppLinks: getAppLinks(app.tier, app.host),
|
||||
Tier: app.tier,
|
||||
BaseUri: baseURI,
|
||||
BaseUri: app.host,
|
||||
}
|
||||
|
||||
app.render(writer, request, http.StatusOK, "home.tmpl.html", data)
|
||||
|
@ -5,24 +5,30 @@ import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
"flag"
|
||||
)
|
||||
|
||||
type application struct {
|
||||
logger *slog.Logger
|
||||
templateCache map[string]*template.Template
|
||||
tier string
|
||||
host string
|
||||
}
|
||||
|
||||
func main() {
|
||||
//Get env variables
|
||||
addr := flag.String("addr", ":8080", "HTTP network address")
|
||||
tier := flag.String("tier", "starter", "tier the core is on")
|
||||
flag.Parse()
|
||||
//Set up logger
|
||||
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
|
||||
AddSource: true,
|
||||
}))
|
||||
//Get env variables
|
||||
tier := os.Getenv("TIER")
|
||||
if len(tier) == 0 {
|
||||
tier = "starter"
|
||||
}
|
||||
host := os.Getenv("HOST")
|
||||
if len(host) == 0 {
|
||||
logger.Error("Must specify host name.")
|
||||
os.Exit(1)
|
||||
}
|
||||
//Set up template cache
|
||||
templateCache, err := newTemplateCache()
|
||||
if err != nil {
|
||||
@ -33,10 +39,11 @@ func main() {
|
||||
app := application {
|
||||
logger: logger,
|
||||
templateCache: templateCache,
|
||||
tier: *tier,
|
||||
tier: tier,
|
||||
host: host,
|
||||
}
|
||||
|
||||
err = http.ListenAndServe(*addr, app.routes())
|
||||
err = http.ListenAndServe(":8080", app.routes())
|
||||
logger.Error(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
Loading…
Reference in New Issue
Block a user