api/common/api.go
File api.go
has 617 lines of code (exceeds 500 allowed). Consider refactoring. Open
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
Method API.StreamResponse
has a Cognitive Complexity of 40 (exceeds 15 allowed). Consider refactoring. Open
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")
- Read upRead up
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
Open
type API struct {
ctx context.Context
cancel func()
config *Config
Method API.SendResponse
has a Cognitive Complexity of 16 (exceeds 15 allowed). Consider refactoring. Open
Open
func (api *API) SendResponse(
w http.ResponseWriter,
status int,
err error,
resp interface{},
- Read upRead up
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
Open
func (api *API) HealthHandler(w http.ResponseWriter, r *http.Request) {
- Exclude checks