// NewResource new exchange Resource
336166
func NewResource(value interface{}, config ...Config) *Resource {
	res := Resource{Resource: resource.New(value)}
	if len(config) > 0 {
		res.Config = &config[0]
	} else {
		res.Config = &Config{}
	}
	res.Permission = res.Config.Permission

	if res.Config.PrimaryField != "" {
		if err := res.SetPrimaryFields(res.Config.PrimaryField); err != nil {
			fmt.Println(err)
		}
	}
	return &res
}
135047
func (s *SourceAuth) SetResource(v string) *SourceAuth {
	s.Resource = &v
	return s
}
371785
func NewResources(version string, items []Resource) Resources {
	return Resources{
		Version: version,
		Items:   IndexResourcesByName(items),
	}
}
38295
func NewResource(bucketName, keyName string) Resource {
	pattern := bucketName
	if keyName != "" {
		if !strings.HasPrefix(keyName, "/") {
			pattern += "/"
		}

		pattern += keyName
	}

	return Resource{
		BucketName: bucketName,
		Pattern:    pattern,
	}
}
1238183
func (s *TaskFailedEventDetails) SetResource(v string) *TaskFailedEventDetails {
	s.Resource = &v
	return s
}
739591
func New(apiDef *raml.APIDefinition, r *raml.Resource, endpoint string, sortMethod bool) Resource {
	name := func() string {
		if r.DisplayName == "" {
			return commons.NormalizeIdentifier(strings.Title(commons.NormalizeURI(endpoint)))
		}
		return strings.Title(commons.DisplayNameToFuncName(r.DisplayName))
	}()

	res := Resource{
		Endpoint: endpoint,
		APIDef:   apiDef,
		Name:     name,
		Resource: r,
	}

	res.generateMethods(r)
	if sortMethod {
		sort.Sort(byEndpoint(res.Methods))
	}
	return res
}
331976
func (c *Compiler) AddResource(url string, r io.Reader) error {
	res, err := newResource(url, r)
	if err != nil {
		return err
	}
	c.resources[res.url] = res
	return nil
}
270597
func (d *DNS) CreateDomainResource(r *Resource) (*ResourceResponse, error) {
	// Ensure that the resource has a name.
	if len(r.Name) == 0 {
		return nil, linode.NewError(errors.New("dns: creating a resource requires Name be specified"))
	}

	// Initialize parameters that are shared across resource types.
	params := linode.Parameters{
		"DomainID": strconv.Itoa(r.DomainID),
		"Name":     r.Name,
		"TTL_Sec":  strconv.Itoa(r.TTL_Sec),
	}

	// Ensure that the resource has a valid, supported type.
	r.Type = strings.ToUpper(r.Type)
	switch r.Type {
	case "A":
	case "AAAA":
	case "CNAME":
	case "MX":
	case "NS":
	case "TXT":
		// No further processing required for these types.
		break
	case "SRV":
		// Ensure that SRV has a protocol.
		if len(r.Protocol) == 0 {
			return nil, linode.NewError(errors.New("dns: creating a SRV resource requires Priority be specified"))
		}
		params.Set("Protocol", r.Protocol)
		break
	default:
		// Unsupported type.
		return nil, linode.NewError(errors.New("dns: can not create resource of unsupported type: " + r.Type))
	}
	params.Set("Type", r.Type)

	// Ensure that the resource has a valid target.
	if len(r.Target) == 0 {
		return nil, linode.NewError(errors.New("dns: creating a resource requires Target to be specified"))
	}
	params.Set("Target", r.Target)

	if r.Name == "MX" || r.Name == "SRV" {
		// If priority is defined, ensure that it's valid.
		if r.Priority != nil {
			priority, ok := r.Priority.(int)
			if !ok {
				return nil, linode.NewError(errors.New("dns: priority must be specified as an int"))
			}
			if priority < 0 || priority > 255 {
				return nil, linode.NewError(errors.New("dns: priority must be within the range of 0-255"))
			}
			r.Priority = priority
			params.Set("Priority", strconv.Itoa(priority))
		}
	}

	// Create the resource.
	return d.createDomainResource(params)
}
1291119
func (t *Template) AddResource(name string, resource ResourceProperties) *Resource {
	templateResource := &Resource{Properties: resource}
	t.Resources[name] = templateResource
	return templateResource
}
1129832
func (s *ModificationState) SetResource(v string) *ModificationState {
	s.Resource = &v
	return s
}
310203
func (ctx *Context) GetResource() (Resource, error) {
	if ctx.Resource == nil {
		return nil, trace.NotFound("resource is not set in the context")
	}
	return ctx.Resource, nil
}
1263374
func (m *CRConverterFactory) NewConverter(crd *apiextensions.CustomResourceDefinition) (safe, unsafe runtime.ObjectConvertor, err error) {
	validVersions := map[schema.GroupVersion]bool{}
	for _, version := range crd.Spec.Versions {
		validVersions[schema.GroupVersion{Group: crd.Spec.Group, Version: version.Name}] = true
	}

	var converter crConverterInterface
	switch crd.Spec.Conversion.Strategy {
	case apiextensions.NoneConverter:
		converter = &nopConverter{}
	case apiextensions.WebhookConverter:
		if !utilfeature.DefaultFeatureGate.Enabled(apiextensionsfeatures.CustomResourceWebhookConversion) {
			return nil, nil, fmt.Errorf("webhook conversion is disabled on this cluster")
		}
		converter, err = m.webhookConverterFactory.NewWebhookConverter(crd)
		if err != nil {
			return nil, nil, err
		}
		converter, err = m.converterMetricFactory.addMetrics("webhook", crd.Name, converter)
		if err != nil {
			return nil, nil, err
		}
	default:
		return nil, nil, fmt.Errorf("unknown conversion strategy %q for CRD %s", crd.Spec.Conversion.Strategy, crd.Name)
	}

	// Determine whether we should expect to be asked to "convert" autoscaling/v1 Scale types
	convertScale := false
	if utilfeature.DefaultFeatureGate.Enabled(apiextensionsfeatures.CustomResourceSubresources) {
		convertScale = crd.Spec.Subresources != nil && crd.Spec.Subresources.Scale != nil
		for _, version := range crd.Spec.Versions {
			if version.Subresources != nil && version.Subresources.Scale != nil {
				convertScale = true
			}
		}
	}

	unsafe = &crConverter{
		convertScale:  convertScale,
		validVersions: validVersions,
		clusterScoped: crd.Spec.Scope == apiextensions.ClusterScoped,
		converter:     converter,
	}
	return &safeConverterWrapper{unsafe}, unsafe, nil
}
1051502
func (p Protos) CreateResource(rsc resource.Resource) (*resource.Resource, error) {
	rscJSON, err := json.Marshal(rsc)
	if err != nil {
		return nil, err
	}

	url := p.createURL("resource")
	req, err := http.NewRequest("POST", url, bytes.NewBuffer(rscJSON))
	if err != nil {
		return nil, err
	}
	req.Header.Set("Content-Type", "application/json")

	res, err := p.makeRequest(req)
	if err != nil {
		return nil, err
	}

	err = json.Unmarshal(res, &rsc)
	if err != nil {
		return nil, err
	}
	return &rsc, nil
}
847896
func NewResourceStore() *ResourceStore {
	return &ResourceStore{
		SecretStore:    make(map[string]*corev1.Secret),
		ConfigMapStore: make(map[string]*corev1.ConfigMap),
	}
}
1109366
func NewCharmResourcesCommand(resourceLister ResourceLister) modelcmd.ModelCommand {
	var c CharmResourcesCommand
	c.setResourceLister(resourceLister)
	return modelcmd.Wrap(&c)
}
742416
func NewResource(context hap.Context, imgFn GetImageFunc) *Resource {
	r := Resource{
		context: context,
		imgFn:   imgFn,
	}

	return &r
}
1325664
func NewResourceAuth(init ...*ResourceAuth) *ResourceAuth {
	var o *ResourceAuth
	if len(init) == 1 {
		o = init[0]
	} else {
		o = new(ResourceAuth)
	}
	return o
}