api.go 712 Bytes
Newer Older
songlinfeng's avatar
songlinfeng committed
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
/**
# Copyright (c) 2024, HCUOpt CORPORATION.  All rights reserved.
**/

package runtime

type rt struct {
	logger       *Logger
	modeOverride string
}

// Interface is the interface for the runtime library.
type Interface interface {
	Run([]string) error
}

// Option is a function that configures the runtime.
type Option func(*rt)

// New creates a runtime with the specified options.
func New(opts ...Option) Interface {
	r := rt{}
	for _, opt := range opts {
		opt(&r)
	}
	if r.logger == nil {
		r.logger = NewLogger()
	}
	return &r
}

// WithModeOverride allows for overriding the mode specified in the config.
func WithModeOverride(mode string) Option {
	return func(r *rt) {
		r.modeOverride = mode
	}
}