aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/outcome/main.go
blob: 48762c13511540937134c6de894a060e6c22c3cd (plain)
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
package outcome

import (
	"context"
	"log"

	"hakurei.app/hst"
	"hakurei.app/message"
)

// Main runs an app according to [hst.Config] and terminates. Main does not return.
func Main(ctx context.Context, msg message.Msg, config *hst.Config) {
	var id hst.ID
	if err := hst.NewInstanceID(&id); err != nil {
		log.Fatal(err.Error())
	}

	seal := outcome{syscallDispatcher: direct{msg}}
	if err := seal.finalise(ctx, msg, &id, config); err != nil {
		printMessageError(msg.GetLogger().Fatalln, "cannot seal app:", err)
		panic("unreachable")
	}

	seal.main(msg)
	panic("unreachable")
}