Skip to content

Commit

Permalink
specify config path (#14)
Browse files Browse the repository at this point in the history
* fix: proper error message when token in is too small

* go work sum

* feat: config path
  • Loading branch information
p0mvn authored Jan 5, 2024
1 parent edeb7c1 commit 2b9cc12
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 59 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ generate-mocks: mockery
bin/mockery --config mockery.yaml

run:
go run app/*.go
go run app/*.go --config config.json

redis-start:
docker run -d --name redis-stack -p 6379:6379 -p 8001:8001 -v ./redis-cache/:/data redis/redis-stack:7.2.0-v3
Expand Down
25 changes: 17 additions & 8 deletions app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,41 @@ package main

import (
"context"
"flag"
"fmt"
"log"
"os"
"os/signal"
"syscall"

"github.com/osmosis-labs/osmosis/v21/app"
"github.com/osmosis-labs/sqs/chaininfo/client"
sqslog "github.com/osmosis-labs/sqs/log"
"github.com/redis/go-redis/v9"
"github.com/spf13/viper"

"github.com/osmosis-labs/osmosis/v21/app"
)

func init() {
viper.SetConfigFile(`config.json`)
err := viper.ReadInConfig()
if err != nil {
panic(err)
}

if viper.GetBool(`debug`) {
log.Println("Service RUN on DEBUG mode")
}
}

func main() {
configPath := flag.String("config", "config.json", "config file location")

// Parse the command-line arguments
flag.Parse()

fmt.Println("configPath", *configPath)

viper.SetConfigFile(*configPath)
err := viper.ReadInConfig()
if err != nil {
panic(err)
}

dbHost := viper.GetString(`database.host`)
dbPort := viper.GetString(`database.port`)

Expand All @@ -49,7 +58,7 @@ func main() {
})

redisStatus := redisClient.Ping(context.Background())
_, err := redisStatus.Result()
_, err = redisStatus.Result()
if err != nil {
panic(err)
}
Expand Down
50 changes: 0 additions & 50 deletions app/sqs_config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package main

import (
servertypes "github.com/cosmos/cosmos-sdk/server/types"

"github.com/osmosis-labs/osmosis/osmoutils"
"github.com/osmosis-labs/sqs/domain"
)

Expand Down Expand Up @@ -62,50 +59,3 @@ var DefaultConfig = Config{
RouteCacheExpirySeconds: 600, // 10 minutes
},
}

// NewConfigFromOptions returns a new sidecar query server config from the given options.
func NewConfigFromOptions(opts servertypes.AppOptions) Config {
isEnabled := osmoutils.ParseBool(opts, groupOptName, "is-enabled", false)

if !isEnabled {
return Config{
IsEnabled: false,
}
}

return Config{
IsEnabled: isEnabled,

StorageHost: osmoutils.ParseString(opts, groupOptName, "db-host"),
StoragePort: osmoutils.ParseString(opts, groupOptName, "db-port"),

ServerAddress: osmoutils.ParseString(opts, groupOptName, "server-address"),
ServerTimeoutDurationSecs: osmoutils.ParseInt(opts, groupOptName, "timeout-duration-secs"),

LoggerFilename: osmoutils.ParseString(opts, groupOptName, "logger-filename"),
LoggerIsProduction: osmoutils.ParseBool(opts, groupOptName, "logger-is-production", false),
LoggerLevel: osmoutils.ParseString(opts, groupOptName, "logger-level"),

ChainGRPCGatewayEndpoint: osmoutils.ParseString(opts, groupOptName, "grpc-gateway-endpoint"),

Router: &domain.RouterConfig{
PreferredPoolIDs: osmoutils.ParseUint64Slice(opts, groupOptName, "preferred-pool-ids"),

MaxPoolsPerRoute: osmoutils.ParseInt(opts, groupOptName, "max-pools-per-route"),

MaxRoutes: osmoutils.ParseInt(opts, groupOptName, "max-routes"),

MaxSplitRoutes: osmoutils.ParseInt(opts, groupOptName, "max-split-routes"),

MaxSplitIterations: osmoutils.ParseInt(opts, groupOptName, "max-split-iterations"),

MinOSMOLiquidity: osmoutils.ParseInt(opts, groupOptName, "min-osmo-liquidity"),

RouteUpdateHeightInterval: osmoutils.ParseInt(opts, groupOptName, "route-update-height-interval"),

RouteCacheEnabled: osmoutils.ParseBool(opts, groupOptName, "route-cache-enabled", false),

RouteCacheExpirySeconds: uint64(osmoutils.ParseInt(opts, groupOptName, "route-cache-expiry-seconds")),
},
}
}

0 comments on commit 2b9cc12

Please sign in to comment.