-
Notifications
You must be signed in to change notification settings - Fork 669
/
Copy pathmain.go
72 lines (57 loc) · 1.28 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
*
* Agora Real Time Engagement
* Created by Wei Hu in 2022-10.
* Copyright (c) 2024 Agora IO. All rights reserved.
*
*/
package main
import (
"flag"
"log"
"os"
"ten_framework/ten"
)
type appConfig struct {
PropertyFilePath string
}
type defaultApp struct {
ten.DefaultApp
cfg *appConfig
}
func (p *defaultApp) OnInit(
tenEnv ten.TenEnv,
) {
// Using the default property.json if not specified.
if len(p.cfg.PropertyFilePath) > 0 {
if b, err := os.ReadFile(p.cfg.PropertyFilePath); err != nil {
log.Fatalf("Failed to read property file %s, err %v\n", p.cfg.PropertyFilePath, err)
}else{
tenEnv.InitPropertyFromJSONBytes(b)
}
}
tenEnv.OnInitDone()
}
func startAppBlocking(cfg *appConfig) {
appInstance, err := ten.NewApp(&defaultApp{
cfg: cfg,
})
if err != nil {
log.Fatalf("Failed to create the app, %v\n", err)
}
appInstance.Run(true)
appInstance.Wait()
ten.UnloadAllAddons()
ten.EnsureCleanupWhenProcessExit()
}
func setDefaultLog() {
log.SetFlags(log.LstdFlags | log.Lmicroseconds)
}
func main() {
// Set the default log format globally, users can use `log.Println()` directly.
setDefaultLog()
cfg := &appConfig{}
flag.StringVar(&cfg.PropertyFilePath, "property", "", "The absolute path of property.json")
flag.Parse()
startAppBlocking(cfg)
}