parsePayloadPositions extracts marked segments from a URI template. Given a marker like "§" and URI "http://example.com/§100§/user/§200§", it returns the marked values ["100", "200"] and a template with internal placeholders.
(uri, marker string)
| 3911 | // Given a marker like "§" and URI "http://example.com/§100§/user/§200§", |
| 3912 | // it returns the marked values ["100", "200"] and a template with internal placeholders. |
| 3913 | func parsePayloadPositions(uri, marker string) ([]string, string) { |
| 3914 | var positions []string |
| 3915 | template := uri |
| 3916 | idx := 0 |
| 3917 | |
| 3918 | for { |
| 3919 | start := strings.Index(template, marker) |
| 3920 | if start == -1 { |
| 3921 | break |
| 3922 | } |
| 3923 | rest := template[start+len(marker):] |
| 3924 | end := strings.Index(rest, marker) |
| 3925 | if end == -1 { |
| 3926 | break |
| 3927 | } |
| 3928 | value := rest[:end] |
| 3929 | positions = append(positions, value) |
| 3930 | placeholder := fmt.Sprintf("%s%d\x00", payloadPlaceholderPrefix, idx) |
| 3931 | template = template[:start] + placeholder + rest[end+len(marker):] |
| 3932 | idx++ |
| 3933 | } |
| 3934 | |
| 3935 | return positions, template |
| 3936 | } |
| 3937 | |
| 3938 | // payloadPlaceholder returns the placeholder string for a given index. |
| 3939 | func payloadPlaceholder(idx int) string { |
no outgoing calls