Skip to content

Commit

Permalink
Merge pull request #1 from Mussabaheen/feat/use-go-embed
Browse files Browse the repository at this point in the history
feat: use go embedd for internal files
  • Loading branch information
Mussabaheen authored Mar 27, 2024
2 parents 25b262f + 426e71d commit 6acc8de
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package main

import (
"context"
"embed"
"encoding/json"
"flag"
"fmt"
"net/http"
"path"
"text/template"

"golang.design/x/clipboard"
Expand All @@ -19,6 +19,9 @@ var (
localPortUsage = "Specify the port number on which you want to serve the UI, by default 8080"
)

//go:embed internal/templates/*
var templates embed.FS

func main() {
// localPort represents the arg with flag -p
localPort := flag.String("port", "8080", localPortUsage)
Expand Down Expand Up @@ -60,8 +63,13 @@ func copyFromClipBoard(ch <-chan []byte) {
}

func ShowClipboard(w http.ResponseWriter, r *http.Request) {
fp := path.Join("internal/templates", "index.html")
tmpl, err := template.ParseFiles(fp)
indexHTML, err := templates.ReadFile("internal/templates/index.html")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

tmpl, err := template.New("index").Parse(string(indexHTML))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand Down

0 comments on commit 6acc8de

Please sign in to comment.