github.com/ethersphere/bee/v2@v2.2.0/pkg/api/topology.go (about)

     1  // Copyright 2020 The Swarm Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package api
     6  
     7  import (
     8  	"bytes"
     9  	"encoding/json"
    10  	"io"
    11  	"net/http"
    12  
    13  	"github.com/ethersphere/bee/v2/pkg/jsonhttp"
    14  )
    15  
    16  func (s *Service) topologyHandler(w http.ResponseWriter, _ *http.Request) {
    17  	logger := s.logger.WithName("get_topology").Build()
    18  
    19  	params := s.topologyDriver.Snapshot()
    20  
    21  	params.LightNodes = s.lightNodes.PeerInfo()
    22  
    23  	b, err := json.Marshal(params)
    24  	if err != nil {
    25  		logger.Error(err, "marshal to json failed")
    26  		jsonhttp.InternalServerError(w, err)
    27  		return
    28  	}
    29  	w.Header().Set(ContentTypeHeader, jsonhttp.DefaultContentTypeHeader)
    30  	_, _ = io.Copy(w, bytes.NewBuffer(b))
    31  }