当前位置: 首页>>代码示例>>Golang>>正文


Golang Config.Load方法代码示例

本文整理汇总了Golang中github.com/cloudfoundry-incubator/lattice/ltc/config.Config.Load方法的典型用法代码示例。如果您正苦于以下问题:Golang Config.Load方法的具体用法?Golang Config.Load怎么用?Golang Config.Load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/cloudfoundry-incubator/lattice/ltc/config.Config的用法示例。


在下文中一共展示了Config.Load方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: MakeCliApp

func MakeCliApp(
	diegoVersion string,
	latticeVersion string,
	ltcConfigRoot string,
	exitHandler exit_handler.ExitHandler,
	config *config.Config,
	logger lager.Logger,
	receptorClientCreator receptor_client.Creator,
	targetVerifier target_verifier.TargetVerifier,
	cliStdout io.Writer,
) *cli.App {
	config.Load()
	app := cli.NewApp()
	app.Name = AppName
	app.Author = latticeCliAuthor
	app.Version = defaultVersion(diegoVersion, latticeVersion)
	app.Usage = LtcUsage
	app.Email = "[email protected]"

	ui := terminal.NewUI(os.Stdin, cliStdout, password_reader.NewPasswordReader(exitHandler))
	app.Writer = ui

	app.Before = func(context *cli.Context) error {
		args := context.Args()
		command := app.Command(args.First())

		if command == nil {
			return nil
		}

		if _, ok := nonTargetVerifiedCommandNames[command.Name]; ok || len(args) == 0 {
			return nil
		}

		if receptorUp, authorized, err := targetVerifier.VerifyTarget(config.Receptor()); !receptorUp {
			ui.SayLine(fmt.Sprintf("Error connecting to the receptor. Make sure your lattice target is set, and that lattice is up and running.\n\tUnderlying error: %s", err.Error()))
			return err
		} else if !authorized {
			ui.SayLine("Could not authenticate with the receptor. Please run ltc target with the correct credentials.")
			return errors.New("Could not authenticate with the receptor.")
		}
		return nil
	}

	app.Action = defaultAction
	app.CommandNotFound = func(c *cli.Context, command string) {
		ui.SayLine(fmt.Sprintf(unknownCommand, command))
		exitHandler.Exit(1)
	}
	app.Commands = cliCommands(ltcConfigRoot, exitHandler, config, logger, receptorClientCreator, targetVerifier, ui)
	return app
}
开发者ID:datachand,项目名称:lattice,代码行数:52,代码来源:cli_app_factory.go

示例2:

				})
				It("errors when port exceeds 65536", func() {
					commandFinishChan := test_helpers.AsyncExecuteCommandWithArgs(targetBlobCommand, []string{"192.168.11.11:70000"})

					Eventually(commandFinishChan).Should(BeClosed())
					Expect(outputBuffer).To(test_helpers.SayLine("Error setting blob target: malformed port"))
					Expect(fakeExitHandler.ExitCalledWith).To(Equal([]int{exit_codes.InvalidSyntax}))
					Expect(fakeTargetVerifier.VerifyBlobTargetCallCount()).To(BeZero())
				})
			})

			Context("scenarios that should not save the config", func() {
				verifyConfigNotSaved := func(failMessage string) {
					Expect(outputBuffer).NotTo(test_helpers.Say("Blob Location Set"))
					Expect(outputBuffer).To(test_helpers.Say(failMessage))
					config.Load()
					blobTarget := config.BlobTarget()
					Expect(blobTarget.TargetHost).To(Equal("original-host"))
					Expect(blobTarget.TargetPort).To(Equal(uint16(8989)))
					Expect(blobTarget.AccessKey).To(Equal("original-key"))
					Expect(blobTarget.SecretKey).To(Equal("original-secret"))
					Expect(blobTarget.BucketName).To(Equal("original-bucket"))
					Expect(fakeExitHandler.ExitCalledWith).To(Equal([]int{exit_codes.BadTarget}))
				}

				BeforeEach(func() {
					config.SetBlobTarget("original-host", 8989, "original-key", "original-secret", "original-bucket")
					config.Save()
				})

				It("does not save the config when there is an error connecting to the target", func() {
开发者ID:se77en,项目名称:lattice,代码行数:31,代码来源:blob_config_command_factory_test.go

示例3:

		It("returns errors from the persistor", func() {
			testPersister.err = errors.New("Error")

			err := testConfig.Save()
			Expect(err).To(MatchError("Error"))
		})
	})

	Describe("Load", func() {
		It("loads the target, username, and password from the persister", func() {
			testPersister.target = "mysavedapi.com"
			testPersister.username = "saveduser"
			testPersister.password = "password"

			Expect(testConfig.Load()).To(Succeed())

			Expect(testPersister.target).To(Equal("mysavedapi.com"))
			Expect(testConfig.Receptor()).To(Equal("http://saveduser:[email protected]"))
		})

		It("returns errors from loading the config", func() {
			testPersister.err = errors.New("Error")

			err := testConfig.Load()
			Expect(err).To(MatchError("Error"))
		})
	})

	Describe("TargetBlob", func() {
		It("sets the blob target", func() {
开发者ID:shanetreacy,项目名称:lattice,代码行数:30,代码来源:config_test.go

示例4:

		It("returns errors from the persistor", func() {
			testConfig = config.New(&fakePersister{err: errors.New("Error")})

			err := testConfig.Save()

			Expect(err).To(MatchError("Error"))
		})
	})

	Describe("Load", func() {
		It("loads the target, username, and password from the persister", func() {
			fakePersister := &fakePersister{target: "mysavedapi.com", username: "saveduser", password: "password"}
			testConfig = config.New(fakePersister)

			testConfig.Load()

			Expect(fakePersister.target).To(Equal("mysavedapi.com"))
			Expect(testConfig.Receptor()).To(Equal("http://saveduser:[email protected]"))
		})

		It("returns errors from loading the config", func() {
			testConfig = config.New(&fakePersister{err: errors.New("Error")})

			err := testConfig.Load()

			Expect(err).To(MatchError("Error"))
		})
	})

	Describe("TargetBlob", func() {
开发者ID:rajkumargithub,项目名称:lattice,代码行数:30,代码来源:config_test.go


注:本文中的github.com/cloudfoundry-incubator/lattice/ltc/config.Config.Load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。