Skip to content

Commit

Permalink
Fixing the current directory to be able to find the template
Browse files Browse the repository at this point in the history
  • Loading branch information
Gepser Hoil committed Dec 5, 2022
1 parent f969077 commit b80f3b2
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"net/http"
"os"
"path"
"strconv"
"text/template"
Expand All @@ -25,6 +26,15 @@ var red = "#d9534f"
var yellow = "#f0ad4e"
var green = "#5cb85c"

const gcloudFuncSourceDir = "serverless_function_source_code"

func fixDir() {
fileInfo, err := os.Stat(gcloudFuncSourceDir)
if err == nil && fileInfo.IsDir() {
_ = os.Chdir(gcloudFuncSourceDir)
}
}

func pickColor(percentage int, successColor string, warningColor string, dangerColor string) string {
pickedColor := green
if successColor != "" {
Expand All @@ -49,6 +59,7 @@ func pickColor(percentage int, successColor string, warningColor string, dangerC
}

func init() {
fixDir()
functions.HTTP("Progress", Progress)
}

Expand All @@ -70,9 +81,8 @@ func Progress(w http.ResponseWriter, r *http.Request) {
PickedColor: pickColor(percentage, successColor, warningColor, dangerColor),
}

//To test it locally we should interchange these two paths
//tpl, err := template.ParseFiles("progress.html")
tpl, err := template.ParseFiles("src/progress/progress.html")
tpl, err := template.ParseFiles("progress.html")

if err != nil {
log.Fatalln(err)
}
Expand Down

0 comments on commit b80f3b2

Please sign in to comment.