• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang names.IsValidService函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/juju/names.IsValidService函数的典型用法代码示例。如果您正苦于以下问题:Golang IsValidService函数的具体用法?Golang IsValidService怎么用?Golang IsValidService使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: Init

func (c *SetConstraintsCommand) Init(args []string) (err error) {
	if c.ServiceName != "" && !names.IsValidService(c.ServiceName) {
		return fmt.Errorf("invalid service name %q", c.ServiceName)
	}
	c.Constraints, err = constraints.Parse(args...)
	return err
}
开发者ID:jiasir,项目名称:juju,代码行数:7,代码来源:constraints.go


示例2: Run

// Run implements cmd.Command.Run.
func (c *ShowServiceCommand) Run(ctx *cmd.Context) error {
	apiclient, err := c.deps.NewClient(c)
	if err != nil {
		return errors.Annotatef(err, "can't connect to %s", c.ConnectionName())
	}
	defer apiclient.Close()

	var unit string
	var service string
	if names.IsValidService(c.target) {
		service = c.target
	} else {
		service, err = names.UnitService(c.target)
		if err != nil {
			return errors.Errorf("%q is neither a service nor a unit", c.target)
		}
		unit = c.target
	}

	vals, err := apiclient.ListResources([]string{service})
	if err != nil {
		return errors.Trace(err)
	}
	if len(vals) != 1 {
		return errors.Errorf("bad data returned from server")
	}
	v := vals[0]
	if unit == "" {
		return c.formatServiceResources(ctx, v)
	}
	return c.formatUnitResources(ctx, unit, service, v)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:33,代码来源:show_service.go


示例3: Rescale

// Rescale requests that all supplied service names be rescaled to
// their minimum configured sizes. It returns the first error it
// encounters.
func (api *API) Rescale(services []string) error {
	args := params.Entities{
		Entities: make([]params.Entity, len(services)),
	}
	for i, service := range services {
		if !names.IsValidService(service) {
			return errors.NotValidf("service name %q", service)
		}
		tag := names.NewServiceTag(service)
		args.Entities[i].Tag = tag.String()
	}
	var results params.ErrorResults
	err := api.caller.FacadeCall("Rescale", args, &results)
	if err != nil {
		return errors.Trace(err)
	}
	for _, result := range results.Results {
		if result.Error != nil {
			if err == nil {
				err = result.Error
			} else {
				logger.Errorf("additional rescale error: %v", err)
			}
		}
	}
	return errors.Trace(err)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:30,代码来源:api.go


示例4: NewAddPendingResourcesArgs

// NewAddPendingResourcesArgs returns the arguments for the
// AddPendingResources API endpoint.
func NewAddPendingResourcesArgs(serviceID string, chID charmstore.CharmID, csMac *macaroon.Macaroon, resources []charmresource.Resource) (AddPendingResourcesArgs, error) {
	var args AddPendingResourcesArgs

	if !names.IsValidService(serviceID) {
		return args, errors.Errorf("invalid service %q", serviceID)
	}
	tag := names.NewServiceTag(serviceID).String()

	var apiResources []CharmResource
	for _, res := range resources {
		if err := res.Validate(); err != nil {
			return args, errors.Trace(err)
		}
		apiRes := CharmResource2API(res)
		apiResources = append(apiResources, apiRes)
	}
	args.Tag = tag
	args.Resources = apiResources
	if chID.URL != nil {
		args.URL = chID.URL.String()
		args.Channel = string(chID.Channel)
		args.CharmStoreMacaroon = csMac
	}
	return args, nil
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:27,代码来源:data.go


示例5: Init

func (c *removeServiceCommand) Init(args []string) error {
	if len(args) == 0 {
		return fmt.Errorf("no service specified")
	}
	if !names.IsValidService(args[0]) {
		return fmt.Errorf("invalid service name %q", args[0])
	}
	c.ServiceName, args = args[0], args[1:]
	return cmd.CheckEmpty(args)
}
开发者ID:pmatulis,项目名称:juju,代码行数:10,代码来源:removeservice.go


示例6: Init

func (c *serviceGetConstraintsCommand) Init(args []string) error {
	if len(args) == 0 {
		return fmt.Errorf("no service name specified")
	}
	if !names.IsValidService(args[0]) {
		return fmt.Errorf("invalid service name %q", args[0])
	}

	c.ServiceName = args[0]
	return nil
}
开发者ID:imoapps,项目名称:juju,代码行数:11,代码来源:constraints.go


示例7: validate

// validate returns an error if any fields are invalid or missing.
func (b block) validate() error {
	if !names.IsValidService(b.serviceName) {
		return errors.Errorf("invalid service name %q", b.serviceName)
	}
	if b.unblock == nil {
		return errors.New("missing unblock channel")
	}
	if b.abort == nil {
		return errors.New("missing abort channel")
	}
	return nil
}
开发者ID:imoapps,项目名称:juju,代码行数:13,代码来源:block.go


示例8: GetServiceConstraints

func (f *fakeConstraintsClient) GetServiceConstraints(name string) (constraints.Value, error) {
	if !names.IsValidService(name) {
		return constraints.Value{}, errors.Errorf("%q is not a valid service name", name)
	}

	cons, ok := f.servCons[name]
	if !ok {
		return constraints.Value{}, errors.NotFoundf("service %q", name)
	}

	return cons, nil
}
开发者ID:imoapps,项目名称:juju,代码行数:12,代码来源:constraints_test.go


示例9: Init

// Init implements cmd.Command.
func (c *setPlanCommand) Init(args []string) error {
	if len(args) < 2 {
		return errors.New("need to specify plan uuid and service name")
	}

	serviceName := args[0]
	if !names.IsValidService(serviceName) {
		return errors.Errorf("invalid service name %q", serviceName)
	}

	c.Plan = args[1]
	c.Service = serviceName

	return c.ModelCommandBase.Init(args[2:])
}
开发者ID:perrito666,项目名称:romulus,代码行数:16,代码来源:set_plan.go


示例10: Service

// Service returns a service state by name.
func (st *State) Service(name string) (service *Service, err error) {
	if !names.IsValidService(name) {
		return nil, fmt.Errorf("%q is not a valid service name", name)
	}
	sdoc := &serviceDoc{}
	sel := bson.D{{"_id", name}}
	err = st.services.Find(sel).One(sdoc)
	if err == mgo.ErrNotFound {
		return nil, errors.NotFoundf("service %q", name)
	}
	if err != nil {
		return nil, fmt.Errorf("cannot get service %q: %v", name, err)
	}
	return newService(st, sdoc), nil
}
开发者ID:klyachin,项目名称:juju,代码行数:16,代码来源:state.go


示例11: Init

// Init validates the service name and any other options.
func (c *DefinedCommand) Init(args []string) error {
	switch len(args) {
	case 0:
		return errors.New("no service name specified")
	case 1:
		svcName := args[0]
		if !names.IsValidService(svcName) {
			return errors.Errorf("invalid service name %q", svcName)
		}
		c.serviceTag = names.NewServiceTag(svcName)
		return nil
	default:
		return cmd.CheckEmpty(args[1:])
	}
}
开发者ID:Pankov404,项目名称:juju,代码行数:16,代码来源:defined.go


示例12: validate

// validate returns an error if any fields are invalid or missing.
func (c check) validate() error {
	if !names.IsValidService(c.serviceName) {
		return errors.Errorf("invalid service name %q", c.serviceName)
	}
	if !names.IsValidUnit(c.unitName) {
		return errors.Errorf("invalid unit name %q", c.unitName)
	}
	if c.response == nil {
		return errors.New("missing response channel")
	}
	if c.abort == nil {
		return errors.New("missing abort channel")
	}
	return nil
}
开发者ID:imoapps,项目名称:juju,代码行数:16,代码来源:check.go


示例13: Init

// Init reads and verifies the cli arguments for the collectMetricsCommand
func (c *collectMetricsCommand) Init(args []string) error {
	if len(args) == 0 {
		return errors.New("you need to specify a unit or service.")
	}
	if names.IsValidUnit(args[0]) {
		c.units = []string{args[0]}
	} else if names.IsValidService(args[0]) {
		c.services = []string{args[0]}
	} else {
		return errors.Errorf("%q is not a valid unit or service", args[0])
	}
	if err := cmd.CheckEmpty(args[1:]); err != nil {
		return errors.Errorf("unknown command line arguments: " + strings.Join(args, ","))
	}
	return nil
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:17,代码来源:collectmetrics.go


示例14: Init

func (c *deployCommand) Init(args []string) error {
	switch len(args) {
	case 2:
		if !names.IsValidService(args[1]) {
			return fmt.Errorf("invalid service name %q", args[1])
		}
		c.ServiceName = args[1]
		fallthrough
	case 1:
		c.CharmOrBundle = args[0]
	case 0:
		return errors.New("no charm or bundle specified")
	default:
		return cmd.CheckEmpty(args[2:])
	}
	return c.UnitCommandBase.Init(args)
}
开发者ID:snailwalker,项目名称:juju,代码行数:17,代码来源:deploy.go


示例15: SetServiceConstraints

func (f *fakeConstraintsClient) SetServiceConstraints(name string, cons constraints.Value) error {
	if f.err != nil {
		return f.err
	}

	if !names.IsValidService(name) {
		return errors.Errorf("%q is not a valid service name", name)
	}

	_, ok := f.servCons[name]
	if !ok {
		return errors.NotFoundf("service %q", name)
	}

	f.servCons[name] = cons
	return nil
}
开发者ID:imoapps,项目名称:juju,代码行数:17,代码来源:constraints_test.go


示例16: Init

func (c *UpgradeCharmCommand) Init(args []string) error {
	switch len(args) {
	case 1:
		if !names.IsValidService(args[0]) {
			return fmt.Errorf("invalid service name %q", args[0])
		}
		c.ServiceName = args[0]
	case 0:
		return fmt.Errorf("no service specified")
	default:
		return cmd.CheckEmpty(args[1:])
	}
	if c.SwitchURL != "" && c.Revision != -1 {
		return fmt.Errorf("--switch and --revision are mutually exclusive")
	}
	return nil
}
开发者ID:kapilt,项目名称:juju,代码行数:17,代码来源:upgradecharm.go


示例17: Init

func (c *RunCommand) Init(args []string) error {
	if len(args) == 0 {
		return fmt.Errorf("no commands specified")
	}
	c.commands, args = args[0], args[1:]

	if c.all {
		if len(c.machines) != 0 {
			return fmt.Errorf("You cannot specify --all and individual machines")
		}
		if len(c.services) != 0 {
			return fmt.Errorf("You cannot specify --all and individual services")
		}
		if len(c.units) != 0 {
			return fmt.Errorf("You cannot specify --all and individual units")
		}
	} else {
		if len(c.machines) == 0 && len(c.services) == 0 && len(c.units) == 0 {
			return fmt.Errorf("You must specify a target, either through --all, --machine, --service or --unit")
		}
	}

	var nameErrors []string
	for _, machineId := range c.machines {
		if !names.IsValidMachine(machineId) {
			nameErrors = append(nameErrors, fmt.Sprintf("  %q is not a valid machine id", machineId))
		}
	}
	for _, service := range c.services {
		if !names.IsValidService(service) {
			nameErrors = append(nameErrors, fmt.Sprintf("  %q is not a valid service name", service))
		}
	}
	for _, unit := range c.units {
		if !names.IsValidUnit(unit) {
			nameErrors = append(nameErrors, fmt.Sprintf("  %q is not a valid unit name", unit))
		}
	}
	if len(nameErrors) > 0 {
		return fmt.Errorf("The following run targets are not valid:\n%s",
			strings.Join(nameErrors, "\n"))
	}

	return cmd.CheckEmpty(args)
}
开发者ID:Pankov404,项目名称:juju,代码行数:45,代码来源:run.go


示例18: Init

// Init reads and verifies the cli arguments for the SetMeterStatusCommand
func (c *SetMeterStatusCommand) Init(args []string) error {
	if len(args) != 2 {
		return errors.New("you need to specify an entity (service or unit) and a status")
	}
	if names.IsValidUnit(args[0]) {
		c.Tag = names.NewUnitTag(args[0])
	} else if names.IsValidService(args[0]) {
		c.Tag = names.NewServiceTag(args[0])
	} else {
		return errors.Errorf("%q is not a valid unit or service", args[0])
	}
	c.Status = args[1]

	if err := cmd.CheckEmpty(args[2:]); err != nil {
		return errors.Errorf("unknown command line arguments: " + strings.Join(args, ","))
	}
	return nil
}
开发者ID:exekias,项目名称:juju,代码行数:19,代码来源:setmeterstatus.go


示例19: NewListResourcesArgs

// NewListResourcesArgs returns the arguments for the ListResources endpoint.
func NewListResourcesArgs(services []string) (ListResourcesArgs, error) {
	var args ListResourcesArgs
	var errs []error
	for _, service := range services {
		if !names.IsValidService(service) {
			err := errors.Errorf("invalid service %q", service)
			errs = append(errs, err)
			continue
		}
		args.Entities = append(args.Entities, params.Entity{
			Tag: names.NewServiceTag(service).String(),
		})
	}
	if err := resolveErrors(errs); err != nil {
		return args, errors.Trace(err)
	}
	return args, nil
}
开发者ID:OSBI,项目名称:juju,代码行数:19,代码来源:data.go


示例20: NewUploadRequest

// NewUploadRequest generates a new upload request for the given resource.
func NewUploadRequest(service, name string, r io.ReadSeeker) (UploadRequest, error) {
	if !names.IsValidService(service) {
		return UploadRequest{}, errors.Errorf("invalid service %q", service)
	}

	content, err := resource.GenerateContent(r)
	if err != nil {
		return UploadRequest{}, errors.Trace(err)
	}

	ur := UploadRequest{
		Service:     service,
		Name:        name,
		Size:        content.Size,
		Fingerprint: content.Fingerprint,
	}
	return ur, nil
}
开发者ID:OSBI,项目名称:juju,代码行数:19,代码来源:upload.go



注:本文中的github.com/juju/names.IsValidService函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang names.IsValidSpace函数代码示例发布时间:2022-05-23
下一篇:
Golang names.IsValidMachine函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap