--- /dev/null
+// Copyright (c) 2023 Mattia Cabrini
+// SPDX-License-Identifier: MIT
+
+package net
+
+import "strings"
+
+type URI struct {
+ comp []string
+ path string
+
+ stackIx int
+}
+
+func InitURI(uri string) (u URI) {
+ u.path = strings.Split(uri, "?")[0]
+ u.comp = strings.Split(u.path, "/")[1:]
+ return
+}
+
+func (u *URI) Pop() (part string) {
+ if u.stackIx < len(u.comp) {
+ part = u.comp[u.stackIx]
+ u.stackIx++
+ }
+
+ return
+}
+
+func (u *URI) StackCount() int {
+ return len(u.comp) - u.stackIx
+}
+
+func (u *URI) ResetStack() {
+ u.stackIx = 0
+}
return nil
}
-// Giveng an obj interface{}, returns an interface{} which is a propery value of that onj.
-// GetProperty seeks a property that has name equal to name + suffix.
+// Giveng an obj interface{}, returns an interface{} which is a propery value of that obj.
+// GetProperty seeks a property that has name equal to name + suffix and all given tags equal to true.
// `suffix` might just be an empty string.
func GetProperty(obj interface{}, name string, suffix string, tags ...string) interface{} {
to := reflect.TypeOf(obj)
--- /dev/null
+// Copyright (c) 2023 Mattia Cabrini
+// SPDX-License-Identifier: MIT
+
+package utility
+
+// Returns str without last n characters
+func ButLastN(str string, n int) string {
+ lenStr := len(str)
+
+ if lenStr < n {
+ return ""
+ }
+
+ return str[:lenStr-n]
+}
+
+// Returns true is str ends with any of the provided suffixes; False otherwise
+// If true is returned, the matching suffix is also returned; Empty string otherwise
+func EndsWithAny(str string, suffixesList ...string) (bool, string) {
+ for _, suffix := range suffixesList {
+ if EndsWith(str, suffix) {
+ return true, suffix
+ }
+ }
+
+ return false, ""
+}
+
+// Returns true is str ends with suffix; False otherwise
+func EndsWith(str string, suffix string) bool {
+ lenStr := len(str)
+ lenSuffix := len(suffix)
+
+ if lenStr < lenSuffix {
+ return false
+ }
+
+ return str[lenStr-lenSuffix:] == suffix
+}