本文整理汇总了Golang中github.com/appc/acbuild/Godeps/_workspace/src/github.com/appc/spec/schema/types.NewACIdentifier函数的典型用法代码示例。如果您正苦于以下问题:Golang NewACIdentifier函数的具体用法?Golang NewACIdentifier怎么用?Golang NewACIdentifier使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewACIdentifier函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: writeEmptyManifest
func (a *ACBuild) writeEmptyManifest() error {
acid, err := types.NewACIdentifier("acbuild-unnamed")
if err != nil {
return err
}
archlabel, err := types.NewACIdentifier("arch")
if err != nil {
return err
}
oslabel, err := types.NewACIdentifier("os")
if err != nil {
return err
}
manifest := &schema.ImageManifest{
ACKind: schema.ImageManifestKind,
ACVersion: schema.AppContainerVersion,
Name: *acid,
Labels: types.Labels{
types.Label{
*archlabel,
runtime.GOARCH,
},
types.Label{
*oslabel,
runtime.GOOS,
},
},
}
manblob, err := manifest.MarshalJSON()
if err != nil {
return err
}
manfile, err := os.Create(path.Join(a.CurrentACIPath, aci.ManifestFile))
if err != nil {
return err
}
_, err = manfile.Write(manblob)
if err != nil {
return err
}
err = manfile.Close()
if err != nil {
return err
}
return nil
}
示例2: NewAppFromString
// NewAppFromString takes a command line app parameter and returns a map of labels.
//
// Example app parameters:
// example.com/reduce-worker:1.0.0
// example.com/reduce-worker,channel=alpha,label=value
// example.com/reduce-worker:1.0.0,label=value
//
// As can be seen in above examples - colon, comma and equal sign have
// special meaning. If any of them has to be a part of a label's value
// then consider writing your own string to App parser.
func NewAppFromString(app string) (*App, error) {
var (
name string
labels map[types.ACIdentifier]string
)
preparedApp, err := prepareAppString(app)
if err != nil {
return nil, err
}
v, err := url.ParseQuery(preparedApp)
if err != nil {
return nil, err
}
labels = make(map[types.ACIdentifier]string, 0)
for key, val := range v {
if len(val) > 1 {
return nil, fmt.Errorf("label %s with multiple values %q", key, val)
}
if key == "name" {
name = val[0]
continue
}
labelName, err := types.NewACIdentifier(key)
if err != nil {
return nil, err
}
labels[*labelName] = val[0]
}
a, err := NewApp(name, labels)
if err != nil {
return nil, err
}
return a, nil
}
示例3: AddLabel
// AddLabel will add a label with the given name and value to the untarred ACI
// stored at a.CurrentACIPath. If the label already exists its value will be updated to
// the new value.
func (a *ACBuild) AddLabel(name, value string) (err error) {
if err = a.lock(); err != nil {
return err
}
defer func() {
if err1 := a.unlock(); err == nil {
err = err1
}
}()
acid, err := types.NewACIdentifier(name)
if err != nil {
return err
}
fn := func(s *schema.ImageManifest) {
removeLabelFromMan(*acid)(s)
s.Labels = append(s.Labels,
types.Label{
Name: *acid,
Value: value,
})
}
return util.ModifyManifest(fn, a.CurrentACIPath)
}
示例4: AddDependency
// AddDependency will add a dependency with the given name, id, labels, and size
// to the untarred ACI stored at acipath. If the dependency already exists its
// fields will be updated to the new values.
func AddDependency(acipath, imageName, imageId string, labels types.Labels, size uint) error {
acid, err := types.NewACIdentifier(imageName)
if err != nil {
return err
}
var hash *types.Hash
if imageId != "" {
var err error
hash, err = types.NewHash(imageId)
if err != nil {
return err
}
}
fn := func(s *schema.ImageManifest) {
removeDep(*acid)(s)
s.Dependencies = append(s.Dependencies,
types.Dependency{
ImageName: *acid,
ImageID: hash,
Labels: labels,
Size: size,
})
}
return util.ModifyManifest(fn, acipath)
}
示例5: NewAppFromString
// NewAppFromString takes a command line app parameter and returns a map of labels.
//
// Example app parameters:
// example.com/reduce-worker:1.0.0
// example.com/reduce-worker,channel=alpha,label=value
func NewAppFromString(app string) (*App, error) {
var (
name string
labels map[types.ACIdentifier]string
)
app = strings.Replace(app, ":", ",version=", -1)
app = "name=" + app
v, err := url.ParseQuery(strings.Replace(app, ",", "&", -1))
if err != nil {
return nil, err
}
labels = make(map[types.ACIdentifier]string, 0)
for key, val := range v {
if len(val) > 1 {
return nil, fmt.Errorf("label %s with multiple values %q", key, val)
}
if key == "name" {
name = val[0]
continue
}
labelName, err := types.NewACIdentifier(key)
if err != nil {
return nil, err
}
labels[*labelName] = val[0]
}
a, err := NewApp(name, labels)
if err != nil {
return nil, err
}
return a, nil
}
示例6: AddIsolator
func (a *ACBuild) AddIsolator(name string, value []byte) (err error) {
if err = a.lock(); err != nil {
return err
}
defer func() {
if err1 := a.unlock(); err == nil {
err = err1
}
}()
acid, err := types.NewACIdentifier(name)
if err != nil {
return err
}
rawMsg := json.RawMessage(value)
fn := func(s *schema.ImageManifest) error {
if s.App == nil {
s.App = newManifestApp()
}
removeIsolatorFromMan(*acid)(s)
s.App.Isolators = append(s.App.Isolators,
types.Isolator{
Name: *acid,
ValueRaw: &rawMsg,
})
return nil
}
return util.ModifyManifest(fn, a.CurrentACIPath)
}
示例7: RemoveDependency
// RemoveDependency will remove the dependency with the given name from the
// untarred ACI stored at acipath
func RemoveDependency(acipath, imageName string) error {
acid, err := types.NewACIdentifier(imageName)
if err != nil {
return err
}
return util.ModifyManifest(removeDep(*acid), acipath)
}
示例8: RemoveAnnotation
// RemoveAnnotation will remove the annotation with the given name from the
// untarred ACI stored at acipath
func RemoveAnnotation(acipath, name string) error {
acid, err := types.NewACIdentifier(name)
if err != nil {
return err
}
return util.ModifyManifest(removeAnnotation(*acid), acipath)
}
示例9: AddAnnotation
// AddAnnotation will add an annotation with the given name and value to the
// untarred ACI stored at acipath. If the annotation already exists its value
// will be updated to the new value.
func AddAnnotation(acipath, name, value string) error {
acid, err := types.NewACIdentifier(name)
if err != nil {
return err
}
fn := func(s *schema.ImageManifest) {
s.Annotations.Set(*acid, value)
}
return util.ModifyManifest(fn, acipath)
}
示例10: NewApp
func NewApp(name string, labels map[types.ACIdentifier]string) (*App, error) {
if labels == nil {
labels = make(map[types.ACIdentifier]string, 0)
}
acn, err := types.NewACIdentifier(name)
if err != nil {
return nil, err
}
return &App{
Name: *acn,
Labels: labels,
}, nil
}
示例11: SetName
// SetName sets the name for the untarred ACI stored at acipath
func SetName(acipath, name string) error {
if name == "" {
return fmt.Errorf("name cannot be empty")
}
acid, err := types.NewACIdentifier(name)
if err != nil {
return err
}
fn := func(s *schema.ImageManifest) {
s.Name = *acid
}
return util.ModifyManifest(fn, acipath)
}
示例12: Set
func (ls *labellist) Set(input string) error {
parts := strings.SplitN(input, "=", 2)
if len(parts) != 2 {
return fmt.Errorf("no '=' character in %q", input)
}
acid, err := types.NewACIdentifier(parts[0])
if err != nil {
return err
}
*ls = append(*ls, types.Label{
Name: *acid,
Value: parts[1],
})
return nil
}
示例13: AddLabel
// AddLabel will add a label with the given name and value to the untarred ACI
// stored at acipath. If the label already exists its value will be updated to
// the new value.
func AddLabel(acipath, name, value string) error {
acid, err := types.NewACIdentifier(name)
if err != nil {
return err
}
fn := func(s *schema.ImageManifest) {
removeLabelFromMan(*acid)(s)
s.Labels = append(s.Labels,
types.Label{
Name: *acid,
Value: value,
})
}
return util.ModifyManifest(fn, acipath)
}
示例14: RemoveAnnotation
// RemoveAnnotation will remove the annotation with the given name from the
// untarred ACI stored at a.CurrentACIPath
func (a *ACBuild) RemoveAnnotation(name string) (err error) {
if err = a.lock(); err != nil {
return err
}
defer func() {
if err1 := a.unlock(); err == nil {
err = err1
}
}()
acid, err := types.NewACIdentifier(name)
if err != nil {
return err
}
return util.ModifyManifest(removeAnnotation(*acid), a.CurrentACIPath)
}
示例15: AddAnnotation
// AddAnnotation will add an annotation with the given name and value to the
// untarred ACI stored at a.CurrentACIPath. If the annotation already exists
// its value will be updated to the new value.
func (a *ACBuild) AddAnnotation(name, value string) (err error) {
if err = a.lock(); err != nil {
return err
}
defer func() {
if err1 := a.unlock(); err == nil {
err = err1
}
}()
acid, err := types.NewACIdentifier(name)
if err != nil {
return err
}
fn := func(s *schema.ImageManifest) {
s.Annotations.Set(*acid, value)
}
return util.ModifyManifest(fn, a.CurrentACIPath)
}