aboutsummaryrefslogtreecommitdiff
path: root/utils/string.go
diff options
context:
space:
mode:
authorn-peugnet <n.peugnet@free.fr>2021-09-22 21:06:18 +0200
committern-peugnet <n.peugnet@free.fr>2021-09-22 21:07:07 +0200
commitdb5b7303c254af467a6458d9025f825ab50b452e (patch)
treebe317ffc762c854fc05c25ea2c03b9fe9ba56784 /utils/string.go
parentcce3365003dba7c3ac2905f71aa284caf63a1c78 (diff)
downloaddna-backup-db5b7303c254af467a6458d9025f825ab50b452e.tar.gz
dna-backup-db5b7303c254af467a6458d9025f825ab50b452e.zip
export unprefix in utils and fix error msg
Diffstat (limited to 'utils/string.go')
-rw-r--r--utils/string.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/utils/string.go b/utils/string.go
new file mode 100644
index 0000000..b3cbb17
--- /dev/null
+++ b/utils/string.go
@@ -0,0 +1,14 @@
+package utils
+
+import (
+ "fmt"
+ "strings"
+)
+
+func Unprefix(path string, prefix string) (string, error) {
+ if !strings.HasPrefix(path, prefix) {
+ return path, fmt.Errorf("%q is not prefixed by %q", path, prefix)
+ } else {
+ return path[len(prefix):], nil
+ }
+}