Ejemplo n.º 1
0
// generate weak random id for a route if
// it doesn't have one.
func GenerateIfNeeded(existingId string) string {
	if existingId != "" {
		return existingId
	}

	// using this to avoid adding a new dependency.
	id, err := flowid.NewFlowId(randomIdLength)
	if err != nil {
		return existingId
	}

	// replace characters that are not allowed
	// for eskip route ids.
	id = routeIdRx.ReplaceAllString(id, "x")
	return "route" + id
}
Ejemplo n.º 2
0
// generate weak random id for a route if
// it doesn't have one.
func ensureId(r *eskip.Route) error {
	if r.Id != "" {
		return nil
	}

	// using this to avoid adding a new dependency.
	id, err := flowid.NewFlowId(randomIdLength)
	if err != nil {
		return err
	}

	// replace characters that are not allowed
	// for eskip route ids.
	id = routeIdRx.ReplaceAllString(id, "x")
	r.Id = "route" + id
	return nil
}