예제 #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
파일: service_test.go 프로젝트: st3v/cfkit
		})
	})
})

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())
		})
	})