本文整理匯總了Golang中github.com/juju/names.IsValidService函數的典型用法代碼示例。如果您正苦於以下問題:Golang IsValidService函數的具體用法?Golang IsValidService怎麽用?Golang IsValidService使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了IsValidService函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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
}
示例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)
}
示例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)
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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:])
}
示例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
}
示例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:])
}
}
示例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
}
示例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
}
示例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)
}
示例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
}