1
0
mirror of https://github.com/mattermost/focalboard.git synced 2025-05-31 22:24:57 +02:00

Refactor server: moved utils to under the main pacakge

This commit is contained in:
Chen-I Lim 2020-10-08 11:47:59 -07:00
parent 65b59146a3
commit 751114f61b
3 changed files with 5 additions and 15 deletions

View File

@ -63,11 +63,3 @@ func readConfigFile() Configuration {
return configuration return configuration
} }
func fileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
}

View File

@ -10,8 +10,6 @@ import (
"syscall" "syscall"
"time" "time"
"../utils"
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
@ -263,7 +261,7 @@ func saveFile(w http.ResponseWriter, file multipart.File, handle *multipart.File
fileExtension = ".jpg" fileExtension = ".jpg"
} }
filename := fmt.Sprintf(`%s%s`, utils.CreateGUID(), fileExtension) filename := fmt.Sprintf(`%s%s`, createGUID(), fileExtension)
folderPath := config.FilesPath folderPath := config.FilesPath
filePath := filepath.Join(folderPath, filename) filePath := filepath.Join(folderPath, filename)
@ -455,7 +453,7 @@ func main() {
// Start the server, with SSL if the certs exist // Start the server, with SSL if the certs exist
urlPort := fmt.Sprintf(`:%d`, config.Port) urlPort := fmt.Sprintf(`:%d`, config.Port)
var isSSL = config.UseSSL && utils.FileExists("./cert/cert.pem") && utils.FileExists("./cert/key.pem") var isSSL = config.UseSSL && fileExists("./cert/cert.pem") && fileExists("./cert/key.pem")
if isSSL { if isSSL {
log.Println("https server started on ", urlPort) log.Println("https server started on ", urlPort)
err := http.ListenAndServeTLS(urlPort, "./cert/cert.pem", "./cert/key.pem", nil) err := http.ListenAndServeTLS(urlPort, "./cert/cert.pem", "./cert/key.pem", nil)

View File

@ -1,4 +1,4 @@
package utils package main
import ( import (
"crypto/rand" "crypto/rand"
@ -8,7 +8,7 @@ import (
) )
// FileExists returns true if a file exists at the path // FileExists returns true if a file exists at the path
func FileExists(path string) bool { func fileExists(path string) bool {
_, err := os.Stat(path) _, err := os.Stat(path)
if os.IsNotExist(err) { if os.IsNotExist(err) {
return false return false
@ -17,7 +17,7 @@ func FileExists(path string) bool {
} }
// CreateGUID returns a random GUID // CreateGUID returns a random GUID
func CreateGUID() string { func createGUID() string {
b := make([]byte, 16) b := make([]byte, 16)
_, err := rand.Read(b) _, err := rand.Read(b)
if err != nil { if err != nil {