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) {
|
func (app *application) home(writer http.ResponseWriter, request *http.Request) {
|
||||||
baseURI := request.Host
|
|
||||||
|
|
||||||
data := templateData{
|
data := templateData{
|
||||||
AppLinks: getAppLinks(app.tier, baseURI),
|
AppLinks: getAppLinks(app.tier, app.host),
|
||||||
Tier: app.tier,
|
Tier: app.tier,
|
||||||
BaseUri: baseURI,
|
BaseUri: app.host,
|
||||||
}
|
}
|
||||||
|
|
||||||
app.render(writer, request, http.StatusOK, "home.tmpl.html", data)
|
app.render(writer, request, http.StatusOK, "home.tmpl.html", data)
|
||||||
|
@ -5,24 +5,30 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"flag"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type application struct {
|
type application struct {
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
templateCache map[string]*template.Template
|
templateCache map[string]*template.Template
|
||||||
tier string
|
tier string
|
||||||
|
host string
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
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
|
//Set up logger
|
||||||
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
|
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
|
||||||
AddSource: true,
|
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
|
//Set up template cache
|
||||||
templateCache, err := newTemplateCache()
|
templateCache, err := newTemplateCache()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -33,10 +39,11 @@ func main() {
|
|||||||
app := application {
|
app := application {
|
||||||
logger: logger,
|
logger: logger,
|
||||||
templateCache: templateCache,
|
templateCache: templateCache,
|
||||||
tier: *tier,
|
tier: tier,
|
||||||
|
host: host,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = http.ListenAndServe(*addr, app.routes())
|
err = http.ListenAndServe(":8080", app.routes())
|
||||||
logger.Error(err.Error())
|
logger.Error(err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user