Skip to content

Commit

Permalink
Fix linter problems
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio committed Jun 18, 2024
1 parent 3807722 commit 52e747b
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 12 deletions.
5 changes: 1 addition & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ linters-settings:
# Forbid the following identifiers (list of regexp).
# Default: ["^(fmt\\.Print(|f|ln)|print|println)$"]
forbid:
# Builtin function:
- ^print.*$
# Optional message that gets included in error reports.
- p: ^fmt\.Print.*$
- p: "^(fmt\\.Print(|f|ln)|print|println)$"
msg: Do not commit debug print statements.
- p: .*
pkg: ^stellar/go/support/errors$
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ clean:
build-soroban-rpc: build-libpreflight
go build -ldflags="${GOLDFLAGS}" ${MACOS_MIN_VER} -o soroban-rpc -trimpath -v ./cmd/soroban-rpc

go-check-changes:
golangci-lint run ./... --new-from-rev $$(git rev-parse HEAD)
go-check-diff-main:
golangci-lint run ./... --new-from-rev $$(git rev-parse origin/main)

go-check:
golangci-lint run ./...
Expand Down
2 changes: 2 additions & 0 deletions cmd/soroban-rpc/internal/config/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ func parseBool(option *ConfigOption, i interface{}) error {
case nil:
return nil
case bool:
//nolint:forcetypeassert
*option.ConfigKey.(*bool) = v
case string:
lower := strings.ToLower(v)
b, err := strconv.ParseBool(lower)
if err != nil {
return fmt.Errorf("invalid boolean value %s: %s", option.Name, v)
}
//nolint:forcetypeassert
*option.ConfigKey.(*bool) = b
default:
return fmt.Errorf("could not parse boolean %s: %v", option.Name, i)
Expand Down
2 changes: 2 additions & 0 deletions cmd/soroban-rpc/internal/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ func (d *Daemon) GetDB() *db.DB {
}

func (d *Daemon) GetEndpointAddrs() (net.TCPAddr, *net.TCPAddr) {
//nolint:forcetypeassert
addr := d.listener.Addr().(*net.TCPAddr)
var adminAddr *net.TCPAddr
if d.adminListener != nil {
//nolint:forcetypeassert
adminAddr = d.adminListener.Addr().(*net.TCPAddr)
}
return *addr, adminAddr
Expand Down
13 changes: 8 additions & 5 deletions cmd/soroban-rpc/internal/network/requestdurationlimiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func MakeHTTPRequestDurationLimiter(
warningCounter increasingCounter,
limitCounter increasingCounter,
logger *log.Entry,
) *httpRequestDurationLimiter {
) http.Handler {
// make sure the warning threshold is less then the limit threshold; otherwise, just set it to the limit threshold.
if warningThreshold > limitThreshold {
warningThreshold = limitThreshold
Expand Down Expand Up @@ -196,7 +196,7 @@ func (q *httpRequestDurationLimiter) ServeHTTP(res http.ResponseWriter, req *htt
}
}

type rpcRequestDurationLimiter struct {
type RPCRequestDurationLimiter struct {
jrpcDownstreamHandler jrpc2.Handler
requestDurationLimiter
}
Expand All @@ -208,13 +208,13 @@ func MakeJrpcRequestDurationLimiter(
warningCounter increasingCounter,
limitCounter increasingCounter,
logger *log.Entry,
) *rpcRequestDurationLimiter {
) *RPCRequestDurationLimiter {
// make sure the warning threshold is less then the limit threshold; otherwise, just set it to the limit threshold.
if warningThreshold > limitThreshold {
warningThreshold = limitThreshold
}

return &rpcRequestDurationLimiter{
return &RPCRequestDurationLimiter{
jrpcDownstreamHandler: downstream,
requestDurationLimiter: requestDurationLimiter{
warningThreshold: warningThreshold,
Expand All @@ -226,7 +226,10 @@ func MakeJrpcRequestDurationLimiter(
}
}

func (q *rpcRequestDurationLimiter) Handle(ctx context.Context, req *jrpc2.Request) (interface{}, error) {
// TODO: this function is too complicated we should fix this and remove the nolint:gocognit
//
//nolint:gocognit,cyclop
func (q *RPCRequestDurationLimiter) Handle(ctx context.Context, req *jrpc2.Request) (interface{}, error) {
if q.limitThreshold == RequestDurationLimiterNoLimit {
// if specified max duration, pass-through
return q.jrpcDownstreamHandler(ctx, req)
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-rpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func main() {
Short: "Print version information and exit",
Run: func(_ *cobra.Command, _ []string) {
if config.CommitHash == "" {
//nolint:forbidgo
//nolint:forbidigo
fmt.Printf("soroban-rpc dev\n")
} else {
// avoid printing the branch for the main branch
Expand Down

0 comments on commit 52e747b

Please sign in to comment.