Skip to content

Commit

Permalink
improve shutdown comms; improve readability; filter stream by file pr…
Browse files Browse the repository at this point in the history
…efix + fixes
  • Loading branch information
i-norden committed Jul 8, 2021
1 parent e6da8c7 commit 2549cf0
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 82 deletions.
5 changes: 3 additions & 2 deletions store/streaming/file/server/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const (

var (
configPath string
serverCfg *config.StateServerConfig
serverCfg *config.StateFileServerConfig
interfaceRegistry = codecTypes.NewInterfaceRegistry()
marshaller = codec.NewProtoCodec(interfaceRegistry)
)
Expand All @@ -37,6 +37,7 @@ var rootCmd = &cobra.Command{
PersistentPreRun: initFuncs,
}

// Execute is the top level command entry point
func Execute() {
log.Print("----- Starting Cosmos state change file server -----")
if err := rootCmd.Execute(); err != nil {
Expand Down Expand Up @@ -79,7 +80,7 @@ func initFuncs(cmd *cobra.Command, args []string) {
}

func initConfig() {
serverCfg = config.DefaultStateServerConfig()
serverCfg = config.DefaultStateFileServerConfig()
if configPath != "" {
switch _, err := os.Stat(configPath); {
case os.IsNotExist(err):
Expand Down
16 changes: 8 additions & 8 deletions store/streaming/file/server/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ import (
)

const (
tomlFlagRemoveAfter = "file-server.remove-after"
tomlFlagFilePrefix = "file-server.file-prefix"
tomlFlagReadDir = "file-server.read-dir"
tomlFlagChainID = "file-server.chain-id"
tomlFlagGRPCAddress = "file-server.grpc-address"
tomlFlagGRPCWebEnable = "file-server.grpc-web-enable"
tomlFlagGRPCWebAddress = "file-server.grpc-web-address"

cliFlagRemoveAfter = "remove-after"
cliFlagFilePrefix = "file-prefix"
cliFlagReadDir = "read-dir"
cliFlagChainID = "chain-id"
cliFlagGRPCAddress = "grpc-address"
cliFlagGRPCWebEnable = "grpc-web-enable"
cliFlagGRPCWebAddress = "grpc-web-address"

tomlFlagRemoveAfter = "file-server.remove-after"
tomlFlagFilePrefix = "file-server.file-prefix"
tomlFlagReadDir = "file-server.read-dir"
tomlFlagChainID = "file-server.chain-id"
tomlFlagGRPCAddress = "file-server.grpc-address"
tomlFlagGRPCWebEnable = "file-server.grpc-web-enable"
tomlFlagGRPCWebAddress = "file-server.grpc-web-address"
)

var (
Expand Down
29 changes: 15 additions & 14 deletions store/streaming/file/server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const (
DefaultGRPCWebAddress = "0.0.0.0:9093"
)

type StateServerConfig struct {
// StateFileServerConfig contains configuration parameters for the state file server
type StateFileServerConfig struct {
GRPCAddress string `mapstructure:"grpc-address"`
GRPCWebEnabled bool `mapstructure:"grpc-web-enabled"`
GRPCWebAddress string `mapstructure:"grpc-web-address"`
Expand All @@ -32,18 +33,18 @@ type StateServerConfig struct {
LogLevel string `mapstructure:"log-level"`
}

// DefaultStateServerConfig returns the reference to ClientConfig with default values.
func DefaultStateServerConfig() *StateServerConfig {
return &StateServerConfig{
DefaultGRPCAddress,
true,
DefaultGRPCWebAddress,
"",
DefaultReadDir,
"",
true,
"",
"info",
// DefaultStateFileServerConfig returns the reference to ClientConfig with default values.
func DefaultStateFileServerConfig() *StateFileServerConfig {
return &StateFileServerConfig{
GRPCAddress: DefaultGRPCAddress,
GRPCWebEnabled: true,
GRPCWebAddress: DefaultGRPCWebAddress,
ChainID: "",
ReadDir: DefaultReadDir,
FilePrefix: "",
RemoveAfter: true,
LogFile: "",
LogLevel: "info",
}
}

Expand All @@ -61,7 +62,7 @@ func init() {

// WriteConfigFile renders config using the template and writes it to
// configFilePath.
func WriteConfigFile(configFilePath string, config *StateServerConfig) {
func WriteConfigFile(configFilePath string, config *StateFileServerConfig) {
var buffer bytes.Buffer

if err := configTemplate.Execute(&buffer, config); err != nil {
Expand Down
Loading

0 comments on commit 2549cf0

Please sign in to comment.