Very little factorize around "func runPath()"

This commit is contained in:
Bertrand Moreau 2020-08-21 20:05:11 +02:00
parent 9e69193739
commit ae6cbe97e1
3 changed files with 16 additions and 19 deletions

View File

@ -27,17 +27,20 @@ var chatTemplateDefs map[string]string = map[string]string{
`</span> <span class="cmdme">{{.Message}}</span></span>`, `</span> <span class="cmdme">{{.Message}}</span></span>`,
} }
func runPath() string {
ex, er := os.Executable()
if er != nil {
panic(er)
}
return filepath.Dir(ex)
}
// Called from the server // Called from the server
func InitTemplates() error { func InitTemplates() error {
isServer = true isServer = true
serverTemplates = make(map[string]*html.Template) serverTemplates = make(map[string]*html.Template)
chatTemplates = make(map[string]*text.Template) chatTemplates = make(map[string]*text.Template)
ex, er := os.Executable() var runPath string = runPath()
if er != nil {
panic(er)
}
runPath := filepath.Dir(ex)
fmt.Println(runPath)
// keys and files to load for that template // keys and files to load for that template
var serverTemplateDefs map[string][]string = map[string][]string{ var serverTemplateDefs map[string][]string = map[string][]string{

View File

@ -27,13 +27,16 @@ type EmoteInfo struct {
Code string Code string
} }
func loadEmotes() error { func runPath() string {
ex, er := os.Executable() ex, er := os.Executable()
if er != nil { if er != nil {
panic(er) panic(er)
} }
runPath := filepath.Dir(ex) return filepath.Dir(ex)
newEmotes, err := processEmoteDir(runPath + emoteDir) }
func loadEmotes() error {
newEmotes, err := processEmoteDir(runPath() + emoteDir)
if err != nil { if err != nil {
return err return err
} }
@ -92,7 +95,7 @@ func processEmoteDir(path string) (common.EmotesMap, error) {
func findEmotes(dir string, em common.EmotesMap) (common.EmotesMap, error) { func findEmotes(dir string, em common.EmotesMap) (common.EmotesMap, error) {
//em := NewEmotesMap() //em := NewEmotesMap()
fmt.Printf("finding emotes in %q\n", dir) //fmt.Printf("finding emotes in %q\n", dir)
emotePNGs, err := filepath.Glob(filepath.Join(dir, "*.png")) emotePNGs, err := filepath.Glob(filepath.Join(dir, "*.png"))
if err != nil { if err != nil {
return em, fmt.Errorf("unable to glob emote directory: %s\n", err) return em, fmt.Errorf("unable to glob emote directory: %s\n", err)

View File

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
"os"
"path" "path"
"path/filepath" "path/filepath"
"strings" "strings"
@ -45,14 +44,6 @@ func (self writeFlusher) Flush() error {
return nil return nil
} }
func runPath() string {
ex, er := os.Executable()
if er != nil {
panic(er)
}
return filepath.Dir(ex)
}
// Serving static files // Serving static files
func wsStaticFiles(w http.ResponseWriter, r *http.Request) { func wsStaticFiles(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path { switch r.URL.Path {