-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
92 lines (80 loc) · 2.95 KB
/
config.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
// Copyright (c) 2022 Gobalsky Labs Limited
//
// Use of this software is governed by the Business Source License included
// in the LICENSE file and at https://www.mariadb.com/bsl11.
//
// Change Date: 18 months from the later of the date of the first publicly
// available Distribution of this version of the repository, and 25 June 2022.
//
// On the date above, in accordance with the Business Source License, use
// of this software will be governed by version 3 or later of the GNU General
// Public License.
package api
import (
"github.com/inhies/go-bytesize"
"github.com/elysiumstation/fury/blockexplorer/api/grpc"
"github.com/elysiumstation/fury/libs/config/encoding"
libhttp "github.com/elysiumstation/fury/libs/http"
"github.com/elysiumstation/fury/logging"
)
var (
portalNamedLogger = "api.portal"
gatewayNamedLogger = "api.gateway"
restNamedLogger = "api.rest"
grpcUINamedLogger = "api.grpc-ui"
)
type Config struct {
GRPC grpc.Config `group:"grpc api" namespace:"grpc"`
GRPCUI GRPCUIConfig `group:"grpc web ui" namespace:"grpcui"`
REST RESTConfig `group:"rest api" namespace:"rest"`
Gateway GatewayConfig `group:"gateway" namespace:"grpcui"`
ListenAddress string `long:"listen-address" description:"the IP address that our sever will listen on"`
ListenPort uint16 `long:"listen-port" description:"the port that our sever will listen on"`
}
func NewDefaultConfig() Config {
return Config{
GRPC: grpc.NewDefaultConfig(),
GRPCUI: NewDefaultGRPCUIConfig(),
REST: NewDefaultRESTConfig(),
Gateway: NewDefaultGatewayConfig(),
ListenAddress: "0.0.0.0",
ListenPort: 1515,
}
}
type GRPCUIConfig struct {
Enabled encoding.Bool `long:"enabled"`
Endpoint string `long:"endpoint"`
Level encoding.LogLevel `long:"log-level" choice:"debug" choice:"info" choice:"warning"`
MaxPayloadSize encoding.ByteSize `long:"max-payload-size" description:"Maximum size of GRPC messages the UI will accept from the GRPC server (e.g. 4mb)"`
}
func NewDefaultGRPCUIConfig() GRPCUIConfig {
return GRPCUIConfig{
Enabled: encoding.Bool(true),
Endpoint: "/grpc",
Level: encoding.LogLevel{Level: logging.InfoLevel},
MaxPayloadSize: encoding.ByteSize(4 * bytesize.MB),
}
}
type GatewayConfig struct {
CORS libhttp.CORSConfig `long:"cors" description:"CORS allowed origins"`
}
func NewDefaultGatewayConfig() GatewayConfig {
return GatewayConfig{
CORS: libhttp.CORSConfig{
AllowedOrigins: []string{"*"},
MaxAge: 7200,
},
}
}
type RESTConfig struct {
Level encoding.LogLevel `long:"log-level" choice:"debug" choice:"info" choice:"warning"`
Enabled encoding.Bool `long:"enabled"`
Endpoint string `long:"endpoint"`
}
func NewDefaultRESTConfig() RESTConfig {
return RESTConfig{
Level: encoding.LogLevel{Level: logging.InfoLevel},
Enabled: encoding.Bool(true),
Endpoint: "/rest",
}
}