@@ -10,44 +10,30 @@ sidebar_position: 4
1010
1111See example client in ` examples/go-client/ ` .
1212
13+ Currently supports the following parsers:
14+
15+ - GitHub
16+ - GitLab
17+
1318``` go
1419package main
1520
1621import (
1722 " log/slog"
1823 " os"
19- " time"
20-
21- " github.com/lmittmann/tint"
2224
2325 " github.com/retr0h/git-url-parse/pkg"
2426 " github.com/retr0h/git-url-parse/pkg/repository"
2527)
2628
29+ var logger = slog.New (slog.NewTextHandler (os.Stdout , nil ))
30+
2731type repositoryManager interface {
2832 RegisterParser (url string ) error
2933 Parse () (pkg.RepositoryManager , error )
3034}
3135
32- func getLogger (debug bool ) *slog .Logger {
33- logLevel := slog.LevelInfo
34- if debug {
35- logLevel = slog.LevelDebug
36- }
37-
38- logger := slog.New (
39- tint.NewHandler (os.Stderr , &tint.Options {
40- Level: logLevel,
41- TimeFormat: time.Kitchen ,
42- }),
43- )
44-
45- return logger
46- }
47-
4836func main () {
49- debug := true
50- logger := getLogger (debug)
5137 var r repositoryManager = repository.New (logger)
5238
5339 r.RegisterParser (" https://github.com/retr0h/foo" )
@@ -56,13 +42,14 @@ func main() {
5642 panic (err)
5743 }
5844
59- logger.Info (repo.GetProtocol ())
60- logger.Info (repo.GetResourceName ())
61- logger.Info (repo.GetHREF ())
62- logger.Info (repo.GetOwnerName ())
63- logger.Info (repo.GetRepoName ())
45+ logger.Info (repo.GetProtocol ()) // https
46+ logger.Info (repo.GetProtocols ()[0 ]) // https
47+ logger.Info (repo.GetResourceName ()) // github.com
48+ logger.Info (repo.GetHREF ()) // https://github.com/retr0h/foo
49+ logger.Info (repo.GetOwnerName ()) // retr0h
50+ logger.Info (repo.GetRepoName ()) // foo
6451 logger.Info (repo.GetPath ())
6552 logger.Info (repo.GetBranchName ())
66- logger.Info (repo.GetProviderName ())
53+ logger.Info (repo.GetProviderName ()) // github
6754}
6855```
0 commit comments