当前位置: 首页>>代码示例>>Golang>>正文


Golang utils.NewError函数代码示例

本文整理汇总了Golang中github.com/taviti/caldav-go/utils.NewError函数的典型用法代码示例。如果您正苦于以下问题:Golang NewError函数的具体用法?Golang NewError怎么用?Golang NewError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: hydrateNestedComponent

func hydrateNestedComponent(v reflect.Value, component *token) error {

	// create a new object to hold the property value
	var vnew, varr = newValue(v)
	if err := hydrateComponent(vnew, component); err != nil {
		return utils.NewError(hydrateNestedComponent, "unable to decode component", component, err)
	}

	if varr {
		// for arrays, append the new value into the array structure
		voldval := dereferencePointerValue(v)
		if !voldval.CanSet() {
			return utils.NewError(hydrateNestedComponent, "unable to set array value", v, nil)
		} else {
			voldval.Set(reflect.Append(voldval, vnew))
		}
	} else if !v.CanSet() {
		return utils.NewError(hydrateNestedComponent, "unable to set pointer value", v, nil)
	} else {
		// everything else should be a pointer, set it directly
		v.Set(vnew)
	}

	return nil

}
开发者ID:johnboiles,项目名称:caldav-go,代码行数:26,代码来源:unmarshal.go

示例2: ValidateICalValue

func (c *Calendar) ValidateICalValue() error {

	for i, e := range c.Events {

		if e == nil {
			continue // skip nil events
		}

		if err := e.ValidateICalValue(); err != nil {
			msg := fmt.Sprintf("event %d failed validation", i)
			return utils.NewError(c.ValidateICalValue, msg, c, err)
		}

		if e.DateStart == nil && c.Method == "" {
			msg := fmt.Sprintf("no value for method and no start date defined on event %d", i)
			return utils.NewError(c.ValidateICalValue, msg, c, nil)
		}

	}

	if c.UsingTimeZone() && !c.UsingGlobalTimeZone() {
		for i, t := range c.TimeZones {
			if t == nil || t.Id != c.TimeZoneId {
				msg := fmt.Sprintf("timezone ID does not match timezone %d", i)
				return utils.NewError(c.ValidateICalValue, msg, c, nil)
			}
		}
	}

	return nil

}
开发者ID:johnboiles,项目名称:caldav-go,代码行数:32,代码来源:calendar.go

示例3: DecodeICalValue

// decodes the duration of time from iCalendar format
func (d *Duration) DecodeICalValue(value string) error {
	var seconds int64
	var isPast = strings.HasPrefix(value, "-P")
	var matches = durationRegEx.FindAllStringSubmatch(value, -1)
	for _, match := range matches {
		var multiplier int64
		ivalue, err := strconv.ParseInt(match[1], 10, 64)
		if err != nil {
			return utils.NewError(d.DecodeICalValue, "unable to decode duration value "+match[1], d, nil)
		}
		switch match[2] {
		case "S":
			multiplier = 1
		case "M":
			multiplier = 60
		case "H":
			multiplier = 60 * 60
		case "D":
			multiplier = 60 * 60 * 24
		case "W":
			multiplier = 60 * 60 * 24 * 7
		default:
			return utils.NewError(d.DecodeICalValue, "unable to decode duration segment "+match[2], d, nil)
		}
		seconds = seconds + multiplier*ivalue
	}
	d.d = time.Duration(seconds) * time.Second
	if isPast {
		d.d = -d.d
	}
	return nil
}
开发者ID:johnboiles,项目名称:caldav-go,代码行数:33,代码来源:duration.go

示例4: QueryEvents

// attempts to fetch an event on the remote CalDAV server
func (c *Client) QueryEvents(path string, query *cent.CalendarQuery) (events []*components.Event, oerr error) {
	ms := new(cent.Multistatus)
	if req, err := c.Server().WebDAV().NewRequest("REPORT", path, query); err != nil {
		oerr = utils.NewError(c.QueryEvents, "unable to create request", c, err)
	} else if resp, err := c.WebDAV().Do(req); err != nil {
		oerr = utils.NewError(c.QueryEvents, "unable to execute request", c, err)
	} else if resp.StatusCode == http.StatusNotFound {
		return // no events if not found
	} else if resp.StatusCode != webdav.StatusMulti {
		err := new(entities.Error)
		msg := fmt.Sprintf("unexpected server response %s", resp.Status)
		resp.Decode(err)
		oerr = utils.NewError(c.QueryEvents, msg, c, err)
	} else if err := resp.Decode(ms); err != nil {
		msg := "unable to decode response"
		oerr = utils.NewError(c.QueryEvents, msg, c, err)
	} else {
		for i, r := range ms.Responses {
			for j, p := range r.PropStats {
				if p.Prop == nil || p.Prop.CalendarData == nil {
					continue
				} else if cal, err := p.Prop.CalendarData.CalendarComponent(); err != nil {
					msg := fmt.Sprintf("unable to decode property %d of response %d", j, i)
					oerr = utils.NewError(c.QueryEvents, msg, c, err)
					return
				} else {
					events = append(events, cal.Events...)
				}
			}
		}
	}
	return
}
开发者ID:johnboiles,项目名称:caldav-go,代码行数:34,代码来源:client.go

示例5: ValidateServer

// returns an error if the server does not support WebDAV
func (c *Client) ValidateServer(path string) error {
	if features, err := c.Features(path); err != nil {
		return utils.NewError(c.ValidateServer, "feature detection failed", c, err)
	} else if len(features) <= 0 {
		return utils.NewError(c.ValidateServer, "no DAV headers found", c, err)
	} else {
		return nil
	}
}
开发者ID:johnboiles,项目名称:caldav-go,代码行数:10,代码来源:client.go

示例6: Features

// fetches a list of WebDAV features supported by the server
// returns an error if the server does not support DAV
func (c *Client) Features(path string) ([]string, error) {
	if req, err := c.Server().NewRequest("OPTIONS", path); err != nil {
		return []string{}, utils.NewError(c.Features, "unable to create request", c, err)
	} else if resp, err := c.Do(req); err != nil {
		return []string{}, utils.NewError(c.Features, "unable to execute request", c, err)
	} else {
		return resp.Features(), nil
	}
}
开发者ID:johnboiles,项目名称:caldav-go,代码行数:11,代码来源:client.go

示例7: Exists

// checks if a resource exists given a particular path
func (c *Client) Exists(path string) (bool, error) {
	if req, err := c.Server().NewRequest("HEAD", path); err != nil {
		return false, utils.NewError(c.Exists, "unable to create request", c, err)
	} else if resp, err := c.Do(req); err != nil {
		return false, utils.NewError(c.Exists, "unable to execute request", c, err)
	} else {
		return resp.StatusCode != nhttp.StatusNotFound, nil
	}
}
开发者ID:johnboiles,项目名称:caldav-go,代码行数:10,代码来源:client.go

示例8: PutEvents

// creates or updates one or more events on the remote CalDAV server
func (c *Client) PutEvents(path string, events ...*components.Event) error {
	if len(events) <= 0 {
		return utils.NewError(c.PutEvents, "no calendar events provided", c, nil)
	} else if cal := components.NewCalendar(events...); events[0] == nil {
		return utils.NewError(c.PutEvents, "icalendar event must not be nil", c, nil)
	} else if err := c.PutCalendars(path, cal); err != nil {
		return utils.NewError(c.PutEvents, "unable to put calendar", c, err)
	}
	return nil
}
开发者ID:johnboiles,项目名称:caldav-go,代码行数:11,代码来源:client.go

示例9: CalendarComponent

func (c *CalendarData) CalendarComponent() (*components.Calendar, error) {
	cal := new(components.Calendar)
	if content := strings.TrimSpace(c.Content); content == "" {
		return nil, utils.NewError(c.CalendarComponent, "no calendar data to decode", c, nil)
	} else if err := icalendar.Unmarshal(content, cal); err != nil {
		return nil, utils.NewError(c.CalendarComponent, "decoding calendar data failed", c, err)
	} else {
		return cal, nil
	}
}
开发者ID:johnboiles,项目名称:caldav-go,代码行数:10,代码来源:calendar_data.go

示例10: hydrateComponent

func hydrateComponent(v reflect.Value, component *token) error {
	if tag, err := extractTagFromValue(v); err != nil {
		return utils.NewError(hydrateComponent, "error extracting tag from value", component, err)
	} else if tag != component.name {
		msg := fmt.Sprintf("expected %s and found %s", tag, component.name)
		return utils.NewError(hydrateComponent, msg, component, nil)
	} else if err := hydrateProperties(v, component); err != nil {
		return utils.NewError(hydrateComponent, "unable to hydrate properties", component, err)
	}
	return nil
}
开发者ID:johnboiles,项目名称:caldav-go,代码行数:11,代码来源:unmarshal.go

示例11: DecodeICalValue

// decodes the geo value from the iCalendar specification
func (g *Geo) DecodeICalValue(value string) error {
	if latlng := strings.Split(value, " "); len(latlng) < 2 {
		return utils.NewError(g.DecodeICalValue, "geo value must have both a latitude and longitude component", g, nil)
	} else if lat, err := strconv.ParseFloat(latlng[0], 64); err != nil {
		return utils.NewError(g.DecodeICalValue, "unable to decode latitude component", g, err)
	} else if lng, err := strconv.ParseFloat(latlng[1], 64); err != nil {
		return utils.NewError(g.DecodeICalValue, "unable to decode latitude component", g, err)
	} else {
		*g = Geo{coords: []float64{lat, lng}}
		return nil
	}
}
开发者ID:johnboiles,项目名称:caldav-go,代码行数:13,代码来源:geo.go

示例12: PutCalendars

// creates or updates one or more calendars on the remote CalDAV server
func (c *Client) PutCalendars(path string, calendars ...*components.Calendar) error {
	if req, err := c.Server().NewRequest("PUT", path, calendars); err != nil {
		return utils.NewError(c.PutCalendars, "unable to encode request", c, err)
	} else if resp, err := c.Do(req); err != nil {
		return utils.NewError(c.PutCalendars, "unable to execute request", c, err)
	} else if resp.StatusCode != http.StatusCreated && resp.StatusCode != http.StatusNoContent {
		err := new(entities.Error)
		resp.WebDAV().Decode(err)
		msg := fmt.Sprintf("unexpected server response %s", resp.Status)
		return utils.NewError(c.PutCalendars, msg, c, err)
	}
	return nil
}
开发者ID:johnboiles,项目名称:caldav-go,代码行数:14,代码来源:client.go

示例13: NewRequest

// creates a new CalDAV request object
func NewRequest(method string, urlstr string, icaldata ...interface{}) (*Request, error) {
	if buffer, err := icalToReadCloser(icaldata...); err != nil {
		return nil, utils.NewError(NewRequest, "unable to encode icalendar data", icaldata, err)
	} else if r, err := http.NewRequest(method, urlstr, buffer); err != nil {
		return nil, utils.NewError(NewRequest, "unable to create request", urlstr, err)
	} else {
		if buffer != nil {
			// set the content type to XML if we have a body
			r.Native().Header.Set("Content-Type", "text/calendar; charset=UTF-8")
		}
		return (*Request)(r), nil
	}
}
开发者ID:johnboiles,项目名称:caldav-go,代码行数:14,代码来源:request.go

示例14: Delete

// deletes a resource if it exists on a particular path
func (c *Client) Delete(path string) error {
	if req, err := c.Server().NewRequest("DELETE", path); err != nil {
		return utils.NewError(c.Delete, "unable to create request", c, err)
	} else if resp, err := c.Do(req); err != nil {
		return utils.NewError(c.Delete, "unable to execute request", c, err)
	} else if resp.StatusCode != nhttp.StatusNoContent && resp.StatusCode != nhttp.StatusNotFound {
		err := new(entities.Error)
		resp.Decode(err)
		msg := fmt.Sprintf("unexpected server response %s", resp.Status)
		return utils.NewError(c.Delete, msg, c, err)
	} else {
		return nil
	}
}
开发者ID:johnboiles,项目名称:caldav-go,代码行数:15,代码来源:client.go

示例15: DecodeICalParams

// decodes the datetime params from the iCalendar specification
func (d *DateTime) DecodeICalParams(params properties.Params) error {
	layout := DateTimeFormatString
	value := d.t.Format(layout)
	if name, found := params[properties.TimeZoneIdPropertyName]; !found {
		return nil
	} else if loc, err := time.LoadLocation(name); err != nil {
		return utils.NewError(d.DecodeICalValue, "unable to parse timezone", d, err)
	} else if t, err := time.ParseInLocation(layout, value, loc); err != nil {
		return utils.NewError(d.DecodeICalValue, "unable to parse datetime value", d, err)
	} else {
		d.t = t
		return nil
	}
}
开发者ID:johnboiles,项目名称:caldav-go,代码行数:15,代码来源:datetime.go


注:本文中的github.com/taviti/caldav-go/utils.NewError函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。