示例#1
0
文件: rabbitmq.go 项目: st3v/cfkit
func RabbitWithName(name string) (*RabbitMQ, error) {
	svc, err := env.ServiceWithName(name)
	if err != nil {
		return nil, err
	}
	return rabbitLift(svc)
}
示例#2
0
文件: eureka.go 项目: st3v/cfkit
func EurekaWithName(name string) (*eureka.Client, error) {
	svc, err := env.ServiceWithName(name)
	if err != nil {
		return nil, err
	}
	return eurekaLift(svc)
}
示例#3
0
文件: main.go 项目: st3v/cfkit
func svcHandler(rw http.ResponseWriter, req *http.Request) {
	name := mux.Vars(req)["name"]
	if name == "" {
		fmt.Fprint(rw, "Missing service name")
		rw.WriteHeader(http.StatusBadRequest)
		return
	}

	svc, err := env.ServiceWithName(name)
	if err != nil {
		fmt.Fprint(rw, err.Error())
		rw.WriteHeader(http.StatusNotFound)
		return
	}

	out, err := json.Marshal(svc)
	if err != nil {
		fmt.Fprint(rw, err.Error())
		rw.WriteHeader(http.StatusInternalServerError)
		return
	}

	fmt.Fprint(rw, string(out))
}
示例#4
0
		})
	})
})

var _ = Describe(".ServiceWithName", func() {
	BeforeEach(func() {
		os.Setenv("VCAP_SERVICES", vcapServices)
	})

	AfterEach(func() {
		os.Unsetenv("VCAP_SERVICES")
	})

	Context("when the service is defined", func() {
		It("does NOT return an error", func() {
			_, err := env.ServiceWithName("service-name-2")
			Expect(err).ToNot(HaveOccurred())
		})

		It("returns the correct service", func() {
			svc, _ := env.ServiceWithName("service-name-2")
			Expect(svc.Name).To(Equal("service-name-2"))
			Expect(svc.Label).To(Equal("service-label"))
			Expect(svc.Plan).To(Equal("service-plan-2"))
		})

		It("is case-insensitive", func() {
			_, err := env.ServiceWithName("SERVICE-NAME-2")
			Expect(err).ToNot(HaveOccurred())
		})
	})