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>`,
}
func runPath() string {
ex, er := os.Executable()
if er != nil {
panic(er)
}
return filepath.Dir(ex)
}
// Called from the server
func InitTemplates() error {
isServer = true
serverTemplates = make(map[string]*html.Template)
chatTemplates = make(map[string]*text.Template)
ex, er := os.Executable()
if er != nil {
panic(er)
}
runPath := filepath.Dir(ex)
fmt.Println(runPath)
var runPath string = runPath()
// keys and files to load for that template
var serverTemplateDefs map[string][]string = map[string][]string{

View File

@ -27,13 +27,16 @@ type EmoteInfo struct {
Code string
}
func loadEmotes() error {
func runPath() string {
ex, er := os.Executable()
if er != nil {
panic(er)
}
runPath := filepath.Dir(ex)
newEmotes, err := processEmoteDir(runPath + emoteDir)
return filepath.Dir(ex)
}
func loadEmotes() error {
newEmotes, err := processEmoteDir(runPath() + emoteDir)
if err != nil {
return err
}
@ -92,7 +95,7 @@ func processEmoteDir(path string) (common.EmotesMap, error) {
func findEmotes(dir string, em common.EmotesMap) (common.EmotesMap, error) {
//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"))
if err != nil {
return em, fmt.Errorf("unable to glob emote directory: %s\n", err)

View File

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