本文整理匯總了Golang中github.com/docker/swarmkit/api.ServiceSpec.Networks方法的典型用法代碼示例。如果您正苦於以下問題:Golang ServiceSpec.Networks方法的具體用法?Golang ServiceSpec.Networks怎麽用?Golang ServiceSpec.Networks使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/docker/swarmkit/api.ServiceSpec
的用法示例。
在下文中一共展示了ServiceSpec.Networks方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ResolveServiceNetworks
// ResolveServiceNetworks takes a service spec and resolves network names to network IDs.
func ResolveServiceNetworks(ctx context.Context, c api.ControlClient, spec *api.ServiceSpec) error {
if len(spec.Networks) == 0 {
return nil
}
networks := make([]*api.ServiceSpec_NetworkAttachmentConfig, 0, len(spec.Networks))
for _, na := range spec.Networks {
n, err := GetNetwork(ctx, c, na.Target)
if err != nil {
return err
}
networks = append(networks, &api.ServiceSpec_NetworkAttachmentConfig{
Target: n.ID,
})
}
spec.Networks = networks
return nil
}
示例2: parseNetworks
func parseNetworks(cmd *cobra.Command, spec *api.ServiceSpec, c api.ControlClient) error {
flags := cmd.Flags()
if !flags.Changed("network") {
return nil
}
input, err := flags.GetString("network")
if err != nil {
return err
}
n, err := network.GetNetwork(common.Context(cmd), c, input)
if err != nil {
return err
}
spec.Networks = []*api.ServiceSpec_NetworkAttachmentConfig{
{
Target: n.ID,
},
}
return nil
}