-
Notifications
You must be signed in to change notification settings - Fork 9
/
configurations.go
50 lines (37 loc) · 1.32 KB
/
configurations.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
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package servercore
import (
"context"
"net"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"namespacelabs.dev/foundation/std/go/core"
)
var configConfigs = map[string]ListenerConfiguration{}
type DefaultConfiguration struct{}
type ListenerConfiguration interface {
CreateListener(context.Context, string, ListenOpts) (net.Listener, error)
}
type GrpcListenerConfiguration interface {
ListenerConfiguration
TransportCredentials(string) credentials.TransportCredentials
ServerOpts(string) []grpc.ServerOption
}
func SetListenerConfiguration(name string, conf ListenerConfiguration) {
core.AssertNotRunning("SetServiceConfiguration")
if _, ok := configConfigs[name]; ok {
panic("configuration already set")
}
configConfigs[name] = conf
}
func SetGrpcListenerConfiguration(name string, conf GrpcListenerConfiguration) {
SetListenerConfiguration(name, conf)
}
func listenerConfiguration(name string) ListenerConfiguration {
return configConfigs[name]
}
func (DefaultConfiguration) CreateListener(ctx context.Context, name string, opts ListenOpts) (net.Listener, error) {
return opts.CreateNamedListener(ctx, name)
}