示例#1
0
// setMatch extracts the variables from the URL once a route matches.
func (v *routeRegexp) setMatch(msg *coap.Message, m *RouteMatch, r *Route) {
	// Store path variables.
	pathVars := v.regexp.FindStringSubmatch(msg.PathString())
	if pathVars != nil {
		subexpNames := v.regexp.SubexpNames()
		varName := 0
		for i, name := range subexpNames[1:] {
			if name != "" && name == varGroupName(varName) {
				m.Vars[v.varsN[varName]] = pathVars[i+1]
				varName++
			}
		}

	}
}
示例#2
0
func handle(conn *net.UDPConn, addr *net.UDPAddr, mess *coap.Message) *coap.Message {
	log.Printf("Got message path=%q: %#v from %v", mess.Path(), mess, addr)

	var payload []byte
	var err error

	// checks available endpoints
	check := check_endpoint(mess.Path())
	if !check {
		return response(mess, coap.BadRequest, &payload)
	}

	// invoke handler
	payload, err = handlers.SendRequest(mess)
	if err != nil {
		log.Printf("Error on handler, stopping: %v", err)
		return nil
	}

	if mess.IsConfirmable() {
		return response(mess, coap.Content, &payload)
	}

	return nil
}
示例#3
0
// Match matches the regexp against the URL host or path.
func (r *routeRegexp) Match(msg *coap.Message, addr *net.UDPAddr) bool {
	return r.regexp.MatchString(msg.PathString())
}