113 lines
2.1 KiB
Go
113 lines
2.1 KiB
Go
package aeus
|
|
|
|
import (
|
|
"context"
|
|
"maps"
|
|
"reflect"
|
|
"time"
|
|
|
|
"git.nobla.cn/golang/aeus/pkg/logger"
|
|
"git.nobla.cn/golang/aeus/registry"
|
|
)
|
|
|
|
type options struct {
|
|
id string
|
|
name string
|
|
version string
|
|
metadata map[string]string
|
|
ctx context.Context
|
|
logger logger.Logger
|
|
servers []Server
|
|
endpoints []string
|
|
scope Scope
|
|
debug bool
|
|
registrarTimeout time.Duration
|
|
registry registry.Registry
|
|
serviceLoader ServiceLoader
|
|
stopTimeout time.Duration
|
|
injectVars []reflect.Value
|
|
}
|
|
|
|
func WithName(name string) Option {
|
|
return func(o *options) {
|
|
o.name = name
|
|
}
|
|
}
|
|
|
|
func WithVersion(version string) Option {
|
|
return func(o *options) {
|
|
o.version = version
|
|
}
|
|
}
|
|
|
|
func WithMetadata(metadata map[string]string) Option {
|
|
return func(o *options) {
|
|
if o.metadata == nil {
|
|
o.metadata = make(map[string]string)
|
|
}
|
|
maps.Copy(o.metadata, metadata)
|
|
}
|
|
}
|
|
|
|
func WithServer(servers ...Server) Option {
|
|
return func(o *options) {
|
|
o.servers = append(o.servers, servers...)
|
|
}
|
|
}
|
|
|
|
func WithEndpoint(endpoints ...string) Option {
|
|
return func(o *options) {
|
|
o.endpoints = append(o.endpoints, endpoints...)
|
|
}
|
|
}
|
|
|
|
func WithLogger(logger logger.Logger) Option {
|
|
return func(o *options) {
|
|
o.logger = logger
|
|
}
|
|
}
|
|
|
|
func WithScope(scope Scope) Option {
|
|
return func(o *options) {
|
|
o.scope = scope
|
|
}
|
|
}
|
|
|
|
func WithDebug(debug bool) Option {
|
|
return func(o *options) {
|
|
o.debug = debug
|
|
}
|
|
}
|
|
|
|
func WithInjectVars(vars ...any) Option {
|
|
return func(o *options) {
|
|
for _, v := range vars {
|
|
o.injectVars = append(o.injectVars, reflect.ValueOf(v))
|
|
}
|
|
}
|
|
}
|
|
|
|
func WithServiceLoader(loader ServiceLoader) Option {
|
|
return func(o *options) {
|
|
o.serviceLoader = loader
|
|
}
|
|
}
|
|
|
|
func WithStopTimeout(timeout time.Duration) Option {
|
|
return func(o *options) {
|
|
o.stopTimeout = timeout
|
|
}
|
|
}
|
|
|
|
func WithRegistry(registry registry.Registry) Option {
|
|
return func(o *options) {
|
|
o.registry = registry
|
|
}
|
|
}
|
|
|
|
func WithRegistrarTimeout(timeout time.Duration) Option {
|
|
return func(o *options) {
|
|
o.registrarTimeout = timeout
|
|
}
|
|
}
|