File: util.go

package info (click to toggle)
golang-github-hashicorp-atlas-go 0.0~git20230125.46e9b3e-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 528 kB
  • sloc: sh: 262; makefile: 17
file content (22 lines) | stat: -rw-r--r-- 586 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package atlas

import (
	"fmt"
	"strings"
)

// ParseSlug parses a slug of the format (x/y) into the x and y components. It
// accepts a string of the format "x/y" ("user/name" for example). If an empty
// string is given, an error is returned. If the given string is not a valid
// slug format, an error is returned.
func ParseSlug(slug string) (string, string, error) {
	if slug == "" {
		return "", "", fmt.Errorf("missing slug")
	}

	parts := strings.Split(slug, "/")
	if len(parts) != 2 {
		return "", "", fmt.Errorf("malformed slug %q", slug)
	}
	return parts[0], parts[1], nil
}