Skip to content
Snippets Groups Projects
Select Git revision
  • 55a97a2af37088dd7f40a5d6973df231b46513a3
  • master default protected
2 results

Makefile

Blame
  • id.go 541 B
    package id
    
    import (
    	"errors"
    	"strings"
    )
    
    const Separator = '/'
    
    var ErrInvalidID = errors.New("invalid id")
    
    type ID interface {
    	String() string
    	Type() string
    	ToMap() map[string]any
    	FromString(string) error
    	FromMap(map[string]any) error
    	Validate() error
    }
    
    func Split(id string) []string {
    	if id[0] != Separator {
    		return nil
    	}
    	return strings.Split(id[1:], string(Separator))
    }
    
    func Join(parts ...string) string {
    	s := strings.Join(parts, string(Separator))
    	if s[0] != Separator {
    		s = string(Separator) + s
    	}
    	return s
    }