Skip to content

Commit

Permalink
feat: embed web content into binary
Browse files Browse the repository at this point in the history
Fixes #15
  • Loading branch information
danstis committed Nov 12, 2022
1 parent 4b24579 commit 1b66ac7
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cmd/go-read-burn/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"embed"
"fmt"
"log"
"net/http"
Expand All @@ -17,8 +18,13 @@ import (
"github.com/kelseyhightower/envconfig"
)

//go:embed all:views/*
var views embed.FS

//go:embed static/*
var static embed.FS

var (
dbPath = path.Join("..", "..", "db", "secrets.db")
db *bolt.DB
templates *template.Template
)
Expand Down Expand Up @@ -52,11 +58,11 @@ func main() {
r.HandleFunc("/", IndexHandler)
r.HandleFunc("/create", CreateHandler).Methods("POST")
r.HandleFunc("/get/{key}", SecretHandler)
s := http.StripPrefix("/static/", http.FileServer(http.Dir("./static/")))
s := http.StripPrefix("/static/", http.FileServer(http.FS(static)))
r.PathPrefix("/static/").Handler(s)
http.Handle("/", r)

templates = template.Must(template.ParseGlob("views/*.html"))
templates = template.Must(template.ParseFS(views, "views/*.html"))

srv := &http.Server{
Handler: r,
Expand Down

0 comments on commit 1b66ac7

Please sign in to comment.