-
Notifications
You must be signed in to change notification settings - Fork 10
/
channel.go
197 lines (185 loc) · 3.92 KB
/
channel.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
package namecheck
import (
"context"
"errors"
)
//ChannelType value
type ChannelType string
//ChannelStatus value
type ChannelStatus string
const (
//StatusAvailable represents status when
//the name is available on a channel
StatusAvailable ChannelStatus = "V"
//StatusNotAvailable represents status when
//the name is not available on a channel
StatusNotAvailable ChannelStatus = "X"
//StatusUnknown represents status when there is
//an unknown problem when checking the availability of the name
StatusUnknown ChannelStatus = "?"
//TypeDomain represents DNS channel type
TypeDomain ChannelType = "domain"
//TypeSocial represents Social media channel type
TypeSocial ChannelType = "social"
)
//Channel represents channel that will be checked
type Channel struct {
Code string
URL string
Type ChannelType
Status ChannelStatus
Error error
}
//DefaultChannels contains list of available channel
var DefaultChannels = []*Channel{{
Code: ".biz",
URL: "http://{name}.biz",
Type: TypeDomain,
}, {
Code: ".cc",
URL: "http://{name}.cc",
Type: TypeDomain,
}, {
Code: ".com",
URL: "http://{name}.com",
Type: TypeDomain,
}, {
Code: ".co",
URL: "http://{name}.co",
Type: TypeDomain,
}, {
Code: ".co.id",
URL: "http://{name}.co.id",
Type: TypeDomain,
}, {
Code: ".id",
URL: "http://{name}.id",
Type: TypeDomain,
}, {
Code: ".in",
URL: "http://{name}.info",
Type: TypeDomain,
}, {
Code: ".info",
URL: "http://{name}.info",
Type: TypeDomain,
}, {
Code: ".io",
URL: "http://{name}.io",
Type: TypeDomain,
}, {
Code: ".ly",
URL: "http://{name}.ly",
Type: TypeDomain,
}, {
Code: ".me",
URL: "http://{name}.me",
Type: TypeDomain,
}, {
Code: ".name",
URL: "http://{name}.name",
Type: TypeDomain,
}, {
Code: ".net",
URL: "http://{name}.net",
Type: TypeDomain,
}, {
Code: ".org",
URL: "http://{name}.org",
Type: TypeDomain,
}, {
Code: ".us",
URL: "http://{name}.us",
Type: TypeDomain,
}, {
Code: ".xyz",
URL: "http://{name}.xyz",
Type: TypeDomain,
}, {
Code: "Facebook",
URL: "https://facebook.com/{name}",
Type: TypeSocial,
}, {
Code: "YouTube",
URL: "https://youtube.com/{name}",
Type: TypeSocial,
}, {
Code: "Instagram",
URL: "https://instagram.com/{name}",
Type: TypeSocial,
}, {
Code: "Twitter",
URL: "https://twitter.com/{name}",
Type: TypeSocial,
}, {
Code: "Github",
URL: "https://github.com/{name}",
Type: TypeSocial,
}, {
Code: "Gitlab",
URL: "https://gitlab.com/{name}",
Type: TypeSocial,
}, {
Code: "Bitbucket",
URL: "https://bitbucket.org/{name}",
Type: TypeSocial,
}, {
Code: "Reddit",
URL: "https://www.reddit.com/user/{name}",
Type: TypeSocial,
}, {
Code: "Medium",
URL: "https://www.medium.com/@{name}",
Type: TypeSocial,
}, {
Code: "Vimeo",
URL: "https://vimeo.com/{name}",
Type: TypeSocial,
}, {
Code: "Artstation",
URL: "https://www.artstation.com/{name}",
Type: TypeSocial,
}, {
Code: "Tumblr",
URL: "https://{name}.tumblr.com",
Type: TypeSocial,
}, {
Code: "Keybase.io",
URL: "https://keybase.io/{name}",
Type: TypeSocial,
}, {
Code: "Vkontakte",
URL: "https://vk.com/{name}",
Type: TypeSocial,
}, {
Code: "Pinterest",
URL: "https://pinterest.com/{name}",
Type: TypeSocial,
}, {
Code: "Slack",
URL: "https://{name}.slack.com",
Type: TypeSocial,
}, {
Code: "Dev.to",
URL: "https://dev.to/{name}",
Type: TypeSocial,
}}
//FindChannelByCode is used to find channel by its channel code
func FindChannelByCode(ctx context.Context, code string) (*Channel, error) {
for _, channel := range DefaultChannels {
if channel.Code == code {
return channel, nil
}
}
return nil, errors.New("No channel found. Please use the available channel code")
}
//FindChannelsByType is used to find channels by its channel type
func FindChannelsByType(ctx context.Context, chType ChannelType) []*Channel {
result := []*Channel{}
for _, channel := range DefaultChannels {
if channel.Type == chType {
result = append(result, channel)
}
}
return result
}