// Returns a new Payload struct managing the path provied.
556748
func NewPayload(location string) (*Payload, error) {
	if _, err := os.Stat(filepath.Clean(location)); os.IsNotExist(err) {
		return nil, fmt.Errorf("Payload directory does not exist! Returned: %v", err)
	}
	p := new(Payload)
	p.dir = filepath.Clean(location)
	return p, nil
}
1190741
func (s *VolumeService) NewGetPathForVolumeParams(volumeid string) *GetPathForVolumeParams {
	p := &GetPathForVolumeParams{}
	p.p = make(map[string]interface{})
	p.p["volumeid"] = volumeid
	return p
}
843526
func PayloadMember(i interface{}) interface{} {
	if i == nil {
		return nil
	}

	v := reflect.ValueOf(i).Elem()
	if !v.IsValid() {
		return nil
	}
	if field, ok := v.Type().FieldByName("_"); ok {
		if payloadName := field.Tag.Get("payload"); payloadName != "" {
			field, _ := v.Type().FieldByName(payloadName)
			if field.Tag.Get("type") != "structure" {
				return nil
			}

			payload := v.FieldByName(payloadName)
			if payload.IsValid() || (payload.Kind() == reflect.Ptr && !payload.IsNil()) {
				return payload.Interface()
			}
		}
	}
	return nil
}
1315438
func (fw *Framework) NewReplyFromTransportJSON(payload []byte, skipvalidate bool) (msg protocol.Reply, err error) {
	transport, err := fw.NewTransportFromJSON(string(payload))
	if err != nil {
		return nil, err
	}

	sreply, err := fw.NewSecureReplyFromTransport(transport, skipvalidate)
	if err != nil {
		return nil, err
	}

	reply, err := fw.NewReplyFromSecureReply(sreply)
	if err != nil {
		return nil, err
	}

	protocol.CopyFederationData(transport, reply)

	return reply, nil
}
70569
func Payload(r interface{}, act string) {
	if bs, ok := buildSourceDefinition(true); ok {
		var res *design.ResourceDefinition
		var resName string
		if n, ok := r.(string); ok {
			res = design.Design.Resources[n]
			resName = n
		} else {
			res, _ = r.(*design.ResourceDefinition)
		}
		if res == nil {
			dslengine.ReportError("There is no resource %q", resName)
			return
		}
		a, ok := res.Actions[act]
		if !ok {
			dslengine.ReportError("There is no action")
			return
		}
		payload := a.Payload

		// Set UTD in BuildsFrom parent context

		bs.Parent.BuiltFrom[payload.TypeName] = payload
		bs.Parent.PopulateFromModeledType()
	}
}
29565
func (client *Client) NewRequest(method, path string, payload url.Values) (*http.Request, error) {
	url := client.BaseURL + fmt.Sprintf("%s", path)

	req, err := http.NewRequest(method, url, strings.NewReader(payload.Encode()))
	if err != nil {
		return nil, err
	}

	req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
	req.Header.Add("Accept", "application/json")
	req.Header.Add("User-Agent", client.UserAgent)

	return req, nil
}
799502
func (e Timing) Payload() interface{} {
	return map[string]int64{
		"min": e.Min,
		"max": e.Max,
		"val": e.Value,
		"cnt": e.Count,
	}
}
878716
func New(path string) (*Handle, error) {
	setup()

	n := netns.None()
	if path != "" {
		var err error
		n, err = netns.GetFromPath(path)
		if err != nil {
			return nil, err
		}
	}
	defer n.Close()

	sock, err := nl.GetNetlinkSocketAt(n, netns.None(), syscall.NETLINK_GENERIC)
	if err != nil {
		return nil, err
	}
	// Add operation timeout to avoid deadlocks
	tv := syscall.NsecToTimeval(netlinkSendSocketTimeout.Nanoseconds())
	if err := sock.SetSendTimeout(&tv); err != nil {
		return nil, err
	}
	tv = syscall.NsecToTimeval(netlinkRecvSocketsTimeout.Nanoseconds())
	if err := sock.SetReceiveTimeout(&tv); err != nil {
		return nil, err
	}

	return &Handle{sock: sock}, nil
}
1036386
func New(path string) *Node {
	return &Node{path: path, vpaths: make(map[string]bool)}
}
1316832
func (c *Client) NewRequest(method, pathquery string, payload interface{}) (*http.Request, error) {
	url := *c.BaseURL

	pq := strings.SplitN(pathquery, "?", 2)
	url.Path = url.Path + fmt.Sprintf("%s/%s", apiVersion, pq[0])
	if len(pq) == 2 {
		url.RawQuery = pq[1]
	}

	body := new(bytes.Buffer)
	if payload != nil {
		err := json.NewEncoder(body).Encode(payload)
		if err != nil {
			return nil, err
		}
	}

	req, err := http.NewRequest(method, url.String(), body)
	if err != nil {
		return nil, err
	}

	req.Header.Set("Content-Type", "application/json")
	req.Header.Add("Accept", "application/json")
	req.Header.Add("User-Agent", c.UserAgent)

	return req, nil
}
443589
func (nsPayloads_) asPayloads(docs []payloadDoc) []payload.FullPayloadInfo {
	payloads := make([]payload.FullPayloadInfo, 0, len(docs))
	for _, doc := range docs {
		payloads = append(payloads, nsPayloads.asPayload(doc))
	}
	return payloads
}
163400
func newStruct(name string, def ast.Node) *Struct {
	return &Struct{
		symbol: symbol{
			name: name,
			def:  def,
		},
	}
}
696085
func (c *client) Push(p *drone.Payload) error {
	uri := fmt.Sprintf(pathPush, c.base, p.Job.ID)
	err := c.post(uri, p, nil)
	return err
}
647237
func encodeStruct(path string, src interface{}) ([]byte, error) {
	rv := indirect(reflect.ValueOf(src))
	if rv.Kind() != reflect.Struct {
		return nil, fmt.Errorf("%v, expected struct.", path)
	}
	buf := bytes.NewBuffer(make([]byte, 0))

	// This will be replaced by the size of the doc later.
	if err := binary.Write(buf, binary.LittleEndian, uint32(0)); err != nil {
		return nil, err
	}

	// Encode.
	for i := 0; i < rv.NumField(); i++ {
		sv := rv.Type().Field(i)
		if sv.PkgPath != "" {
			// Unexported field.
			continue
		}
		name := sv.Name
		fv := rv.Field(i)
		fv = indirect(rv.Field(i))
		if tag := sv.Tag.Get("bson"); tag != "" {
			tok := strings.Split(tag, ",")
			if tok[0] == "-" {
				// Ignore field.
				continue
			}
			if tok[0] != "" {
				// Renamed field.
				name = tok[0]
			}
			if len(tok) == 2 && tok[1] == "omitempty" && isEmptyValue(fv) {
				// Empty field, omitempty true.
				continue
			}
		}
		if err := encodeVal(buf, catpath(path, name), name, fv.Interface());
			err != nil {

			return nil, err
		}
	}

	// End of BSON null byte.
	if err := buf.WriteByte(0x00); err != nil {
		return nil, err
	}

	// Write size of document at start of BSON.
	binary.LittleEndian.PutUint32(buf.Bytes(), uint32(buf.Len()))

	return buf.Bytes(), nil
}
807521
func (s *StructStruct) Lookup(path ...string) *StructField {
	name := path[0]
	if len(path) == 1 {
		for _, item := range s.data {
			if item.Name() == name {
				return item
			}
		}
		return nil
	}
	for _, item := range s.data {
		if item.embedded != nil && item.Name() == name {
			return item.embedded.Lookup(path[1:]...)
		}
	}
	return nil
}
241828
func StructToMessage(pbst *types.Struct, out proto.Message) error {
	if pbst == nil {
		return errors.New("nil struct")
	}

	buf := &bytes.Buffer{}
	if err := (&jsonpb.Marshaler{OrigName: true}).Marshal(buf, pbst); err != nil {
		return err
	}

	return jsonpb.Unmarshal(buf, out)
}
86375
func BuildPredicatesFor(patterns []string) ([]PayloadPredicate, error) {
	var predicates []PayloadPredicate
	for i := range patterns {
		pattern := patterns[i]

		predicate := func(payload FullPayloadInfo) bool {
			return Match(payload, pattern)
		}
		predicates = append(predicates, predicate)
	}
	return predicates, nil
}