|
5 | 5 | "errors" |
6 | 6 | "fmt" |
7 | 7 | "reflect" |
| 8 | + "strings" |
8 | 9 | ) |
9 | 10 |
|
10 | 11 | // MarshalIdentifier interface is necessary to give an element |
@@ -301,25 +302,18 @@ func getStructRelationships(relationer MarshalLinkedRelations, information Serve |
301 | 302 | // helper method to generate URL fields for `links` |
302 | 303 | func getLinksForServerInformation(relationer MarshalLinkedRelations, name string, information ServerInformation) map[string]string { |
303 | 304 | links := map[string]string{} |
304 | | - // generate links if necessary |
| 305 | + |
305 | 306 | if information != serverInformationNil { |
306 | | - prefix := "" |
307 | | - baseURL := information.GetBaseURL() |
308 | | - if baseURL != "" { |
309 | | - prefix = baseURL |
310 | | - } |
311 | | - p := information.GetPrefix() |
312 | | - if p != "" { |
313 | | - prefix += "/" + p |
314 | | - } |
| 307 | + prefix := strings.Trim(information.GetBaseURL(), "/") |
| 308 | + namespace := strings.Trim(information.GetPrefix(), "/") |
| 309 | + structType := getStructType(relationer) |
315 | 310 |
|
316 | | - if prefix != "" { |
317 | | - links["self"] = fmt.Sprintf("%s/%s/%s/relationships/%s", prefix, getStructType(relationer), relationer.GetID(), name) |
318 | | - links["related"] = fmt.Sprintf("%s/%s/%s/%s", prefix, getStructType(relationer), relationer.GetID(), name) |
319 | | - } else { |
320 | | - links["self"] = fmt.Sprintf("/%s/%s/relationships/%s", getStructType(relationer), relationer.GetID(), name) |
321 | | - links["related"] = fmt.Sprintf("/%s/%s/%s", getStructType(relationer), relationer.GetID(), name) |
| 311 | + if namespace != "" { |
| 312 | + prefix += "/" + namespace |
322 | 313 | } |
| 314 | + |
| 315 | + links["self"] = fmt.Sprintf("%s/%s/%s/relationships/%s", prefix, structType, relationer.GetID(), name) |
| 316 | + links["related"] = fmt.Sprintf("%s/%s/%s/%s", prefix, structType, relationer.GetID(), name) |
323 | 317 | } |
324 | 318 |
|
325 | 319 | return links |
|
0 commit comments