Ocean/Log/ReadProjectName.go

43 lines
1.4 KiB
Go
Raw Permalink Normal View History

2015-06-17 15:44:52 +00:00
package Log
import (
"fmt"
2015-06-17 15:44:52 +00:00
"io/ioutil"
"os"
"path/filepath"
"strings"
)
// Read the project name out of the local configuration file "project.name".
func readProjectName() {
// Try to get access to the working directory:
if currentDir, dirError := os.Getwd(); dirError != nil {
// Case: Error! Stop the server.
fmt.Printf("[Error] Was not able to read the working directory. %s\n", dirError.Error())
os.Exit(0)
2015-06-17 15:44:52 +00:00
} else {
// Try to get access to the file:
filename := filepath.Join(currentDir, `project.name`)
if _, errFile := os.Stat(filename); errFile != nil {
// Cases: Error.
if os.IsNotExist(errFile) {
fmt.Printf("[Error] Cannot read the project name file 'project.name': File not found! Please read https://github.com/SommerEngineering/Ocean\n")
2015-06-17 15:44:52 +00:00
} else {
fmt.Printf("[Error] Cannot read the project name file 'project.name': %s. Please read https://github.com/SommerEngineering/Ocean\n", errFile.Error())
2015-06-17 15:44:52 +00:00
}
os.Exit(0)
2015-06-17 15:44:52 +00:00
}
// Try to read the file:
if projectNameBytes, errRead := ioutil.ReadFile(filename); errRead != nil {
// Case: Error.
fmt.Printf("[Error] Cannot read the project name file 'project.name': %s. Please read https://github.com/SommerEngineering/Ocean\n", errRead.Error())
os.Exit(0)
2015-06-17 15:44:52 +00:00
} else {
// Store the project name:
projectName = string(projectNameBytes)
projectName = strings.TrimSpace(projectName)
}
}
}