-
Notifications
You must be signed in to change notification settings - Fork 3
/
hap.go
95 lines (82 loc) · 2.04 KB
/
hap.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// SPDX-License-Identifier: Apache-2.0
//
// Copyright © 2023 The Happy Authors
package main
import (
"time"
"github.com/happy-sdk/happy"
"github.com/happy-sdk/happy/addons/third-party/github"
"github.com/happy-sdk/happy/cmd/hap/addons/releaser"
"github.com/happy-sdk/happy/cmd/hap/migrations"
"github.com/happy-sdk/happy/sdk/instance"
"github.com/happy-sdk/happy/sdk/logging"
"github.com/happy-sdk/happy/sdk/settings"
)
type Settings struct {
// happy develpment
Happy struct {
Placeholder settings.Bool `key:"placeholder"`
} `group:"happy"`
Placeholder settings.String `key:"placeholder"`
}
func (s Settings) Blueprint() (*settings.Blueprint, error) {
b, err := settings.New(s)
if err != nil {
return nil, err
}
return b, nil
}
func hap() *happy.Main {
settings := happy.Settings{
Name: "Happy Prototyper",
Slug: "happy-sdk",
CopyrightBy: "The Happy Authors",
CopyrightSince: 2019,
License: "Apache-2.0",
TimeLocation: "Local",
MainArgcMax: 0,
// ThrottleTicks: settings.Duration(time.Millisecond * 100),
Instance: instance.Settings{
Max: 100,
},
}
config := Settings{}
config.Placeholder = "happy-placeholder"
config.Placeholder = "app-placeholder"
settings.Extend(config)
main := happy.New(settings).
WithAddon(releaser.Addon(
releaser.Settings{
CommandEnabled: true,
},
)).
WithAddon(github.Addon(
github.Settings{
Owner: "happy-sdk",
Repo: "happy",
},
)).
WithMigrations(migrations.New()).
WithService(backgroundService()).
// WithCommand(nil).
// WithFlag(nil).
WithLogger(logging.Console(logging.LevelOk)).
WithOptions(happy.Option("somekey", "somevalue"))
return main
}
func githubAddon() *happy.Addon {
return github.Addon(
github.Settings{
Owner: "happy-sdk",
Repo: "happy",
},
)
}
func backgroundService() *happy.Service {
svc := happy.NewService("background")
svc.OnTick(func(sess *happy.Session, ts time.Time, delta time.Duration) error {
sess.Log().Info("backgroundService.OnTick")
return nil
})
return svc
}