Sergiusz Bazanski | c881cf3 | 2020-04-08 20:03:12 +0200 | [diff] [blame] | 1 | package source |
| 2 | |
Sergiusz Bazanski | f157b4d | 2020-04-10 17:39:43 +0200 | [diff] [blame] | 3 | import "context" |
Sergiusz Bazanski | c881cf3 | 2020-04-08 20:03:12 +0200 | [diff] [blame] | 4 | |
Sergiusz Bazanski | f157b4d | 2020-04-10 17:39:43 +0200 | [diff] [blame] | 5 | var ( |
Serge Bazanski | bc0d3cb | 2021-03-06 20:49:00 +0000 | [diff] [blame] | 6 | FlagGitwebURLPattern = "https://cs.hackerspace.pl/hscloud@%s/-/blob/%s" |
Sergiusz Bazanski | f157b4d | 2020-04-10 17:39:43 +0200 | [diff] [blame] | 7 | ) |
| 8 | |
| 9 | type Source interface { |
| 10 | IsFile(ctx context.Context, path string) (bool, error) |
| 11 | ReadFile(ctx context.Context, path string) ([]byte, error) |
| 12 | IsDirectory(ctx context.Context, path string) (bool, error) |
| 13 | WebLinks(fpath string) []WebLink |
| 14 | } |
| 15 | |
| 16 | type WebLink struct { |
| 17 | Kind string |
| 18 | LinkLabel string |
| 19 | LinkURL string |
| 20 | } |
| 21 | |
| 22 | type SourceProvider interface { |
| 23 | Source(ctx context.Context, rev string) (Source, error) |
| 24 | } |
| 25 | |
| 26 | type singleRefProvider struct { |
| 27 | source Source |
| 28 | } |
| 29 | |
| 30 | func (s *singleRefProvider) Source(ctx context.Context, rev string) (Source, error) { |
| 31 | return s.source, nil |
| 32 | } |
| 33 | |
| 34 | func NewSingleRefProvider(s Source) SourceProvider { |
| 35 | return &singleRefProvider{s} |
Sergiusz Bazanski | c881cf3 | 2020-04-08 20:03:12 +0200 | [diff] [blame] | 36 | } |