ns_endpoint.go 582 B

123456789101112131415161718192021222324
  1. package agent
  2. import (
  3. "net/http"
  4. "strings"
  5. "go-common/app/service/main/bns/agent/backend"
  6. "go-common/library/log"
  7. )
  8. // NSTranslation query name from http api
  9. func (s *HTTPServer) NSTranslation(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
  10. name := strings.TrimPrefix(req.URL.Path, "/v1/naming/")
  11. inss, err := s.agent.Query(name)
  12. if err != nil {
  13. log.Error("call easyns server failed with naming translation, err: %s", err.Error())
  14. return nil, err
  15. }
  16. obj := struct {
  17. Instances []*backend.Instance `json:"instances"`
  18. }{inss}
  19. return obj, nil
  20. }