-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (35 loc) · 819 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"log"
"math/rand"
"os"
"strconv"
"time"
)
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
var seededRand *rand.Rand = rand.New(rand.NewSource(time.Now().UnixNano()))
func generateRandomString(length int) string {
b := make([]byte, length)
for i := range b {
b[i] = charset[seededRand.Intn(len(charset))]
}
return string(b)
}
func main() {
port, found := os.LookupEnv("echo_service_port")
if !found {
port = "8080"
}
instanceName, found := os.LookupEnv("instance_name")
if !found {
instanceName = generateRandomString(10)
}
p, err := strconv.Atoi(port)
if err != nil {
log.Fatalf("Cannot start echo-service: %v", err)
}
err = StartEchoService(p, instanceName)
if err != nil {
log.Fatalf("Cannot start echo-service: %v", err)
}
}