ipfs/ipfs-cluster

View on GitHub
api/common/api.go

Summary

Maintainability
C
1 day
Test Coverage

File api.go has 617 lines of code (exceeds 500 allowed). Consider refactoring.
Open

// Package common implements all the things that an IPFS Cluster API component
// must do, except the actual routes that it handles.
//
// This is meant for re-use when implementing actual REST APIs by saving most
// of the efforts and automatically getting a lot of the setup and things like
Severity: Minor
Found in api/common/api.go - About 4 hrs to fix

    Method API.StreamResponse has a Cognitive Complexity of 40 (exceeds 15 allowed). Consider refactoring.
    Open

    func (api *API) StreamResponse(w http.ResponseWriter, next StreamIterator, errCh chan error) {
        api.SetHeaders(w)
        enc := json.NewEncoder(w)
        flusher, flush := w.(http.Flusher)
        w.Header().Set("Trailer", "X-Stream-Error")
    Severity: Minor
    Found in api/common/api.go - About 4 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    API has 23 methods (exceeds 20 allowed). Consider refactoring.
    Open

    type API struct {
        ctx    context.Context
        cancel func()
    
        config *Config
    Severity: Minor
    Found in api/common/api.go - About 2 hrs to fix

      Method API.SendResponse has a Cognitive Complexity of 16 (exceeds 15 allowed). Consider refactoring.
      Open

      func (api *API) SendResponse(
          w http.ResponseWriter,
          status int,
          err error,
          resp interface{},
      Severity: Minor
      Found in api/common/api.go - About 25 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      exported method API.HealthHandler should have comment or be unexported
      Open

      func (api *API) HealthHandler(w http.ResponseWriter, r *http.Request) {
      Severity: Minor
      Found in api/common/api.go by golint

      There are no issues that match your filters.

      Category
      Status