Initial commit of Ocean's local development
This commit is contained in:
1 parent
9944a9e1df
commit
86451938ec
116 files changed
+3320
No files matched your search
@@ -0,0 +1,6 @@
|
||||
package Tools
|
||||
|
||||
func ThisHostname() (result string) {
|
||||
result = hostname
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package Tools
|
||||
|
||||
import "net"
|
||||
import "strings"
|
||||
|
||||
func ReadAllIPAddresses4ThisHost() (addresses4Host []string) {
|
||||
addresses4Host = ipAddresses
|
||||
return
|
||||
}
|
||||
|
||||
func initIPAddresses4ThisHost() {
|
||||
addresses, err := net.InterfaceAddrs()
|
||||
if err != nil {
|
||||
ipAddresses = make([]string, 1)
|
||||
ipAddresses[0] = `127.0.0.1`
|
||||
return
|
||||
}
|
||||
|
||||
counter := 0
|
||||
ipAddresses = make([]string, len(addresses))
|
||||
for _, address := range addresses {
|
||||
addressText := address.String()
|
||||
if strings.Contains(addressText, `/`) {
|
||||
addressText = addressText[:strings.Index(addressText, `/`)]
|
||||
}
|
||||
|
||||
ip := net.ParseIP(addressText)
|
||||
if !ip.IsLoopback() && !ip.IsUnspecified() {
|
||||
ipAddresses[counter] = ip.String()
|
||||
counter++
|
||||
}
|
||||
}
|
||||
|
||||
if counter == 0 {
|
||||
ipAddresses = make([]string, 1)
|
||||
ipAddresses[0] = `127.0.0.1`
|
||||
} else {
|
||||
ipAddresses = ipAddresses[:counter]
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package Tools
|
||||
|
||||
import "os"
|
||||
import "time"
|
||||
import "math/rand"
|
||||
import "github.com/SommerEngineering/Ocean/ConfigurationDB"
|
||||
import "github.com/SommerEngineering/Ocean/Log"
|
||||
import LM "github.com/SommerEngineering/Ocean/Log/Meta"
|
||||
|
||||
func init() {
|
||||
// Get this hostname:
|
||||
if hostText, errHost := os.Hostname(); errHost != nil {
|
||||
panic(`Was not able to read the hostname: ` + errHost.Error())
|
||||
} else {
|
||||
hostname = hostText
|
||||
Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameCONFIGURATION, `Log the hostname of this machine.`, hostname)
|
||||
}
|
||||
|
||||
// Get all IP addresses:
|
||||
initIPAddresses4ThisHost()
|
||||
|
||||
// Read the InternalCommPassword:
|
||||
internalCommPassword = ConfigurationDB.Read(`InternalCommPassword`)
|
||||
|
||||
// Set the seed for random:
|
||||
rand.Seed(time.Now().Unix())
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package Tools
|
||||
|
||||
func InternalCommPassword() (pwd string) {
|
||||
pwd = internalCommPassword
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package Tools
|
||||
|
||||
import "math/rand"
|
||||
|
||||
func RandomInteger(max int) (rnd int) {
|
||||
rnd = rand.Intn(max)
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package Tools
|
||||
|
||||
import LM "github.com/SommerEngineering/Ocean/Log/Meta"
|
||||
|
||||
var (
|
||||
senderName LM.Sender = `System::Tools`
|
||||
hostname string = `unknown`
|
||||
ipAddresses []string = nil
|
||||
internalCommPassword string = ``
|
||||
)
|
||||
Reference in new issue
Block a user