-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
87 lines (73 loc) · 1.84 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package vanity
import (
"encoding"
)
// Config defines the configuration used by the http handler.
type Config struct {
// The vanity import prefix shared by all paths, without URL schema and
// trailing "/".
//
// Example:
//
// go.yhsif.com
//
// Or:
//
// yhsif.com/go
Prefix string `yaml:"prefix" json:"prefix"`
// The mappings of the repositories.
Mappings []Mapping `yaml:"mappings" json:"mappings"`
}
// Mapping defines a mapping from a vanity path to an actual repository.
type Mapping struct {
// The path of the vanity URL, with leading "/"/
//
// Example:
//
// /vanity
Path string `yaml:"path" json:"path"`
// The full URL of the actual repository.
//
// Example:
//
// https://github.com/fishy/go-vanity
URL string `yaml:"url" json:"url"`
// The VCS of the repository. Default to DefaultVCS ("git").
VCS VCS `yaml:"vcs" json:"vcs"`
// A brief description to be shown on the index page.
Description string `yaml:"description" json:"description"`
// If set to true, do not show this mapping in index page.
HideInIndex bool `yaml:"unlist" json:"unlist"`
}
// The default VCS to be used.
const (
DefaultVCS VCS = "git"
)
// VCS defines the vcs ("git", "mod", "hg", etc.) used in Mapping.
//
// It treats zero value (empty string) as DefaultVCS,
// and behave the same as strings otherwise.
type VCS string
var (
_ encoding.TextMarshaler = VCS("")
_ encoding.TextUnmarshaler = (*VCS)(nil)
)
func (v VCS) String() string {
if v == "" {
return string(DefaultVCS)
}
return string(v)
}
// MarshalText implements encoding.TextMarshaler.
func (v VCS) MarshalText() (text []byte, err error) {
return []byte(v.String()), nil
}
// UnmarshalText implements encoding.TextUnmarshaler.
func (v *VCS) UnmarshalText(text []byte) error {
if len(text) <= 0 {
*v = DefaultVCS
} else {
*v = VCS(text)
}
return nil
}