github.com/scorpionis/hub@v2.2.1+incompatible/github/url.go (about)

     1  package github
     2  
     3  import (
     4  	"net/url"
     5  	"strings"
     6  )
     7  
     8  type URL struct {
     9  	url.URL
    10  	*Project
    11  }
    12  
    13  func (url URL) ProjectPath() (projectPath string) {
    14  	split := strings.SplitN(url.Path, "/", 4)
    15  	if len(split) > 3 {
    16  		projectPath = split[3]
    17  	}
    18  
    19  	return
    20  }
    21  
    22  func ParseURL(rawurl string) (*URL, error) {
    23  	url, err := url.Parse(rawurl)
    24  	if err != nil {
    25  		return nil, err
    26  	}
    27  
    28  	project, err := NewProjectFromURL(url)
    29  	if err != nil {
    30  		return nil, err
    31  	}
    32  
    33  	return &URL{Project: project, URL: *url}, nil
    34  }