Refactor server: moved utils to under the main pacakge
This commit is contained in:
parent
65b59146a3
commit
751114f61b
3 changed files with 5 additions and 15 deletions
|
@ -63,11 +63,3 @@ func readConfigFile() Configuration {
|
|||
|
||||
return configuration
|
||||
}
|
||||
|
||||
func fileExists(filename string) bool {
|
||||
info, err := os.Stat(filename)
|
||||
if os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
return !info.IsDir()
|
||||
}
|
||||
|
|
|
@ -10,8 +10,6 @@ import (
|
|||
"syscall"
|
||||
"time"
|
||||
|
||||
"../utils"
|
||||
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
@ -263,7 +261,7 @@ func saveFile(w http.ResponseWriter, file multipart.File, handle *multipart.File
|
|||
fileExtension = ".jpg"
|
||||
}
|
||||
|
||||
filename := fmt.Sprintf(`%s%s`, utils.CreateGUID(), fileExtension)
|
||||
filename := fmt.Sprintf(`%s%s`, createGUID(), fileExtension)
|
||||
|
||||
folderPath := config.FilesPath
|
||||
filePath := filepath.Join(folderPath, filename)
|
||||
|
@ -455,7 +453,7 @@ func main() {
|
|||
|
||||
// Start the server, with SSL if the certs exist
|
||||
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 {
|
||||
log.Println("https server started on ", urlPort)
|
||||
err := http.ListenAndServeTLS(urlPort, "./cert/cert.pem", "./cert/key.pem", nil)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package utils
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
|
@ -8,7 +8,7 @@ import (
|
|||
)
|
||||
|
||||
// FileExists returns true if a file exists at the path
|
||||
func FileExists(path string) bool {
|
||||
func fileExists(path string) bool {
|
||||
_, err := os.Stat(path)
|
||||
if os.IsNotExist(err) {
|
||||
return false
|
||||
|
@ -17,7 +17,7 @@ func FileExists(path string) bool {
|
|||
}
|
||||
|
||||
// CreateGUID returns a random GUID
|
||||
func CreateGUID() string {
|
||||
func createGUID() string {
|
||||
b := make([]byte, 16)
|
||||
_, err := rand.Read(b)
|
||||
if err != nil {
|
Loading…
Reference in a new issue