| 1 | //go:generate stringer -type=URLPart -trimprefix URL |
| 2 | |
| 3 | package formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/ |
| 4 | |
| 5 | import ( |
| 6 | "logscip-go gomod github.com/golang/go/src . log/" |
| 7 | "strconvscip-go gomod github.com/golang/go/src . strconv/" |
| 8 | "stringsscip-go gomod github.com/golang/go/src . strings/" |
| 9 | ) |
| 10 | |
| 11 | // URLPart is an indicator as to what part of an URL a field is serialized to. |
| 12 | type URLPartscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLPart# int |
| 13 | |
| 14 | // indicator as to what part of an URL a field is serialized to. |
| 15 | const ( |
| 16 | URLQueryscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLQuery. URLPartscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLPart# = iota |
| 17 | URLUserscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLUser. |
| 18 | URLPasswordscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLPassword. |
| 19 | URLHostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLHost. |
| 20 | URLPortscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLPort. |
| 21 | URLPathscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLPath. // Base path; additional paths are URLPath + N |
| 22 | ) |
| 23 | |
| 24 | // Suffix returns the separator between the URLPart and its subsequent part. |
| 25 | func (u URLPartscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLPart#) Suffixscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLPart#Suffix().() rune { |
| 26 | switch u { |
| 27 | case URLQueryscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLQuery.: |
| 28 | return '/' |
| 29 | case URLUserscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLUser.: |
| 30 | return ':' |
| 31 | case URLPasswordscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLPassword.: |
| 32 | return '@' |
| 33 | case URLHostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLHost.: |
| 34 | return ':' |
| 35 | case URLPortscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLPort.: |
| 36 | return '/' |
| 37 | case URLPathscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLPath.: |
| 38 | return '/' |
| 39 | default: |
| 40 | return '/' |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | // ParseURLPart returns the URLPart that matches the supplied string. |
| 45 | func ParseURLPartscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/ParseURLPart().(inputString string) URLPartscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLPart# { |
| 46 | lowerString := stringsscip-go gomod github.com/golang/go/src . strings/.ToLowerscip-go gomod github.com/golang/go/src . strings/ToLower().(inputString) |
| 47 | switch lowerString { |
| 48 | case "user": |
| 49 | return URLUserscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLUser. |
| 50 | case "pass", "password": |
| 51 | return URLPasswordscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLPassword. |
| 52 | case "host": |
| 53 | return URLHostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLHost. |
| 54 | case "port": |
| 55 | return URLPortscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLPort. |
| 56 | case "path", "path1": |
| 57 | return URLPathscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLPath. |
| 58 | case "query", "": |
| 59 | return URLQueryscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLQuery. |
| 60 | } |
| 61 | |
| 62 | // Handle dynamic path segments (e.g., "path2", "path3", etc.). |
| 63 | if stringsscip-go gomod github.com/golang/go/src . strings/.HasPrefixscip-go gomod github.com/golang/go/src . strings/HasPrefix().(lowerString, "path") && len(lowerString) > 4 { |
| 64 | if num, err := strconvscip-go gomod github.com/golang/go/src . strconv/.Atoiscip-go gomod github.com/golang/go/src . strconv/Atoi().(lowerString[4:]); err == nil && num >= 2 { |
| 65 | return URLPathscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLPath. + URLPartscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLPart#(num-1) // Offset from URLPath; "path2" -> URLPath+1 |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | logscip-go gomod github.com/golang/go/src . log/.Printfscip-go gomod github.com/golang/go/src . log/Printf().("invalid URLPart: %s, defaulting to URLQuery", lowerString) |
| 70 | |
| 71 | return URLQueryscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLQuery. |
| 72 | } |
| 73 | |
| 74 | // ParseURLParts returns the URLParts that matches the supplied string. |
| 75 | func ParseURLPartsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/ParseURLParts().(s string) []URLPartscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLPart# { |
| 76 | rawParts := stringsscip-go gomod github.com/golang/go/src . strings/.Splitscip-go gomod github.com/golang/go/src . strings/Split().(s, ",") |
| 77 | urlParts := make([]URLPartscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/URLPart#, len(rawParts)) |
| 78 | |
| 79 | for i, raw := range rawParts { |
| 80 | urlParts[i] = ParseURLPartscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/ParseURLPart().(raw) |
| 81 | } |
| 82 | |
| 83 | return urlParts |
| 84 | } |